Code/Processing

simple wave test

maetel 2007. 8. 30. 03:29

//finn interaction test wave
//ref. http://www.shiffman.net/itp/classes/nature/week04_s06/sine/

int xs = 5;
int w;

float th = 0.0f;
float a = 60.0;
float p = 400.0f;
float dx;
float[] y;

void setup(){
  size(320,240);
  frameRate(30);
  colorMode(RGB,255,255,255,80);
  smooth();
  w = width+8;
  dx = (TWO_PI/p)*xs;
  y = new float[w/xs];
}

void draw(){
  background(0);
  calcWave();
  renderWave();
}

void calcWave(){
  th += 0.02;
  float x = th;
  for (int i=0; i<y.length; i++){
    y[i]=a*sin(x);
    x+=dx;
  }
}

void renderWave(){
  for (int x=0; x<y.length; x++){
    noStroke();
    fill(255,0,0);
    ellipseMode(CENTER);
    ellipse(x*xs,width/2+y[x],5,5);
  }
}