-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplePendulum.pde
More file actions
executable file
·92 lines (72 loc) · 1.78 KB
/
SimplePendulum.pde
File metadata and controls
executable file
·92 lines (72 loc) · 1.78 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
final float scale = 120;
final float g = 9.80665;
PendulumSimulation simulation;
PendulumView pendulum;
AngleGraph angleGraph;
EnergyGraph energyGraph;
AbstractAngleGraph abstractAngleGraph;
AbstractEnergyGraph abstractEnergyGraph;
Timer timer;
boolean angleGraphHover;
float angleGraphTheta;
boolean timerRunning;
boolean levelUp;
PFont font;
PImage arrow;
void setup() {
size(1024, 640);
simulation = new PendulumSimulation(PI/8);
pendulum = new PendulumView(180, 235);
angleGraph = new AngleGraph(340, 225, 340, 150);
energyGraph = new EnergyGraph(740, 225, 140, 150);
abstractAngleGraph = new AbstractAngleGraph(340, 70, 340, 150);
abstractEnergyGraph = new AbstractEnergyGraph(740, 70, 200, 150);
timer = new Timer();
angleGraphHover = false;
timerRunning = false;
font = createFont("Sans Serif", 20);
textFont(font);
arrow = loadImage("arrow.png");
smooth();
}
void draw() {
background(255);
pendulum.draw();
angleGraph.draw();
energyGraph.draw();
timer.update();
if(levelUp) {
image(arrow, 460, 250);
abstractAngleGraph.draw();
abstractEnergyGraph.draw();
}
textSize(14);
fill(#2AA198);
text("SPACE to play.", 30, 20);
text("UP/DOWN for more.", 30, 40);
}
void keyPressed() {
if(key == ' ')
timerRunning = !timerRunning;
if(keyCode == UP && !levelUp) {
levelUp = true;
pendulum.Y = pendulum.Y + 150;
angleGraph.Y = angleGraph.Y + 150;
energyGraph.Y = energyGraph.Y + 150;
}
if(keyCode == DOWN && levelUp) {
levelUp = false;
pendulum.Y = pendulum.Y - 150;
angleGraph.Y = angleGraph.Y - 150;
energyGraph.Y = energyGraph.Y - 150;
}
}
void mousePressed() {
pendulum.clicked();
}
void mouseDragged() {
pendulum.dragged();
}
void mouseReleased() {
pendulum.released();
}