-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject.pde
130 lines (111 loc) · 2.26 KB
/
Object.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
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
class Object
{
PVector location, velocity, acceleration, size;
float radius, theta, r, lifespan;
color col;
//main constructor
Object(float x, float y, float w, float h, boolean isDynamic, boolean isBoid)
{
size = new PVector(w, h);
if (isDynamic && isBoid)
{
location = new PVector(x,y);
velocity = new PVector(random(-1,1),random(-1,1));
acceleration = new PVector(0,0);
}
else if (isDynamic && !(isBoid))
{
location = new PVector(x, y);
velocity = new PVector(0, 0);
acceleration = new PVector(0, 0);
}
else
{
location = new PVector(x, y);
}
lifespan = 255.00;
}
//pulse constructor
Object(float x, float y, float w, float h, float rad, float thet)
{
this(x, y, w, h, true, false);
radius = rad;
theta = thet;
}
//animal constructor
Object(float x, float y, float rB, float rad, float thet, color c)
{
this(x, y, 2*rB, 4*rB, true, false);
r = rB;
radius = rad;
theta = thet;
col = c;
}
//flock constructor
Object(float x, float y, float ra, color c)
{
this(x, y, 2*ra, 4*ra, true, true);
r = ra;
col = c;
}
//handle the display
//provide an option to specify the angle to rotate about for creatures/boids
//and a traditional one for normal linear translation
void display(float ang)
{
float rotation = ang;
rectMode(CENTER);
pushMatrix();
translate(location.x, location.y);
rotate(rotation);
show();
popMatrix();
}
void display()
{
float rotation = velocity.heading2D() + PI/2;
rectMode(CENTER);
pushMatrix();
translate(location.x, location.y);
rotate(rotation);
show();
popMatrix();
}
void show()
{
rect(0,0,size.x,size.y);
}
//wrap-around
void checkEdges()
{
if (location.x > width)
{
location.x = 0;
}
if (location.x < 0)
{
location.x = width;
}
if (location.y > height)
{
location.y = 0;
}
if (location.y < 0)
{
location.y = height;
}
}
void update()
{
checkEdges();
}
//check for object death
boolean isDead()
{
if (lifespan <= 0)
{
return true;
}
return false;
}
}