-
Notifications
You must be signed in to change notification settings - Fork 53
/
part13d.html
66 lines (47 loc) · 1.54 KB
/
part13d.html
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
<!DOCTYPE html>
<html>
<title>Creative Coding Yea!</title>
<head>
<meta charset="utf-8">
<script language="javascript" src="js/creative_coding.js"></script>
<script language="javascript" src="js/canvas.js"></script>
<script language="javascript" src="js/mic.js"></script>
<link rel="stylesheet" href="css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
</head>
<body>
<script>
var ctx = createCanvas("canvas1");
var num_items = 200;
var radius = 80;
ctx.lineWidth = 2;
var particles = [];
// working out the angles
// this was covered here: https://hackernoon.com/math-sin-and-math-cos-the-creative-coders-best-friend-597d69000644#.hs4cfjno1
for (var i = 0; i < num_items; i++) {
var angle = radians(distributeAngles(i, num_items));
particles[i] = {
x: w/2 + Math.cos(angle) * radius,
y: h/2 + Math.sin(angle) * radius,
angle: angle
}
}
function draw(){
ctx.background(245);
//console.log(Mic.data);
for (var i = 0; i < particles.length; i++) {
var p = particles[i];
//var s = Mic.mapRawSound(i, particles.length, 0, 100);
var s = Mic.mapSound(i, particles.length, 10, 100);
// get a nice greyscale spectrum
//ctx.strokeStyle = rgb(map(i, 0, particles.length, 0, 255));
// get a nice colour spectrum
ctx.strokeStyle = hsl(map(i, 0, particles.length, 0, 360), 90, 50);
x2 = w/2 + Math.cos(p.angle) * (s + radius);
y2 = h/2 + Math.sin(p.angle) * (s + radius);
ctx.line(p.x, p.y, x2, y2);
}
}
</script>
</body>
</html>