forked from llovett/CAMusic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawableObject.java
140 lines (112 loc) · 2.37 KB
/
DrawableObject.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* DrawableObject.java
*
* Just a nice way to use object-oriented-style programming with
* drawing, using the Processing library.
*
* @author okami89
**/
import processing.core.*;
import java.awt.Color;
public class DrawableObject {
// Member responsible for doing the actual rendering.
private PApplet parent;
// Width, height, x, y
private int w, h, x, y;
// Stroke width, bgcolor, stroke color
private int strokeWidth;
private int r,g,b,a;
private int sr,sg,sb,sa;
public DrawableObject(PApplet parent) {
this.parent = parent;
r = g = b = a = sr = sg = sb = sa = 0;
w = h = x = y = 0;
strokeWidth = 0;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getWidth() {
return w;
}
public int getHeight() {
return h;
}
public int getStrokeWidth() {
return strokeWidth;
}
public int[] getColor() {
return new int[]{ r, g, b, a };
}
public int[] getStrokeColor() {
return new int[]{ sr, sg, sb, sa };
}
/******************
* MUTATOR METHODS *
******************/
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setPos(int x, int y) {
this.x = x;
this.y = y;
}
public void setWidth(int w) {
this.w = w;
}
public void setHeight(int h) {
this.h = h;
}
public void setSize(int w, int h) {
this.w = w;
this.h = h;
}
public void setStrokeWidth(int strokeWidth) {
this.strokeWidth = strokeWidth;
}
public void setColor(int r, int g, int b) {
this.r = r;
this.g = g;
this.b = b;
}
public void setColor(Color c) {
setColor(c.getRed(),
c.getGreen(),
c.getBlue(),
c.getAlpha());
}
public void setColor(int r, int g, int b, int a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
public void setStrokeColor(int sr, int sg, int sb) {
this.sr = sr;
this.sg = sg;
this.sb = sb;
}
public void setStrokeColor(int sr, int sg, int sb, int sa) {
this.sr = sr;
this.sg = sg;
this.sb = sb;
this.sa = sa;
}
/**
* setupDrawPrefs()
*
* Set up the drawing environment for rendering this
* object properly.
**/
public void setupDrawPrefs() {
parent.fill(r, g, b, a);
parent.stroke(sr, sg, sb, sa);
parent.strokeWeight(strokeWidth);
}
}