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 › help with an animation
Page Index Toggle Pages: 1
help with an animation (Read 414 times)
help with an animation
Oct 19th, 2007, 3:41am
 
hey guys im very new to processing and i have an assignment to make. it's basically a little animated show using mouseX to "animate" it. as the mouse moves across the window and is positioned in a specific place, a new picture is supposed to show up. i did that for the first part of my animation and it was fine. however, i now want to show another animation as the mouse moves backwards...how would i do that??? my prof. said something about using a Boolean, but i dont know...heres what i have so far:
___________________________________

PImage e1;
PImage e2;
PImage e3;
PImage e4;
PImage e5;
PImage e6;
PImage e7;
PImage e8;
PImage e9;
PImage e10;
PImage e11;
PImage e12;
PImage e13;
PImage e14;
PFont myFont;

void setup() {  
size(600,400);
background(255);
frameRate(100);
myFont=loadFont("STXihei-48.vlw");
textFont(myFont);
e1= loadImage("egg1.png");
e2= loadImage("egg2.png");
e3= loadImage("egg3.png");
e4= loadImage("egg4.png");
e5= loadImage("egg5.png");
e6= loadImage("egg6.png");
e7= loadImage("egg7.png");
e8= loadImage("egg8.png");
e9= loadImage("egg9.png");
e10= loadImage("egg10.png");
e11= loadImage("egg11.png");
e12= loadImage("egg12.png");
e13= loadImage("egg13.png");
e14= loadImage("egg14.png");
}

void draw() {
float normX = norm(mouseX,0,width);
 int which = int(lerp(0,14,normX));
 println(which);
 
if (which==0) {
 background(255);
 image(e1,width/4.7,height/16,300,375);

}else if (which==1) {
 background(255);
image(e2,width/5,height/16,350,375);

}else if (which==2) {
 background(255);
image(e3,width/4,45,280,350);

}else if (which==3) {
 background(255);
image(e4,width/4,45,280,350);

}else if (which==4) {
 background(255);
 image(e5,width/5,54,280,350);
 
}else if (which==5) {
 background(255);
image(e6,width/3.7,50,280,350);

}else if (which==6) {
 background(255);
image(e7,width/4,50,280,350);

}else if (which==7) {
 background(255);
image(e8,width/3.7,50,280,350);

}else if (which==8) {
 background(255);
image(e9,width/4,45,325,360);

}else if (which==9) {
 background(255);
image(e10,width/3.7,42,285,360);

}else if (which==10) {
 background(255);
image(e11,width/3.7,42,285,360);
 
}else if (which==11) {
 background(255);
image(e12,width/3.7,42,290,360);

}else if (which==12) {
 background(255);
image(e13,width/3.7,42,285,360);

}else if (which==13) {
 background(255);
image(e14,width/3.7,44,298,360);
textFont(myFont);
textSize(30);
fill(250,20,80);
text("the egg came first!",25,150);

}

}
____________________________________________
please help me.

Re: help with an animation
Reply #1 - Oct 19th, 2007, 12:02pm
 
hi. first, you should use an array instead of 14 differents variables :

PImage[] e;

and load images using an iterator :

for (int i = 0; i < e.length; i++) {
 e[i] = loadImage("egg" + i + ".png");
}

(by the way, since an array's index starts at 0, you should name your first image egg0.png and your last egg13.png)

and your images, since they are part of an animation, should all be the same size (IMG_W x IMG_H), so you draw them the same way and at the same position on the screen (IMG_X, IMG_Y) :

image(e[i], IMG_X, IMG_Y, IMG_W, IMG_H);

once you're done with that, we can help you go further... Smiley
Page Index Toggle Pages: 1