forked from berndpl/Butterflies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBird.txt
154 lines (125 loc) · 3.09 KB
/
Bird.txt
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import peasy.*;
PeasyCam cam;
// Flock array
int birdCount = 1;
Bird[]birds = new Bird[birdCount];
float[]x = new float[birdCount];
float[]y = new float[birdCount];
float[]z = new float[birdCount];
float[]rx = new float[birdCount];
float[]ry = new float[birdCount];
float[]rz = new float[birdCount];
float[]spd = new float[birdCount];
float[]rot = new float[birdCount];
void setup() {
size(640, 360, P3D);
cam = new PeasyCam(this, 100);
noStroke();
// Initialize arrays with random values
for (int i = 0; i < birdCount; i++){
/*birds[i] = new Bird(random(-300, 300), random(-300, 300),
random(-500, -2500), random(5, 30), random(5, 30)); */
birds[i] = new Bird(0, 0, 0, 1, 5);
/*x[i] = random(20, 340);
y[i] = random(30, 350);
z[i] = random(1000, 4800); */
x[i] = 20;
y[i] = 30;
z[i] = 1000;
rx[i] = 100;
ry[i] = 0;
rz[i] = 0;
spd[i] = 1;
rot[i] = .08;
}
}
void draw() {
background(0);
lights();
for (int i = 0; i < birdCount; i++){
birds[i].setFlight(x[i], y[i], z[i], rx[i], ry[i], rz[i]);
birds[i].setWingSpeed(spd[i]);
birds[i].setRotSpeed(rot[i]);
birds[i].fly();
}
}
class Bird {
// Properties
float offsetX, offsetY, offsetZ;
float w, h;
int bodyFill;
int wingFill;
float ang = 0, ang2 = 0, ang3 = 0, ang4 = 0;
float radiusX = 120, radiusY = 200, radiusZ = 700;
float rotX = 15, rotY = 10, rotZ = 5;
float flapSpeed = 0.4;
float rotSpeed = 0.1;
// Constructors
Bird(){
this(0, 0, 0, 60, 80);
}
Bird(float offsetX, float offsetY, float offsetZ,
float w, float h){
this.offsetX = offsetX;
this.offsetY = offsetY;
this.offsetZ = offsetZ;
this.h = h;
this.w = w;
bodyFill = color(153);
wingFill = color(204);
}
void setFlight(float radiusX, float radiusY, float radiusZ,
float rotX, float rotY, float rotZ){
this.radiusX = radiusX;
this.radiusY = radiusY;
this.radiusZ = radiusZ;
this.rotX = rotX;
this.rotY = rotY;
this.rotZ = rotZ;
}
void setWingSpeed(float flapSpeed){
this.flapSpeed = flapSpeed;
}
void setRotSpeed(float rotSpeed){
this.rotSpeed = rotSpeed;
}
void fly() {
pushMatrix();
float px, py, pz;
// Flight
px = sin(radians(ang3)) * radiusX;
py = cos(radians(ang3)) * radiusY;
pz = sin(radians(ang4)) * radiusZ;
translate(width/2 + offsetX + px, height/2 + offsetY+py, -700 + offsetZ+pz);
rotateX(sin(radians(ang2)) * rotX);
rotateY(sin(radians(ang2)) * rotY);
rotateZ(sin(radians(ang2)) * rotZ);
// Body
fill(bodyFill);
box(w/5, h, w/5);
// Left wing
fill(wingFill);
pushMatrix();
rotateY(sin(radians(ang)) * 20);
rect(0, -h/2, w, h);
popMatrix();
// Right wing
pushMatrix();
rotateY(sin(radians(ang)) * -20);
rect(-w, -h/2, w, h);
popMatrix();
// Wing flap
ang += flapSpeed;
if (ang > 3) {
flapSpeed*=-1;
}
if (ang < -3) {
flapSpeed*=-1;
}
// Ang's run trig functions
ang2 += rotSpeed;
ang3 += 1.25;
ang4 += 0.55;
popMatrix();
}
}