forked from yangsu/Synaptic-Wall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drawable.pde
89 lines (76 loc) · 1.9 KB
/
Drawable.pde
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
public abstract class Drawable extends Constants {
protected color fColor;
protected color fHighlightColor;
protected PVector fLoc;
protected boolean fVisible;
protected boolean fMovable;
protected int fBirthTime;
public Drawable() {
this(0, 0, color(255));
}
public Drawable(float x, float y) {
this(x, y, color(255));
}
public Drawable(float x, float y, color cc) {
fLoc = new PVector(x, y);
fVisible = fMovable = true;
fColor = cc;
if (cc == EX_COLOR)
fHighlightColor = EX_HIGHLIGHT_COLOR;
else if (cc == IN_COLOR)
fHighlightColor = IN_HIGHLIGHT_COLOR;
else
fHighlightColor = Util.highlight(fColor);
fBirthTime = millis();
}
public void flipColor() {
if (fColor == EX_COLOR) {
fColor = IN_COLOR;
fHighlightColor = IN_HIGHLIGHT_COLOR;
}
else if (fColor == IN_COLOR) {
fColor = EX_COLOR;
fHighlightColor = EX_HIGHLIGHT_COLOR;
}
else if (fColor == EX_HIGHLIGHT_COLOR) {
fColor = IN_HIGHLIGHT_COLOR;
fHighlightColor = Util.highlight(fColor);
}
else if (fColor == IN_HIGHLIGHT_COLOR) {
fColor = EX_HIGHLIGHT_COLOR;
fHighlightColor = Util.highlight(fColor);
}
else {
println("unknow color");
}
}
public abstract int getType();
public PVector getLoc() {
return fLoc;
}
public void translate(PVector change) {
if (fMovable)
fLoc.add(change);
}
public void setVisible(boolean visible) {
fVisible = visible;
}
public void setMovable(boolean movable) {
fMovable = movable;
}
public void drawBackground() {};
public void drawForeground() {};
public void draw() {
if (fVisible) {
drawBackground();
drawForeground();
}
}
public void update() {
//Perform functions that produce animations or other forms of change over time
};
public void drawAndUpdate() {
update();
draw();
}
}