|
1
|
|
|
package org.gannacademy.cdf.turtlelogo; |
|
2
|
|
|
|
|
3
|
|
|
import java.awt.*; |
|
4
|
|
|
import java.awt.geom.Line2D; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Turtles make visible tracks in terraria (by dragging their pens, of course) |
|
8
|
|
|
* |
|
9
|
|
|
* @author <a href="https://github.com/gann-cdf/turtlelogo/issues">Seth Battis</a> |
|
10
|
|
|
*/ |
|
11
|
|
|
public class Track { |
|
12
|
|
|
private Line2D.Double segment; |
|
13
|
|
|
private Stroke stroke; |
|
14
|
|
|
private Color color; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* <p>Construct a new track segment</p> |
|
18
|
|
|
* |
|
19
|
|
|
* <p>May only be called by {@link Turtle} and its subclasses, enforced via {@link Turtle.UnderTheShell}.</p> |
|
20
|
|
|
* |
|
21
|
|
|
* @param x1 coordinate of start |
|
22
|
|
|
* @param y1 coordinate of start |
|
23
|
|
|
* @param x2 coordinate of end |
|
24
|
|
|
* @param y2 coordinate of end |
|
25
|
|
|
* @param color of track |
|
26
|
|
|
* @param stroke style of track |
|
27
|
|
|
* @param key to authenticate "Turtleness" |
|
28
|
|
|
*/ |
|
29
|
|
|
public Track(double x1, double y1, double x2, double y2, Color color, Stroke stroke, Turtle.UnderTheShell key) { |
|
30
|
|
|
key.hashCode(); |
|
31
|
|
|
segment = new Line2D.Double(x1, y1, x2, y2); |
|
32
|
|
|
this.color = color; |
|
33
|
|
|
this.stroke = stroke; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* <p>Draw the track in the terrarium</p> |
|
38
|
|
|
* |
|
39
|
|
|
* <p>May only be called by {@link Terrarium} and its subclasses, enforced via {@link Terrarium.UnderTheSurface}.</p> |
|
40
|
|
|
* |
|
41
|
|
|
* @param context for drawing commands |
|
42
|
|
|
* @param key to authenticate "Terrarium-iality" |
|
43
|
|
|
*/ |
|
44
|
|
|
public void draw(Graphics2D context, Terrarium.UnderTheSurface key) { |
|
45
|
|
|
key.hashCode(); |
|
46
|
|
|
context.setPaint(color); |
|
47
|
|
|
context.setStroke(stroke); |
|
48
|
|
|
context.draw(segment); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|