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.
IndexProgramming Questions & HelpSyntax Questions › Stopping motion..
Page Index Toggle Pages: 1
Stopping motion.. (Read 197 times)
Stopping motion..
Mar 1st, 2009, 6:23pm
 
In the code below, the circle grows/shrinks repeatedly. How can I make it so it only grows once - while it 'shakes' and then stop and stay at its largest size?

float x1 = -180;       //O
float y1 = 180;
float speed = 0.05;
float angle = 0.0;

void setup(){
 size(600,400);
 noStroke();
 smooth();
 fill(255);
}
void circlePhase(float phase){  
 ellipse(x1,y1,40,40);
     x1 += 5;
 if (x1 > 280){
     x1 = 280;
     x1 += random(15);
 }
 float diameter = 30 + (sin (angle + phase) * 45);
 ellipse(x1, y1, diameter, diameter);
}  

void draw(){
 background(0);
 frameRate(30);
 circlePhase(0.0);
 angle += speed;}
Re: Stopping motion..
Reply #1 - Mar 2nd, 2009, 11:33am
 
You must test against the diameter: once it reaches a given value, increment a step number:
call functions depending on step: 0 => call function growing circle; 1 => call function shaking circle; 2 => call no function (or drawing static circle).

To know when to stop shaking, check frameCount number.
Page Index Toggle Pages: 1