forked from APCSLowell/Starfield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Starfield.pde
64 lines (53 loc) · 1.13 KB
/
Starfield.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
Particle[] p=new Particle[2080];
void setup(){
size(800,800);
background(0);
for(int i=0; i<p.length;i++)
p[i]=new Particle();
for(int i=2000; i<p.length;i++)
p[i]= new Weirdo();
}
void draw(){
background(0);
for(int i=0; i<p.length;i++){
p[i].show();
p[i].move();
}
}
void mousePressed(){
for(int i=0; i<p.length;i++)
p[i]=new Particle();
for(int i=990; i<p.length;i++)
p[i]= new Weirdo();
redraw();
}
class Particle{
double myX,myY,myAngle,mySpeed;
int myColor,mySize;
Particle(){
myX= mouseX;
myY= mouseY;
myAngle=(Math.random()*2*Math.PI);
mySpeed=(Math.random()*15+1);
myColor=color((int)(Math.random()*256),0,(int)(Math.random()*256));
mySize=15/(int)mySpeed+10;
}
void move(){
myX=myX+(Math.cos(myAngle)*mySpeed);
myY=myY+(Math.sin(myAngle)*mySpeed);
}
void show(){
fill(myColor);
ellipse((float)myX,(float)myY,mySize,mySize);
}
}
class Weirdo extends Particle{
Weirdo(){
myX= mouseX;
myY= mouseY;
myAngle=(Math.random()*4*Math.PI/2);
mySpeed=2;
myColor=color(0,(int)(Math.random()*256),255);
mySize=30;
}
}