ABOUT PROJECTS RESUME
nature-of-code:compound_vortex_move.pde
// Jadie Oh 2006Fall Nature of Code
// Source of Sine Wave, Vector3D from  Daniel Shiffman <http://www.shiffman.net>
 
 
int yspacing = 6;   // How far apart should each horizontal location be spaced
int h;              // Height of entire wave
 
float xoff = 0.0f;        // 2nd dimension of perlin noise
 
//int yspacing = 30;   // How far apart should each vertical location be spaced
//int h;              // height of entire wave
 
float theta = 0.0f;       // Start angle at 0
float amplitude = 75.0f;  // Height of wave
float period = 800.0f;    // How many pixels before the wave repeats
float dy;                 // Value for incrementing y, to be calculated as a function of period and yspacing
float[] xvalues;          // Using an array to store width values for the wave (not entirely necessary)
 
 
Vector3D[] tl;//location of tornado which would be the main sine wave
Tornado[] t;
 
float startpointx = height/6;
boolean tornadoMove = false;
 
void setup() {
  size(800,300);
   background(105, 120, 15);
  framerate(30);
  colorMode(RGB,255,255,255,100);
  smooth();
  //h = 4*height/5;
   h = height+16;
  dy = (TWO_PI / period) * yspacing;
  xvalues = new float[h/yspacing];
  tl = new Vector3D[xvalues.length];
  t = new Tornado[tl.length];
}
 
void draw() {
  fill (125, 120, 15, 50);
  rect(0,0, width, height);
 
  calcWave();
  renderWave();
 
  if(tornadoMove){
  startpointx += random(0, 3);
  }
}
 
void calcWave() {
  float dy1 = 0.05f;
  float dx1 = 0.01f;
  float amplitude = 80.0f;
  theta += 0.01;
 
  // Increment y ('time')
  xoff += dx1;
 
  //float xoff = 0.0;  // Option #1
  float yoff = xoff; // Option #2
 
  for (int i = 0; i < xvalues.length; i++) {
    // Using 2D noise function
    //yvalues[i] = (2*noise(xoff,yoff)-1)*amplitude; // Option #1
    // Using 1D noise function
    xvalues[i] = (2*noise(yoff)-1)*amplitude;    // Option #2
    yoff+=dy1;
 
  // For every y value, calculate a x value with sine function
  float y = theta;
    y+=dy;
    //create Vector3D array to give tornado its location
    tl[i] = new Vector3D((startpointx+xvalues[i]), float(i*yspacing));
    t[i] = new Tornado(tl[i]);
    t[i].calcTornado();
   // println("sin(y) = " + sin(y));
 }
} 
 
 
 
 
void renderWave() {
  // A simple way to draw the wave with an ellipse at each location
  for (int x = 0; x < xvalues.length; x++) {
    noStroke();
    fill(255,50);
    //ellipseMode(CENTER);
    //ellipse((startpointx+xvalues[x]),x*yspacing,5,5);
    fill(220, 50);
    ellipse(startpointx+xvalues[x],x*yspacing,((height - (x*yspacing))/3 - 4),16);
 
    //   println("xvalues = " + xvalues[x] + ", y location = " + x*yspacing );
 
  }
}
 
 
void mouseReleased(){
  tornadoMove = !tornadoMove;
 }
Show pagesource Old revisions Backlinks Index Recent changes
nature-of-code/compound_vortex_move.pde.txt · Last modified: 2009/04/26 01:30 (external edit)