forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlinkingPolygon.java
More file actions
42 lines (36 loc) · 880 Bytes
/
BlinkingPolygon.java
File metadata and controls
42 lines (36 loc) · 880 Bytes
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
import java.awt.Color;
import java.awt.Graphics;
/**
* A polygon that periodically changes colors on/off.
*/
public class BlinkingPolygon extends RegularPolygon {
protected boolean visible;
protected int count;
/**
* Constructs a blinking polygon.
*
* @param nsides the number of sides
* @param radius from center to vertex
* @param color initial fill color
*/
public BlinkingPolygon(int nsides, int radius, Color color) {
super(nsides, radius, color);
visible = true;
count = 0;
}
@Override
public void draw(Graphics g) {
if (visible) {
super.draw(g);
}
}
@Override
public void step() {
// toggle visibility every 10 steps
count++;
if (count == 10) {
visible = !visible;
count = 0;
}
}
}