forked from APCSLowell/Starfield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Starfield.pde
95 lines (85 loc) · 1.6 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
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
Particle [] bob;
void setup()
{
size(500, 500);
bob=new Particle [350];
for (int i=0; i<6; i++) {
bob[i]=new OddballParticle();
}
bob[0]=new OddballParticle();
for (int i=6; i<bob.length; i++) {
bob[i]=new Particle();
}
}
void draw()
{
background (255, 255, 255);
for (int i=0; i<bob.length; i++) {
bob[i].show();
bob[i].move();
}
}
void mousePressed()
{
for (int i=0; i<6; i++) {
bob[i]=new OddballParticle ();
}
bob[0]=new OddballParticle();
for (int i=6; i<bob.length; i++) {
bob[i]=new Particle();
}
for (int i=0; i<bob.length; i++) {
bob[i].y=mouseY;
bob[i].x=mouseX;
}
}
class Particle
{
double x, y, mySpeed, myAngle;
color c;
int k;
Particle()
{
k=((int)(Math.random()*6))*2;
x= 250;
y=250;
myAngle=Math.random()*2*Math.PI;
mySpeed=Math.random()*10+1.2;
}
void move() {
x += Math.cos(myAngle) * mySpeed;
y += Math.sin(myAngle) * mySpeed;
}
void show() {
noStroke();
fill(0, 0, 0);
ellipse((int)x, (int)y, 30,30);
fill(255, 255, 255);
text(k, (int)x-3, (int)y+3);
}
}
class OddballParticle extends Particle //inherits from Particle
{
OddballParticle()
{
x=250;
y=250;
k=(((int)(Math.random()*10))*2)+1;
mySpeed=Math.random()*4+2;
}
void show() {
noStroke();
fill(255, 0, 0);
ellipse((int)x, (int)y, 30,30);
fill(255, 255, 255);
text(k, (int)x-3, (int)y+3);
}
void move() {
x += Math.cos(myAngle) * mySpeed;
y += Math.sin(myAngle) * mySpeed;
if (x>500 || x<0 ||y>500 || y<0) {
x = mouseX;
y = mouseY;
}
}
}