-
Notifications
You must be signed in to change notification settings - Fork 0
/
Orbit.pde
41 lines (33 loc) · 918 Bytes
/
Orbit.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
// A circular orbit, with a planet orbiting
class Orbit implements Drawable{
float width, height;
color DEFAULT_COLOR = color(255, 0, 0);
color oColor;
// Orbital parameters
float bodySize = random(5,10);
float rVel = random(5, 10), initPos = random(2);
public Orbit(float w, float h, color c) {
this.width = w;
this.height = w;
oColor = c;
}
public Orbit(float w, float h) {
this.width = w;
this.height = h;
oColor = DEFAULT_COLOR;
}
public void drawme(float t) {
pushMatrix();
float curX = cos(rVel * (t + initPos)) * (this.width / 2);
float curY = sin(rVel * (t + initPos)) * (this.height / 2);
translate(curX, curY);
noStroke();
fill(this.oColor);
sphere(this.bodySize);
translate(-curX, -curY);
stroke(oColor);
noFill();
ellipse(0, 0, this.width, this.height);
popMatrix();
}
}