ABOUT PROJECTS RESUME
nature-of-code:lines.pde
void mousePressed()
{
  Sinewave s = new Sinewave(mouseX, mouseY);
  LinesArray.add(s);
 
  /*  if(playing == false)
   {
   Box b  = new Box(mouseX,mouseY);
   boxCount.add(b); 
   }*/
}
 
void mouseDragged()
{
  Sinewave s = (Sinewave)LinesArray.get(LinesArray.size() - 1);
  s.waveLength(mouseX,mouseY);
  /*if(playing == false)
   {
   Box b = (Box)boxCount.get(boxCount.size() - 1);
   b.boxSize(mouseX);
   }*/
}
 
class Sinewave
{
  float xpos, ypos, xpos2, ypos2; //mouse locations
  float phase;
  float freq;
  int amp=30;
 
 
  Sinewave(float x, float y)
  {
    xpos = x;
    ypos = y;
    //freq = y;
    //freq = noise(y)*height;//more like freq = x
    freq = noise(noise(x));
  }
 
  void waveLength(float x2, float y2)
  {
    xpos2 = x2;
    ypos2 = y2; 
  }
 
  void render()
  {
 
    float x,y,a;
    float dx = xpos2-xpos;
    float dy = ypos2-ypos;
    float l=sqrt(dx*dx+dy*dy);
    phase+=0.01;
 
    float nx = amp*dy/l;  
    float ny = amp*-dx/l;
 
    beginShape(LINE_STRIP);  
    float tstep=1.0 / l;
 
    for (float t=0;t<=1.0;t+=tstep){
      a=sin(phase+TWO_PI*t*freq);
      x=xpos+t*dx+nx*a;
      y=ypos+t*dy+ny*a;
      vertex(x,y);  
    }  
    endShape();    
  }
 
 
 
 
 
 
  /*  void render()
   {  
   if (myChannel.state==Ess.PLAYING)
   {
   stroke(255);
   //println((10000 - wave.ms(wave.cue))/40 );
   fill(255, (10000 - myChannel.ms(myChannel.cue)) /40 ); //alpha - higher = more opaque
   }
   else
   {
   noFill();
   } 
 
   rectMode(CENTER);
   rect(xpos,ypos,w - xpos,w - xpos);
   playbox= new Rectangle(xpos - ((w- xpos)/2),ypos - ((w- xpos)/2),w - xpos,w - xpos);
   }*/
 
 
 
 
}
Show pagesource Old revisions Backlinks Index Recent changes
nature-of-code/lines.pde.txt · Last modified: 2009/04/26 01:30 (external edit)