Using the gifAnimation library it was quite simple to create this little animation.
01 import gifAnimation.*;
02
03 int i = 0;
04 PImage i1,i2,i3;
05 boolean looping = true;
06 int direction = 1;
07 GifMaker gifExport;
08 int frames = -1;
09
10 void setup() {
11 size(400,300, P3D);
12 frameRate(24);
13 gifExport = new GifMaker(this, "export.gif");
14 gifExport.setRepeat(0); // make it an "endless" animation
15
16 i1 = loadImage("img1a.jpg");
17 i2 = loadImage("img2.jpg");
18 i3 = loadImage("img3.jpg");
19 }
20
21 void draw() {
22 frames++;
23 background(255);
24 translate(width/2,height/3);
25 rotateY(direction * (frameCount*PI/100));
26 createCube();
27 gifExport.setDelay(1);
28 gifExport.addFrame();
29 if (frames == 199) noLoop();
30 }
31
32 void createCube() {
33
34 beginShape(QUADS);
35 texture(i1);
36 vertex(0,0,0,0,0); // top left
37 vertex(100,0,0,100,0); // top right
38 vertex(100,100,0,100,100); // bottom right
39 vertex(0,100,0,0,100); // bottom left
40 endShape();
41
42
43 beginShape(QUADS);
44 texture(i2);
45 vertex(0,0,-100,100,0); // top right
46 vertex(100,0,-100,0,0); // top left
47 vertex(100,100,-100,0,100); // bottom left
48 vertex(0,100,-100,100,100); // bottom right
49 endShape();
50
51 beginShape(QUADS);
52 texture(i3);
53 vertex(0,0,0,100,0);
54 vertex(0,0,-100,0,0);
55 vertex(0,100,-100,0,100);
56 vertex(0,100,0,100,100);
57 endShape();
58 }
59
60
No comments:
Post a Comment