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 › object animation
Page Index Toggle Pages: 1
object animation (Read 1358 times)
object animation
Sep 24th, 2008, 4:42pm
 
I'm trying to create an information display that consists of ellipses that rearrange themselves depending on button presses.  I want them to be animated to create continuity.  I've created an object class for the ellipses but it doesn't seem to be working.  I'm posting a simplified version of my code.

movingBall a1;

void setup() {
 size(500, 200);
 smooth();
}

void draw() {
 background(0);
 stroke(255);
 fill(255);
 
 line(0,100,500,100);
 
a1 = new movingBall(50,500);
a1.display();



}

class movingBall {
 int s;
 int y = 100;
 int d;


movingBall(int xpos, float dpos) {
 s = xpos;
 d = int(dpos);
}

void display() {
ellipse(s,y, 20, 20);

if (d<0) {
   d=d+100;
 } else if (d>500) {
   d=d-100;
 } else if(s>d) {
   s--;
 } else if (s<d) {
   s++;
 }
}
}

I'm an art student, getting into programing.  So I'm sure it's something simple that I just don't know.  Thank you.
Re: object animation
Reply #1 - Sep 24th, 2008, 5:00pm
 
'doesn't seem to be working'

in which way isn't it working?

i think the problem is that you have your new movingBall() inside your draw() loop so you get a fresh ball (in the same place) every time.

move the new movingBall() to setup() (which only runs once) and see if that works.
Re: object animation
Reply #2 - Sep 24th, 2008, 5:05pm
 
That worked.  Thank you so much.  and sorry about not being more specific.
Page Index Toggle Pages: 1