forked from AmrSaber/ComputerGraphics-OpenGL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinal.pde
96 lines (76 loc) · 2.15 KB
/
Final.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
//import processing.sound.*;
Star[] stars;
Grass[] grass;
Fly[] flies;
ArrayList<Butterfly> butterflies;
ArrayList<Meteor> meteors;
boolean isLooping = true;
//SoundFile soundFile;
void setup(){
fullScreen(P3D);
frameRate(30);
noCursor();
//soundFile = new SoundFile(this, "night_sound.mp3");
//soundFile.loop();
stars = new Star[300];
for (int i = 0 ; i < stars.length ; ++i){
stars[i] = new Star((int) random(0,width), (int)random(0,7*height/8), random(0.01,0.05));
}
grass = new Grass[width];
for (int i = 0 ; i < grass.length ; ++i) grass[i] = new Grass(random(35, 45), i, height);
flies = new Fly[20];
for (int i = 0 ; i < flies.length ; ++i) flies[i] = new Fly(7 * height / 8);
butterflies = new ArrayList<Butterfly>();
meteors = new ArrayList<Meteor>();
}
void draw(){
setGradient();
for (int i = 0 ; i < stars.length ; ++i) stars[i].display();
for (int i = 0 ; i < grass.length ; ++i) grass[i].display();
for (int i = 0 ; i < flies.length ; ++i) flies[i].display();
for (int i = 0 ; i < butterflies.size() ; ++i) butterflies.get(i).display();
for (int i = 0 ; i < meteors.size() ; ++i) meteors.get(i).display();
handleButterflies();
handleMeteors();
}
void setGradient() {
noFill();
background(0);
color c1 = color(0, 32, 90);
color c2 = color(0);
for (int i = 0 ; i <= height ; ++i) {
float inter = map(i, 0, height, 0, 1);
color c = lerpColor(c1, c2, inter);
stroke(c);
strokeWeight(1);
line(0, i, width, i);
}
}
void handleButterflies(){
for (int i = 0 ; i < butterflies.size() ; ++i) {
if (butterflies.get(i).x > width + 10) {
butterflies.remove(i);
--i;
}
}
if (butterflies.size() < 1 || (random(1) < 0.005 && butterflies.size() < 10)) {
butterflies.add(new Butterfly());
}
}
void handleMeteors(){
for (int i = 0 ; i < meteors.size() ; ++i) {
if (meteors.get(i).isGone) {
meteors.remove(i);
--i;
}
}
if (random(1) < 0.0025 && meteors.size() < 5) {
meteors.add(new Meteor());
}
}
void keyPressed(){
if (key != ' ') return;
if (isLooping) noLoop();
else loop();
isLooping = !isLooping;
}