Skip to content

Commit a448433

Browse files
committed
Initial commit.
0 parents  commit a448433

24 files changed

+1909
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/bin
2+
/target
3+
.settings
4+
.classpath
5+
.project
6+
/javadoc
7+
*.swp

LICENSE.txt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015 Julian Fleischer
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
jazz-examples
2+
=============
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package de.scravy.jazz.examples;
2+
3+
import de.scravy.jazz.Animation;
4+
import de.scravy.jazz.Jazz;
5+
import de.scravy.jazz.Picture;
6+
import de.scravy.jazz.pictures.mutable.Pictures;
7+
import de.scravy.jazz.pictures.mutable.Rectangle;
8+
9+
public class Animate {
10+
11+
public static void main(final String... args) {
12+
Jazz.animate(
13+
"Simple Animation",
14+
1000, 600,
15+
new Animation() {
16+
17+
private final Pictures pictures = new Pictures(
18+
new Rectangle(200, 200).color(0, 0, 0, 0.5)
19+
.filled(true).rotate(0),
20+
new Rectangle(200, 200).color(0, 0, 0, 0.5)
21+
.filled(true).rotate(0)
22+
);
23+
24+
@Override
25+
public void update(final double time, final double delta) {
26+
pictures.get(0).remove().rotate(time * 40);
27+
pictures.get(1).remove().rotate(time * -40);
28+
}
29+
30+
@Override
31+
public Picture getPicture() {
32+
return pictures;
33+
}
34+
})
35+
.onClose(new Runnable() {
36+
@Override
37+
public void run() {
38+
System.exit(0);
39+
}
40+
})
41+
.antiAlias(true);
42+
;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package de.scravy.jazz.examples;
2+
3+
import de.scravy.jazz.Event;
4+
import de.scravy.jazz.Jazz;
5+
import de.scravy.jazz.Picture;
6+
import de.scravy.jazz.World;
7+
import de.scravy.jazz.pictures.mutable.Pictures;
8+
import de.scravy.jazz.pictures.mutable.Pie;
9+
10+
public class Arcs {
11+
12+
public static void main(String... args) {
13+
Jazz.play(
14+
"Woohoo", 800, 600, new World() {
15+
16+
double mouthOpening = 0;
17+
double posPacManX = 0;
18+
double posPacManY = 0;
19+
double pacManRotate = 0;
20+
double speedX = 1;
21+
double speedY = 0;
22+
23+
@Override
24+
public void update(double time, double delta) {
25+
mouthOpening = Math.abs(30 * Math.sin(time * 5));
26+
27+
posPacManX += speedX * delta * 50;
28+
posPacManY += speedY * delta * 50;
29+
}
30+
31+
@Override
32+
public Picture getPicture() {
33+
return new Pictures(
34+
new Pie(200, 200,
35+
pacManRotate + mouthOpening,
36+
pacManRotate + 360 - mouthOpening)
37+
.translate(posPacManX, posPacManY)
38+
.filled(true)
39+
);
40+
}
41+
42+
@Override
43+
public void on(Event e) {
44+
switch (e.getType()) {
45+
case KEY_DOWN:
46+
switch (e.getKey()) {
47+
case DOWN:
48+
speedX = 0;
49+
speedY = -1;
50+
pacManRotate = -90;
51+
break;
52+
case UP:
53+
speedX = 0;
54+
speedY = 1;
55+
pacManRotate = 90;
56+
break;
57+
case LEFT:
58+
speedX = -1;
59+
speedY = 0;
60+
pacManRotate = 180;
61+
break;
62+
case RIGHT:
63+
speedX = 1;
64+
speedY = 0;
65+
pacManRotate = 0;
66+
break;
67+
default:
68+
break;
69+
}
70+
break;
71+
default:
72+
break;
73+
}
74+
}
75+
}).onClose(new Runnable() {
76+
@Override
77+
public void run() {
78+
System.exit(0);
79+
}
80+
}).maxFps(120);
81+
}
82+
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package de.scravy.jazz.examples;
2+
3+
import de.scravy.jazz.Animation;
4+
import de.scravy.jazz.Colors;
5+
import de.scravy.jazz.Jazz;
6+
import de.scravy.jazz.Picture;
7+
import de.scravy.jazz.pictures.mutable.Pictures;
8+
import de.scravy.jazz.pictures.mutable.Rectangle;
9+
10+
public class Funky extends Animation {
11+
12+
public static void main(final String... args) {
13+
Jazz.animate("Funky town", 1000, 600, new Funky());
14+
}
15+
16+
private Pictures pictures = new Pictures();
17+
18+
public Funky() {
19+
final Rectangle r = new Rectangle(50, 50).filled(true);
20+
21+
for (int i = -525; i <= 525; i += 50) {
22+
for (int j = -325; j <= 325; j += 50) {
23+
this.pictures
24+
.add(r.clone().color(Colors.randomColor()).translate(i, j));
25+
}
26+
}
27+
}
28+
29+
@Override
30+
public void update(final double time, final double delta) {
31+
for (final Picture p : this.pictures) {
32+
p.color(Colors.randomColor(-1, 0, 0));
33+
}
34+
this.pictures.reset()
35+
.scale(2 * Math.sin(time), 2 * Math.sin(time))
36+
.rotate(time * 100);
37+
}
38+
39+
@Override
40+
public Picture getPicture() {
41+
return this.pictures;
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package de.scravy.jazz.examples;
2+
3+
import de.scravy.jazz.Animation;
4+
import de.scravy.jazz.Jazz;
5+
import de.scravy.jazz.Picture;
6+
import de.scravy.jazz.Vector;
7+
import de.scravy.jazz.pictures.mutable.Circle;
8+
import de.scravy.jazz.pictures.mutable.Pictures;
9+
import de.scravy.jazz.pictures.mutable.Polygon;
10+
11+
public class Polygons {
12+
13+
public static void main(String... args) {
14+
Jazz.animate(
15+
"Woohoo", 640, 480, new Animation() {
16+
17+
Pictures pictures = new Pictures(
18+
new Circle(25).filled(true),
19+
new Polygon(
20+
new Vector(-50, 100),
21+
new Vector(-100, -50),
22+
new Vector(-200, 0)).filled(true)
23+
.color(255,
24+
0, 255, 0.35).translate(100, -25)
25+
.rotate(0),
26+
new Polygon(
27+
new Vector(200, 200),
28+
new Vector(100, 100),
29+
new Vector(200, 0),
30+
new Vector(0, 0),
31+
new Vector(0, 200)).filled(true)
32+
.color(255, 0,
33+
0, 0.5).translate(-100, -100)
34+
.rotate(0));
35+
36+
@Override
37+
public void update(double time, double delta) {
38+
pictures.get(1).remove().rotate(time * 45);
39+
pictures.get(2).remove().rotate(time * -90);
40+
}
41+
42+
@Override
43+
public Picture getPicture() {
44+
return pictures;
45+
}
46+
}).onClose(new Runnable() {
47+
@Override
48+
public void run() {
49+
System.exit(0);
50+
}
51+
}).maxFps(120);
52+
}
53+
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package de.scravy.jazz.examples;
2+
3+
import de.scravy.jazz.Animation;
4+
import de.scravy.jazz.Jazz;
5+
import de.scravy.jazz.Picture;
6+
import de.scravy.jazz.pictures.mutable.Pictures;
7+
import de.scravy.jazz.pictures.mutable.Polygon;
8+
9+
public class Polygons2 {
10+
11+
public static void main(final String... args) {
12+
Jazz.animate(
13+
"Woohoo", 800, 600, new Animation() {
14+
15+
Pictures pictures = new Pictures();
16+
{
17+
for (int i = 3; i < 15; i++) {
18+
pictures.add(new Polygon(i, (i - 2) * 25));
19+
}
20+
}
21+
22+
@Override
23+
public void update(final double time, final double delta) {
24+
double i = 30;
25+
for (final Picture p : pictures) {
26+
p.reset().rotate(time * i);
27+
i *= -1;
28+
}
29+
}
30+
31+
@Override
32+
public Picture getPicture() {
33+
return pictures;
34+
}
35+
36+
}).onClose(new Runnable() {
37+
@Override
38+
public void run() {
39+
System.exit(0);
40+
}
41+
}).maxFps(120);
42+
}
43+
44+
}

0 commit comments

Comments
 (0)