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 & HelpPrograms › moving an object left to right without input
Page Index Toggle Pages: 1
moving an object left to right without input (Read 1167 times)
moving an object left to right without input
Apr 17th, 2010, 8:50am
 
Hey,

i'm trying to make this image move left to right. i can't figure a way to do it.

heres the code:
Sadsize(400,450);
background(204);
smooth();

//ghost//
stroke(0);
fill(255);
ellipse(200,200,100,200);
fill(0);
ellipse(215,150,20,50);
ellipse(185,150,20,50);
ellipse(200,220,40,50);

thanks in advance. Cool
Re: moving an object left to right without input
Reply #1 - Apr 17th, 2010, 9:59am
 
Put your drawing code in draw(), starting with a background() call. Keep size() and smooth() in setup().
Have a global variable, eg. called 'position'.
On each draw() call, increment this position and use it in all drawing calls (x position):
ellipse(position + 180, 150, 20, 50); and so on.
Re: moving an object left to right without input
Reply #2 - Apr 17th, 2010, 6:21pm
 
when you mean global you make a new function or to put it before the setup.
Re: moving an object left to right without input
Reply #3 - Apr 17th, 2010, 8:21pm
 
how do u repeat it?
Re: moving an object left to right without input
Reply #4 - Apr 18th, 2010, 11:19am
 
Global means "outside of a function or class", so yes, before setup() is fine (and traditional).

And draw() is called repeatedly, it provides the main loop of the sketches.
Re: moving an object left to right without input
Reply #5 - Apr 19th, 2010, 10:47am
 
thank you for your help. Cheesy
Page Index Toggle Pages: 1