Pug and Corgi Transformation

Screen Shot 2017-02-23 at 8.44.38 AM.png

Screen Shot 2017-02-23 at 8.44.49 AM.png

float xpos;
float ypos;
float drag = 30.0;
Animation animation1, animation2;

void setup() {
size(600, 600);
background(255, 204, 0);
frameRate(20);
smooth();
animation1 = new Animation(“corgi”, 12);
animation2 = new Animation(“shiba”, 20);
}
void draw() {
float dx = mouseX – xpos;
xpos = xpos + dx/drag;

// Display the sprite at the position xpos, ypos
if (mousePressed) {
background(153, 153, 0);
animation1.display(xpos-animation1.getWidth()/2, ypos);
} else {
background(255, 204, 0);
animation2.display(xpos-animation2.getWidth()/2, ypos);
}
}

class Animation {
PImage[] images;
int imageCount;
int frame;

Animation(String imagePrefix, int count) {
imageCount = count;
images = new PImage[imageCount];

for (int i = 0; i < imageCount; i++) {
// Use nf() to number format ‘i’ into four digits
String filename = imagePrefix + i + “.gif”;
images[i] = loadImage(filename);
}
}

void display(float xpos, float ypos) {
frame = (frame+1) % imageCount;
image(images[frame], xpos, ypos);
}

int getWidth() {
return images[0].width;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s