-
Notifications
You must be signed in to change notification settings - Fork 53
/
part13f.html
85 lines (66 loc) · 1.59 KB
/
part13f.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!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 gw = 120;
var gh = 20;
var grid = new Grid(gw, gh);
ctx.lineWidth = 0.2;
var mode = 3;
console.log(grid);
// create particles
var balls = [];
var number_of_balls = gw * gh;
for (var i = 0; i < number_of_balls; i++) {
addBall(grid.x[i], grid.y[i], i);
}
function addBall(x, y, i){
var ball = {
x: x,
y: y,
sz: 10,
me: i
}
balls.push(ball);
}
function draw(){
if (chance(500)) mode = randomInt(0,5);
ctx.background(0, 0.2);
for (var i = 0; i < balls.length; i++) {
var b = balls[i];
moveBall(b);
drawBall(b);
}
}
function moveBall(b){
var m = Math.round(Mic.spectrum.length/2);
if (mode == 0) {
var s = Mic.mapRawSound(b.me, balls.length, 10, 100);
} else if (mode == 1) {
var s = Mic.mapSound(b.me, balls.length, 10, 100);
} else {
var s = map(Mic.spectrum[b.me%(m-1)], 0, 255, 4, grid.spacing_y - 2);
}
if(s > 0) {
b.sz = tween(b.sz, s, 2);
}
b.y +=2;
if( b.y > h) b.y = 0;
}
function drawBall(b){
ctx.fillStyle = rgb(b.sz*5);
ctx.fillRect(b.x, b.y - b.sz, grid.spacing_x - 2, b.sz);
}
</script>
</body>
</html>