henry
Junior Member
Offline
Posts: 62
how to make the Recursion example Ocillate?
Oct 24th , 2008, 6:15am
I was interested in the Oscillation example method (http://www.learningprocessing.com/examples/chapter-13/example-13-6/) that I saw and fancied pairing it up with a modified Recursion example (http://www.learningprocessing.com/examples/chapter-13/example-13-8-recursion/) that I thought looked like a light bulb. As you may have guessed I tried to make the 'bulb' swing. Understanding that before there was just one line to move and now there would be several circles, I tried to keep the whole Recursion code separate at the bottom as it was conflicting with the x integer, I wanted to then say 'animate that thing over there' but not quite sure if I've got the right idea. // Learning Processing // Daniel Shiffman // http://www.learningprocessing.com // Example 13-6: Oscillation float theta = 0.0; void setup() { size(200,200); smooth(); } void draw() { background(255); drawCircle(width/2,height/2,100); // The output of the sin() function oscillates smoothly between 1 and 1. // By adding 1 we get values between 0 and 2. // By multiplying by 100, we get values between 0 and 200 which can be used as the ellipse's x location. float x = (sin(theta) + 1) * width/2; // With each cycle, increment theta theta += 0.05; // Draw the ellipse at the value produced by sine fill(0); stroke(0); //line(width/2,0,x,height/2); ellipse(x,height/2,16,16); } // Learning Processing // Daniel Shiffman // http://www.learningprocessing.com // Example 13-8: Recursion void drawCircle(float x, float y, float radius) { noFill(); ellipse(y, x, radius, radius); if(radius > 2) { // drawCircle() calls itself twice, creating a branching effect. // For every circle, a smaller circle is drawn to the left and right. drawCircle(x + radius/7, y, radius/2); drawCircle(x - radius/1, y, radius/2); } } So right now I left the opaque ball swinging and added the modified vales of the Recursion example, but don't see how to make them move. I'd like to get the whole piece to gently sway as if it were one item and not independent pieces fighting for attention.