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 › making legs on a stick figure bug move
Page Index Toggle Pages: 1
making legs on a stick figure bug move (Read 623 times)
making legs on a stick figure bug move
Oct 29th, 2009, 10:01pm
 
so here's the code:

void setup(){
 size (400, 400);
 noFill();
 smooth();
 strokeWeight (1);
}
void draw(){
 ellipse (100, 100, 50, 100);
 legl(40, 90, 90);
 legl(42, 110, 110);
 legl(50, 130, 130);
 legr(125, 100, 100);
 legr(123, 120, 120);
 legr(115, 140, 140);
 frameRate (30);
}
void legl (int a, int b, int c) {
 beginShape();
   vertex (a+35, b + 10);
   vertex (a+20, b);
   vertex (a, c + 30);
   endShape();
}
void legr (int d, int e, int f) {
 beginShape();
   vertex (d, e);
   vertex (d+15, e - 10);
   vertex (d+35, f + 20);
   endShape();
}


I want to make values c and f increase +1 per frame for 20 frames, then decrease -1 per frame for 20 frames. I was thinking of doing it with the "for" and "if" commands, but trial and error hasn't been fruitful yet.
how can I approach this?

thank you!
Re: making legs on a stick figure bug move
Reply #1 - Oct 29th, 2009, 10:39pm
 
Put frameRate call in setup().
No need for a 'for' loop, draw() will do the job.
You can have a global variable, say 'dir', set to 1 initially. And another, say 'count', set to 0.
At the start of draw(), add dir to your positions (should be in global variables too) and increment count (count++).
When count reaches 20, invert dir (dir = -dir;) and reset count.
Page Index Toggle Pages: 1