-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGravitySim.pde
More file actions
78 lines (67 loc) · 1.44 KB
/
Copy pathGravitySim.pde
File metadata and controls
78 lines (67 loc) · 1.44 KB
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
import java.util.ArrayList;
/* CONFIG */
int N; // Number of particles
float r; // Radius
float mass;
float G;
float theta;
float restitution;
float initBounds;
float initVel;
float dt; // Timestep
/* GRAHPICS */
PShape circle;
// Camera stuff
float camx, camy, tox, toy;
float zoom, tozoom;
float dzoom = 0.5; // Change in zoom amount
float xOffset, yOffset;
// Interface stuff
int everyInsert; // One particle inserted every this many frames
Vector insertStart;
/* VARIABLES */
ArrayList<Particle> particles;
TreeNode root;
void setup() {
// Config
N = 0;
r = 2;
mass = 1;
G = 0.01; // Gravitational constant
theta = 0.7; // Constant used for Barnes-Hut
restitution = 0.2;
initBounds = width / 2;
initVel = 0.1;
dt = 1;
// Graphics
size(800, 800, P2D);
frameRate(240);
noFill();
stroke(255);
strokeWeight(2 * r); //noStroke();
textAlign(LEFT, BOTTOM);
textSize(24);
circle = createShape(ELLIPSE, 0, 0, 2 * r, 2 * r);
// Camera
tox = width / 2;
toy = height / 2;
camx = width / 2;
camy = height / 2;
zoom = 1;
tozoom = 1;
xOffset = 0;
yOffset = 0;
// Interface
everyInsert = 30;
insertStart = null;
// Variables
particles = new ArrayList(3000);
for (int i = 0; i < N; i++) {
particles.add(
new Particle(
new Vector(random(-initBounds, initBounds), random(-initBounds, initBounds)),
new Vector(random(-initVel, initVel), random(-initVel, initVel))
)
);
}
}