-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathIpod.java
64 lines (51 loc) · 1.95 KB
/
Ipod.java
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
package edu.ucsb.cs56.drawings.andrewberls.advanced;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Ellipse2D;
import edu.ucsb.cs56.drawings.utilities.ShapeTransforms;
import edu.ucsb.cs56.drawings.utilities.GeneralPathWrapper;
/**
A vector drawing of an Ipod that implements
the Shape interface, and so can be drawn, as well as
rotated, scaled, etc.
@author Andrew Berls
@version for CS56, W14, UCSB
*/
public class Ipod extends GeneralPathWrapper implements Shape {
/**
Constructor
@param x the coordinate of the left edge
@param y the coordinate of the top
@param width the width of the iPod
*/
public Ipod(double x, double y, double bodyWidth)
{
double padding = 10;
double bodyHeight = 1.5 * bodyWidth;
double screenWidth = bodyWidth - (2*padding);
double screenHeight = .66 * bodyWidth;
double screenX = x + (bodyWidth - screenWidth)/2;
double screenY = y + (bodyWidth - screenWidth)/2;
double scrollOuterRadius = 0.35 * screenWidth;
double scrollOuterX = x + bodyWidth/2;
double scrollOuterY = y + screenHeight + (padding/2) + (bodyHeight-screenHeight)/2;
Rectangle2D.Double body =
new Rectangle2D.Double(x, y, bodyWidth, bodyHeight);
Rectangle2D.Double screen =
new Rectangle2D.Double(screenX, screenY, screenWidth, screenHeight);
Ellipse2D.Double scrollWheelOuter =
new Ellipse2D.Double(scrollOuterX-scrollOuterRadius,
scrollOuterY-scrollOuterRadius,
scrollOuterRadius*2, scrollOuterRadius*2);
// put the whole iPod together
GeneralPath iPod = this.get();
iPod.append(body, false);
iPod.append(screen, false);
iPod.append(scrollWheelOuter, false);
}
}