-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandom_Verlet.pde
68 lines (54 loc) · 1.31 KB
/
Random_Verlet.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
// Dependances
// toxilibs 0021
// Functionality and control
// Use the left mouse button to add balls
// The right mouse button to remobe balls
// Onscreen controls control system geometry
import java.util.Iterator;
import toxi.physics2d.*;
import toxi.physics2d.behaviors.*;
import toxi.geom.*;
// Reference to physics "world" (2D)
VerletPhysics2D physics;
//Make the system of particle
System system;
void setup() {
size(1360, 768);
smooth();
// Initialize the physics world
physics = new VerletPhysics2D();
physics.setDrag(0.05f);
physics.setWorldBounds(new Rect(0, 0, width, height));
//Initialise the particle system
system = new System();
system.initialize();
// Setup controls
cp5 = new ControlP5(this);
// by calling function addControlFrame() a
// new frame is created and an instance of class
// ControlFrame is instanziated.
cf = addControlFrame("Controls", 300, 200);
}
void draw() {
background(255);
// Update physics
physics.update();
// Draw system of particles
system.update();
}
void mousePressed()
{
if (mouseButton == LEFT){
system.addNode();
} else if (mouseButton == RIGHT) {
system.removeLastNode();
}
}
void mouseDragged()
{
if (mouseButton == LEFT){
system.addNode();
} else if (mouseButton == RIGHT) {
system.removeLastNode();
}
}