- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern.java
More file actions
Latest commit
executable file
·68 lines (59 loc) · 2.67 KB
/
Copy pathPattern.java
File metadata and controls
executable file
·68 lines (59 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
importjava.awt.*;
importjava.awt.geom.*;
publicclassPattern {
/**
* Draws the n-th cirle with lollipops around it
*
* @param center_x x coordinate of first circle
* @param center_y y coordinate of the first circle
* @param center_diameter diameter of the first circle
* @param n n-th circle to be drawn
* @param g2 drawing pen
*/
publicstaticvoiddrawPattern(doublecenter_x, doublecenter_y, doublecenter_diameter, intn, Graphics2Dg2) {
// the first circle has no lollipops and it is colored inside
if (n == 0) {
Areacenter_circle = newArea(
newEllipse2D.Double(center_x, center_y, center_diameter, center_diameter));
g2.fill(center_circle);
} else {
// lollipop parametres
doublestick_width = 0.4 * center_diameter;
doublestick_height = 1.5 * center_diameter;
doublepop_diameter = 0.9 * center_diameter;
// Circle
doublecircle_radius = Math.abs(center_x - 0.8 * center_diameter)
+ (n - 1) * (stick_height + pop_diameter + 10);
doublecircle_x = center_x - circle_radius;
doublecircle_y = center_y - circle_radius;
doublecircle_width = 2 * (Math.abs(circle_x));
Areacircle = newArea(newEllipse2D.Double(circle_x, circle_y, circle_width, circle_width));
// Lollipop
Lollipoplollipop = newLollipop(stick_width, stick_height, pop_diameter);
Rectanglelollipop_bounds = lollipop.getBounds();
// raise the lollipop to the top of the circle
AffineTransformmove = newAffineTransform();
move.translate(0,
-(circle_radius - center_x - Math.abs(lollipop_bounds.getY()) + lollipop_bounds.getHeight()));
lollipop.transform(move);
// rotoate angle for the f(n) lollipop
AffineTransformr = newAffineTransform();
intn0 = f(n);
r.rotate(2 * Math.PI / n0);
// Drawing with g2
ArealollipopArea = lollipop.getArea();
g2.draw(circle);
for (inti = 0; i < n0; i++) {
lollipopArea = lollipopArea.createTransformedArea(r);
g2.fill(lollipopArea);
}
}
}
/**
* @param n n-th circle of the pattern
* @return number of lollipops around the circle
*/
privatestaticintf(intn) {
return (n + 1) * 8;
}
}