We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Trig Bezier Curve Animation
Page Index Toggle Pages: 1
Trig Bezier Curve Animation (Read 800 times)
Trig Bezier Curve Animation
Apr 14th, 2009, 3:11pm
 
Hello all,

This is one of my first sketches in processing:
http://mmas.unca.edu:16080/~djratlif/processing/strings/applet/

I was wondering if people could give me feedback as far as code (and whatever you wish, as long as you might give me some insight as how to do it!)

Since I am fairly new to programing I probablly have redudencies and/or things I could be doing better (maybe speed up processing time).

My code is on the page but I will post it here as well
Code:

//Trig Strings : By Drew Ratliff


//trig stuff
float angle = 0.0;
float speed = .05;
//radius
float range = 300;

Wave myWave;

void setup() {
 size (750,300);
}


void draw () {
 //set background, make random same, translate to middle
 background(0);
 randomSeed(6);
 pushMatrix();
 translate(0,height/2);
 
 
 for(int i = 0; i < 100; i++) {
   //set random blue stroke to strings
   stroke(random(255),random(255),random(200,255),random(100,200));
   
   //make wave with random x pos for bezier curves
   myWave = new Wave(int(random(width)),int(random(width)));
   
   myWave.display();
 }
 
 angle += speed;
 popMatrix();
}



class Wave {
 float b1x;
 float b1y;
 float b2x;
 float b2y;
 float sinval;
 float cosval;

 
 Wave(float x1, float x2) {

   b1x = x1;
   b2x = x2;
 }
 
 void display() {
   
   //Trig Math for motion
   sinval = sin(random(angle));
   cosval = cos(random(angle));
   float b1y =  (sinval * range);
   float b2y = (cosval * range);
   
   //draw string
   noFill();
   beginShape();
   vertex(0,0);
   bezierVertex(b1x,b1y,b2x,b2y,width,0);
   endShape();
 }
}


thankksss
Page Index Toggle Pages: 1