|
| 1 | +package de.scravy.jazz.examples; |
| 2 | + |
| 3 | +import java.awt.geom.AffineTransform; |
| 4 | +import java.io.IOException; |
| 5 | + |
| 6 | +import de.scravy.jazz.Animation; |
| 7 | +import de.scravy.jazz.Color; |
| 8 | +import de.scravy.jazz.Jazz; |
| 9 | +import de.scravy.jazz.Picture; |
| 10 | +import de.scravy.jazz.pictures.mutable.Bitmap; |
| 11 | +import de.scravy.jazz.pictures.mutable.Pictures; |
| 12 | +import de.scravy.jazz.pictures.mutable.Rectangle; |
| 13 | + |
| 14 | +public class Images { |
| 15 | + |
| 16 | + public static void main(String... args) throws IOException { |
| 17 | + |
| 18 | + Jazz.animate( |
| 19 | + "On this page you see a little girl giggling at a Hippopotamus", |
| 20 | + 1400, 900, new Animation() { |
| 21 | + |
| 22 | + Bitmap bitmap = new Bitmap(Images.class, "hippo.png") |
| 23 | + .scale(0.5, 0.5); |
| 24 | + AffineTransform s = bitmap.getTransform(); |
| 25 | + double x[] = { 400, 400, -400, -400, 400, -400, 0, 0, 0 }; |
| 26 | + double y[] = { 300, -300, 300, -300, 0, 0, 300, -300, 0 }; |
| 27 | + AffineTransform t[] = new AffineTransform[x.length]; |
| 28 | + Pictures pictures = new Pictures(new Rectangle(1400, 900) |
| 29 | + .color(Color.BLACK).filled(true)); |
| 30 | + |
| 31 | + { |
| 32 | + for (int i = 0; i < t.length; i++) { |
| 33 | + Bitmap b = bitmap.clone().reset() |
| 34 | + .translate(x[i], y[i]); |
| 35 | + t[i] = b.getTransform(); |
| 36 | + pictures.add(b); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public void update(double time, double delta) { |
| 42 | + for (int i = 0; i < t.length; i++) { |
| 43 | + pictures.get(i + 1).reset().transform(s) |
| 44 | + .rotate(time * (i + 1) * Math.pow(-1, i)) |
| 45 | + .transform(t[i]); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public Picture getPicture() { |
| 51 | + return pictures; |
| 52 | + } |
| 53 | + |
| 54 | + }).maxFps(80); |
| 55 | + |
| 56 | + } |
| 57 | +} |
0 commit comments