mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 19:31:16 +01:00
28 lines
602 B
Plaintext
28 lines
602 B
Plaintext
// Class for animating a sequence of GIFs
|
|
|
|
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 + nf(i, 4) + ".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;
|
|
}
|
|
}
|