-
Notifications
You must be signed in to change notification settings - Fork 0
/
ACloud.pde
206 lines (140 loc) · 4.14 KB
/
ACloud.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
class ACloud{
float _posx,_posy,_pscale;
PVector move_amp,move_vel,move_phi;
int icloud;
boolean is_turbing;
FrameAnimation ani_turb;
PVector pos_turb_src,pos_turb_dest,amp_turb;
ACloud(float set_posx,float set_posy){
_posx=set_posx;
_posy=set_posy;
_pscale=random(.2,1);
icloud=(int)random(2);
move_amp=new PVector(25*random(2),5*random(1));
move_vel=new PVector(random(70,120),random(120,180));
move_phi=new PVector(random(TWO_PI),random(TWO_PI));
is_turbing=false;
ani_turb=new FrameAnimation(320);
}
void draw(PGraphics pg,PImage img_cloud){
pg.pushStyle();
pg.imageMode(CENTER);
pg.pushMatrix();
if(is_turbing){
float virb_t=ani_turb.GetPortion();
pg.translate(_posx+move_amp.x*60*sin(PI*virb_t*amp_turb.x),_posy+move_amp.y*60*sin(PI*virb_t*amp_turb.y));
}else{
pg.translate(_posx+move_amp.x*sin((float)frameCount/move_vel.x+move_phi.x),_posy+move_amp.y*cos((float)frameCount/move_vel.y+move_phi.y));
}
pg.scale(_pscale*(icloud==2?1.3:1));
pg.image(img_cloud,0,0);
pg.popMatrix();
pg.popStyle();
}
void update(){
if(is_turbing){
ani_turb.Update();
if(!ani_turb.ani_start) is_turbing=false;
}
}
void triggerTurb(){
if(is_turbing) return;
amp_turb=new PVector((int)random(2,6)*(random(2)<1?1:-1),(int)random(2,6)*(random(2)<1?1:-1));
ani_turb.Restart();
is_turbing=true;
}
}
class ASpaceShip{
float _posx,_posy,_pscale;
PVector move_amp,move_vel,move_phi;
ASpaceShip(float set_posx,float set_posy){
_posx=set_posx;
_posy=set_posy;
_pscale=random(.75,1);
move_amp=new PVector(random(900,1500),random(50));
move_vel=new PVector(random(420,650),random(40,80));
move_phi=new PVector(random(TWO_PI),random(TWO_PI));
}
void draw(PGraphics pg,PImage img_ship){
pg.pushStyle();
pg.imageMode(CENTER);
pg.textureMode(NORMAL);
pg.noStroke();
pg.pushMatrix();
pg.translate(_posx+move_amp.x*sin((float)frameCount/move_vel.x+move_phi.x),_posy+move_amp.y*cos((float)frameCount/move_vel.y+move_phi.y));
pg.scale(_pscale);
// pg.image(img_ship,0,0);
float tmp_phi=((float)frameCount/move_vel.x+move_phi.x);
boolean dir=!(tmp_phi%TWO_PI<HALF_PI||tmp_phi%TWO_PI>HALF_PI*3);
pg.beginShape();
pg.texture(img_ship);
pg.vertex(-104,-33,dir?0:1,0);
pg.vertex(104,-33,dir?1:0,0);
pg.vertex(104,33,dir?1:0,1);
pg.vertex(-104,33,dir?0:1,1);
pg.endShape();
pg.popMatrix();
pg.popStyle();
}
}
class AStar{
float _posx,_posy,_pscale;
PVector move_amp;//
float move_vel,move_phi;
float move_delay;
AStar(float set_posx,float set_posy){
_posx=set_posx;
_posy=set_posy;
_pscale=random(.75,1);
float k=5;//random(5,20);
move_amp=new PVector(-150*k,112*k);
move_vel=random(100,200);
move_phi=random(move_vel);
move_delay=random(move_vel,move_vel*5);
}
void draw(PGraphics pg,PImage img_star){
pg.pushStyle();
pg.imageMode(CENTER);
pg.textureMode(NORMAL);
pg.noStroke();
pg.pushMatrix();
float _pos=constrain(((frameCount+move_phi)%(move_vel+move_delay))/move_vel,0,1);
pg.translate(_posx,_posy);
// pg.rotate(move_phi.y);
pg.translate(move_amp.x*_pos,move_amp.y*_pos);
pg.scale(_pscale);
pg.image(img_star,0,0);
pg.popMatrix();
pg.popStyle();
}
}
class ASpaceBalloon{
float _posx,_posy,_pscale;
PVector move_amp;//
PVector move_vel,move_phi;
float move_delay;
int bindex=(int)random(4);
ASpaceBalloon(float set_posx,float set_posy){
_posx=set_posx;
_posy=set_posy;
_pscale=random(.75,1);
move_amp=new PVector(random(4,10),set_posy+100);
move_vel=new PVector(random(10,30),random(450,600));
move_phi=new PVector(random(TWO_PI),random(TWO_PI));
move_delay=random(move_vel.x);
}
void draw(PGraphics pg,PImage img_balloon){
pg.pushStyle();
pg.imageMode(CENTER);
pg.textureMode(NORMAL);
pg.noStroke();
pg.pushMatrix();
float up_t=(((float)frameCount+move_phi.y)%move_vel.y)/move_vel.y;
if(up_t<.005) bindex=(int)random(4);
pg.translate(_posx+move_amp.x*sin((float)frameCount/move_vel.x+move_phi.x),_posy-move_amp.y*sin(up_t*HALF_PI));
pg.scale(_pscale);
pg.image(img_balloon,0,0);
pg.popMatrix();
pg.popStyle();
}
}