|
1
|
|
|
package example; |
|
2
|
|
|
|
|
3
|
|
|
import org.gannacademy.cdf.graphics.Text; |
|
4
|
|
|
import org.gannacademy.cdf.graphics.geom.Rectangle; |
|
5
|
|
|
import org.gannacademy.cdf.graphics.geom.*; |
|
6
|
|
|
import org.gannacademy.cdf.graphics.ui.AppWindow; |
|
7
|
|
|
|
|
8
|
|
|
import java.awt.*; |
|
9
|
|
|
import java.awt.geom.Point2D; |
|
10
|
|
|
|
|
11
|
|
|
public class TransformationDemo extends AppWindow { |
|
12
|
|
|
Path p, q, r, s; |
|
13
|
|
|
Rectangle a; |
|
14
|
|
|
RoundRectangle b; |
|
15
|
|
|
Ellipse c; |
|
16
|
|
|
Arc d; |
|
17
|
|
|
|
|
18
|
|
|
boolean inflation = true; |
|
19
|
|
|
int steps = 0; |
|
20
|
|
|
|
|
21
|
|
|
@Override |
|
22
|
|
|
protected void setup() { |
|
23
|
|
|
Color |
|
24
|
|
|
transparentRed = new Color(1f, 0f, 0f, 0.5f), |
|
25
|
|
|
transparentBlue = new Color(0f, 0f, 1f, 0.5f); |
|
26
|
|
|
|
|
27
|
|
|
a = new Rectangle(100, 50, 150, 100, getDrawingPanel()); |
|
28
|
|
|
a.setFillColor(transparentRed); |
|
29
|
|
|
b = new RoundRectangle(350, 50, 150, 100, 25, 25, getDrawingPanel()); |
|
30
|
|
|
b.setFillColor(transparentRed); |
|
31
|
|
|
c = new Ellipse(100, 250, 150, 100, getDrawingPanel()); |
|
32
|
|
|
c.setFillColor(transparentRed); |
|
33
|
|
|
d = new Arc(350, 250, 150, 100, 117, 312, getDrawingPanel()); |
|
34
|
|
|
d.setFillColor(transparentRed); |
|
35
|
|
|
|
|
36
|
|
|
p = a.getAsPath(); |
|
37
|
|
|
p.setFillColor(transparentBlue); |
|
38
|
|
|
q = b.getAsPath(); |
|
39
|
|
|
q.setFillColor(transparentBlue); |
|
40
|
|
|
r = c.getAsPath(); |
|
41
|
|
|
r.setFillColor(transparentBlue); |
|
42
|
|
|
s = d.getAsPath(); |
|
43
|
|
|
s.setFillColor(transparentBlue); |
|
44
|
|
|
|
|
45
|
|
|
Text t = new Text("Translate", 0, 0, getDrawingPanel()); |
|
46
|
|
|
t.setLocation(a.getX() + (a.getWidth() - t.getWidth()) / 2, a.getY() + (a.getHeight() - t.getHeight()) / 2 + t.getMaxAscent()); |
|
47
|
|
|
t = new Text("Shear", 0, 0, getDrawingPanel()); |
|
48
|
|
|
t.setLocation(b.getX() + (b.getWidth() - t.getWidth()) / 2, b.getY() + (b.getHeight() - t.getHeight()) / 2 + t.getMaxAscent()); |
|
49
|
|
|
t = new Text("Scale", 0, 0, getDrawingPanel()); |
|
50
|
|
|
t.setLocation(c.getX() + (c.getWidth() - t.getWidth()) / 2, c.getY() + (c.getHeight() - t.getHeight()) / 2 + t.getMaxAscent()); |
|
51
|
|
|
t = new Text("Rotate", 0, 0, getDrawingPanel()); |
|
52
|
|
|
t.setLocation(d.getX() + (d.getWidth() - t.getWidth()) / 2, d.getY() + (d.getHeight() - t.getHeight()) / 2 + t.getMaxAscent()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
@Override |
|
56
|
|
|
protected void loop() { |
|
57
|
|
|
steps++; |
|
58
|
|
|
if (steps > 100) { |
|
59
|
|
|
inflation = !inflation; |
|
60
|
|
|
steps = 0; |
|
61
|
|
|
} |
|
62
|
|
|
p.translate(.6 * (inflation ? 1 : 0 - 1), .4 * (inflation ? 1 : 0 - 1)); |
|
63
|
|
|
Point2D p = r.getLocation(); |
|
|
|
|
|
|
64
|
|
|
r.scale(1 + (inflation ? 1 : 0 - 1) * .01, 1 + (inflation ? 1 : 0 - 1) * .01); |
|
65
|
|
|
r.setLocation(p.getX(), p.getY()); |
|
66
|
|
|
p = q.getLocation(); |
|
67
|
|
|
q.shear(.01 * (inflation ? 1 : 0 - 1), .01 * (inflation ? 1 : 0 - 1)); |
|
68
|
|
|
q.setLocation(p.getX(), p.getY()); |
|
69
|
|
|
s.rotate(Math.PI / 180 * (inflation ? 1 : 0 - 1), 425, 300); |
|
70
|
|
|
sleep(100); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public static void main(String[] args) { |
|
74
|
|
|
new TransformationDemo(); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|