-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.html
150 lines (104 loc) · 2.55 KB
/
random.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Oscillators - jsFiddle demo by AbdiasSoftware</title>
<script type='text/javascript' src='/js/lib/dummy.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
body {
background:#335;
}
</style>
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
/**
* Wave oscillators by Ken Fyrstenberg Nilsen
* http://abdiassoftware.com/
*
* CC-Attribute 3.0 License
*/
var ctx = canvas.getContext('2d'),
w, h;
canvas.width = w = window.innerWidth * 0.98;
canvas.height = h = window.innerHeight * 0.9;
var osc1 = new osc(),
osc2 = new osc(),
osc3 = new osc(),
horizon = h * 0.5;
count = 40,
step = Math.ceil(w / count),
//points = new Array(count);
buffer = new ArrayBuffer(count * 4),
points = new Float32Array(buffer);
osc1.max = h * 0.7;
osc2.max = 35;
osc2.speed = 0.03;
osc2.max = 20;
osc2.speed = 0.015;
function fill() {
for(var i = 0; i < count; i++) {
points[i] = mixer(osc1, osc2, osc3);
}
}
fill();
ctx.lineWidth = 20;
ctx.strokeStyle = '#fff';
ctx.fillStyle = 'rgba(50, 50, 80, 0.1)';
function loop() {
var i;
/// move points to the left
for(i = 0; i < count - 1; i++) {
points[i] = points[i + 1];
}
/// get a new point
points[count - 1] = mixer(osc1, osc2, osc3);
//ctx.clearRect(0, 0, w, h);
ctx.fillRect(0, 0, w, h);
/// render wave
ctx.beginPath();
ctx.moveTo(0, points[0]);
for(i = 1; i < count; i++) {
ctx.lineTo(i * step, points[i]);
}
ctx.stroke();
requestAnimationFrame(loop);
}
loop();
/// oscillator object
function osc() {
this.variation = 0.4;
this.max = 150;
this.speed = 0.02;
var me = this,
a = 0,
max = getMax();
this.getAmp = function() {
a += this.speed;
if (a >= 2.0) {
a = 0;
max = getMax();
}
return max * Math.sin(a * Math.PI);
}
function getMax() {
return Math.random() * me.max * me.variation +
me.max * (1 - me.variation);
}
return this;
}
function mixer() {
var d = arguments.length,
i = d,
sum = 0;
if (d < 1) return 0;
while(i--) sum += arguments[i].getAmp();
return sum / d + horizon;
}
}//]]>
</script>
</head>
<body>
<canvas id="canvas"></canvas>
</body>
</html>