-
Notifications
You must be signed in to change notification settings - Fork 1
/
star.pde
97 lines (80 loc) · 2.67 KB
/
star.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
public class Star {
float points = 5;
float circAngle = 360/points * 2;
float radius;
float collideNet;
int x = 0;
int y = 0;
float vx;
float vy;
float sx = 0.1;
float sy = -1;
PVector acceleration;
PVector velocity;
PVector startPos;
PVector newPos = new PVector(0, 0);
int age = 0;
float rotateRate = 0.01;
float rotateState = 0;
float G = 9.81;
float dt = 1.0/25;
Star(PVector inCenter, float inRadius) {
//save star parameters to be accessed locally
this.startPos = inCenter;
this.radius = inRadius;
//(angle, velocity)
starAngle(random(55,65), random(10, 15));
}
void display() {
stroke(255);
rotateState = rotateRate;
//draw stars
for (float i = 0; i < 720; i = circAngle) {
pushMatrix();
stroke(255);
translate(startPos.x, startPos.y);
rotate(rotateState);
PVector point1 = new PVector(cos(radians(i))*(radius), sin(radians(i))*(radius));
PVector point2 = new PVector(cos(radians(i circAngle))*(radius), sin(radians(i circAngle))*(radius));
line(point1.x, point1.y, point2.x, point2.y);
popMatrix();
// shooting star trails
pushMatrix();
//randomize stroke brightness so it looks shimmery;
stroke(random(100));
// translates the center of trails first before drawing all of them
translate(startPos.x, startPos.y);
for (float j = 0; j < 3; j = 1) {
float angle = 180 - (15 * j); // distance of lines = multiples of 15 degrees, use 180 - to get to opposite side
float start = radius * 2; // start the line from double the r distance from center of star
PVector pointA = new PVector(cos(radians(angle)) * start, sin(radians(angle)) * start);
PVector pointB = new PVector(cos(radians(angle)) * (radius) * (3 (0.8 * j)),
sin(radians(angle))*(radius) * (3 (0.8 * j)));
//PVector cPointB = PVector.add(startPos, pointB);
//line(cPointA.x, cPointA.y, cPointB.x, cPointB.y);
line(pointA.x, pointA.y, pointB.x, pointB.y);
}
popMatrix();
}
age = 1;
}
void update() {
// add movement to star location
//velocity = new PVector(.1, .3);//new PVector(random(3), int(random(-4)));
//acceleration = new PVector(0.0001, 0.001);
vx = vx;
vy = vy - G * dt; //gravity pulls down
// update star position
sx = sx vx * dt;
sy = sy vy * dt;
// println(sx " and " sy);
velocity = new PVector(sx, -sy);
this.newPos = startPos.add(velocity);
}
// angle that star curve starts with
void starAngle(float a, float v) {
vx = cos(a * PI/180) * v;
vy = sin(a * PI/180) * v;
// println(a * PI/180 "angle " cos(a * PI/180));
}
}