-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge-159.1.html
More file actions
38 lines (33 loc) · 1009 Bytes
/
challenge-159.1.html
File metadata and controls
38 lines (33 loc) · 1009 Bytes
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
<html>
<head>
<title>Challenge #159 - Simple Pendulum Simulation</title>
<script src="https://cdn.jsdelivr.net/npm/p5@1.5.0/lib/p5.min.js"></script>
<script>
let angle;
let bob;
let len;
let origin;
let angleVelocity = 0.01;
let angleAcceleration = 0;
function setup() {
createCanvas(800, 600);
origin = createVector(300, 0);
angle = PI / 4;
bob = createVector();
len = 300;
}
function draw() {
background(0);
angleVelocity += angleAcceleration;
angle += angleVelocity;
bob.x = len * sin(angle) + origin.x;
bob.y = len * cos(angle) + origin.y;
stroke(255);
strokeWeight(8);
fill(127);
line(origin.x, origin.y, bob.x, bob.y);
circle(bob.x, bob.y, 64);
}
</script>
</head>
</html>