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 › Animating and changing background each time
Page Index Toggle Pages: 1
Animating and changing background each time (Read 367 times)
Animating and changing background each time
Dec 13th, 2007, 3:18am
 
I am trying to write a patch that has an animated foot tapping, every time it taps, i want to add an image to the background. the problem is, if i call background() within  draw() it will erase everything that has appeared within the previous frame. if i don't every stage of the animation is displayed.
Can anyone help?
here is the code as it stands.

PImage red;
float x;

void setup(){
 background(0);
 size(700,700);
 smooth();
 frameRate(30);
 x=220;
 red = loadImage("red shoe.gif");
}

void draw(){
 float siz = random(40,80);
 translate(width/2,height/2);
 rotate(radians(x));
 //radians converts degrees to radiens
 image(red,0,0,100,100);
 translate(-width/2,-height/2);
 x+=5;
 if(x==270){
   x=220;
   image(red,random(0,width),random(width),siz,siz);
 }
     
}

Thank you for any help!

Re: Animating and changing background each time
Reply #1 - Dec 13th, 2007, 7:27am
 
there are different solutions:

1) the object-oriented way would be, instead of just putting images on screen with image(red,random(0,width),random(width),siz,siz);, make each image an object stored in an array. at each frame, you erase everything, draw the objects stored in the array, and then draw your animation over it.

2) another way to achieve the same result : you may use a buffer for the background where the images appear, and at each frame, erase everything on the screen, display the buffer, and then draw your animation over it. see http://processing.org/reference/createGraphics_.html for how to use and display a buffer
Re: Animating and changing background each time
Reply #2 - Dec 15th, 2007, 3:52am
 
Thanks a lot, after some tricky array handling I managed it, you are very helpful, wish i could repay the favour!
Page Index Toggle Pages: 1