-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathang-rot6.html
More file actions
39 lines (36 loc) · 1.2 KB
/
ang-rot6.html
File metadata and controls
39 lines (36 loc) · 1.2 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
<html>
<head>
<title>Angles and Rotation 6 - Graphing Sine Wave</title>
<script src="https://cdn.jsdelivr.net/npm/p5@1.5.0/lib/p5.min.js"></script>
<script>
var angle = 0;
var angleVelocity = 0;
var radius = 16;
var angles = [];
var angleVelocities = [];
function setup() {
createCanvas(800, 600);
let total = floor(width / (radius * 2));
for (let i = 0; i < total; i++) {
angles[i] = 0;
angleVelocities[i] = 0.01 + i / 100;
}
}
function draw() {
background(0);
translate(width / 2, height /2);
fill(252, 238, 33);
stroke(252, 238, 33);
// let r = map(sin(angle), -1, 1, 0, 200);
for (let i = 0; i < angles.length; i++) {
let y = map(sin(angles[i]), -1, 1, -200, 200);
stroke(255);
let x = map(i, 0, angles.length, - width / 2, width / 2);
line(x, 0, x, y);
angles[i] += angleVelocities[i];
circle(x, y, 32);
}
}
</script>
</head>
</html>