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 an image without using background
Page Index Toggle Pages: 1
Animating an image without using background (Read 759 times)
Animating an image without using background
Jan 11th, 2006, 3:32pm
 
Hi there,
I am new to Processing.I have an array of images displayed on screen.I want to animate a particular  image to new posiiton,how it can be done without using background method?

I tried to display all images at there old position except one which I want to move( which is displayed towards new position).
Every time I need to set background and then display all the images.But in that way it became very slow.

plz help

Thanks,
Re: Animating an image without using background
Reply #1 - Jan 11th, 2006, 4:29pm
 
You can't redraw to the screen with out calling background(). Otherwise the stuff just builds up. Without seeing your code I'm guessing that you're running through an array of images and putting them on screen every loop of draw().

I think one solution might be to save the image of the applet in a PImage and then use that as your background. Then when you need to make your changes, only draw the couple of images you're moving about and save the screen again.

Again my psychic powers are a bit rusty but here's how to save the screen:
Code:

PImage saveMe;
void setup(){
size(200,200);
saveMe = new PImage(width,height);
rect(20,20,20,20);
loadPixels();
saveMe = get();
}
void draw(){
background(0);
image(saveMe,mouseX,mouseY);
}
Re: Animating an image without using background
Reply #2 - Jan 12th, 2006, 6:15pm
 
Hi there,
I tried to save the whole screen as image but still it is slow.Actually I have an array of images to be displayed in a row.And then I need to transit every image (or some images depending upon an algorithm) to some new position(one at a time).
What I want is, this transition to be smooth and clearly visible. Right now it is not smooth so I am not able to visualise the transition.
could you please suggest something..

Thanks,
Re: Animating an image without using background
Reply #3 - Jan 14th, 2006, 12:58am
 
I've knocked up a demonstration of Processing chucking up 8 * 6 PImages a frame. It doesn't seem to run that slow. Could you say how you've done it differently to the example I've demonstrated? If you could post the offending bit of code it would help a lot - you might be able to use my "buffer filler" to avoid referring to mystery images.
Code:

PImage [] strip;
int offset = 0;
int stripSize = 100;
void setup(){
size(800,600);
smooth();
stroke(255);
//create a buffer of images of a spinning stick
//so principle can be demonstrated from pure code
strip = new PImage[width / stripSize];
for(int i = 0; i < strip.length; i++){
strip[i] = new PImage(stripSize, stripSize);
background(0);
float x = 50 + cos((TWO_PI / strip.length) * i) * 50;
float y = 50 + sin((TWO_PI / strip.length) * i) * 50;
line(50, 50, x, y);
loadPixels();
//"g" is a PImage that holds the image of the applet
//copy() should be able to work with out it there but on 98 it doesn't
//I'll try to remember to post a bug
strip[i].copy(g, 0, 0, strip[i].width, strip[i].height, 0, 0, strip[i].width, strip[i].height);
}
}
void draw(){
for(int i = 0; i < height / stripSize; i++){
for(int j = 0; j < strip.length; j++){
image(strip[j], ((j + offset) % strip.length) * strip[j].width, i * strip[j].height);
}
}
offset = (offset + 1) % strip.length;
}
Page Index Toggle Pages: 1