-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge-160.1.html
More file actions
35 lines (29 loc) · 979 Bytes
/
challenge-160.1.html
File metadata and controls
35 lines (29 loc) · 979 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
<html>
<head>
<title>Challenge #160.1 - Spring Forces</title>
<script src="https://cdn.jsdelivr.net/npm/p5@1.5.0/lib/p5.min.js"></script>
<script>
let y = 250;
let restLength = 200;
let k = 0.01;
let mass = 1;
let velocity = 0;
function setup() {
createCanvas(800, 600);
}
// // Challenge https://www.youtube.com/watch?v=uWzPe_S-RVE&ab_channel=TheCodingTrain
function draw() {
background(112, 50, 126);
noStroke();
fill(45, 197, 244);
circle(300, y, 64);
let displacement = y - restLength;
let force = -k * displacement;
// F = M(1) * A => A = F / M
velocity += force / mass;
y += velocity;
velocity *= 0.99;
}
</script>
</head>
</html>