forked from abbernie/gendy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgendy_constuctor_demo.html
173 lines (143 loc) · 5.41 KB
/
gendy_constuctor_demo.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html>
<head>
<script src="js/nexusUI.js"></script>
<script src="gendy.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>
<p>GENDY.JS</p>
<p id="subtitle">A module for dynamic stochastic synthesis</p>
</h1>
<canvas id="canvas"></canvas>
<table id="control">
<tr>
<td>
<canvas nx="toggle" class="widg"></canvas>
</td>
<td>
<canvas nx="number" class="widg"></canvas>
</td>
<td>
<canvas nx="slider" class="widg"></canvas>
</td>
<td>
<canvas nx="slider" class="widg"></canvas>
</td>
<td>
<canvas nx="slider" class="widg"></canvas>
</td>
<td>
<canvas nx="slider" class="widg"></canvas>
</td>
</tr>
<tr id="labels">
<td>
<label for="io" id="iol">i/o</label>
</td>
<td>
<label for="break" id="breakl">points</label>
</td>
<td>
<label for="x" id="xl">x-step</label>
</td>
<td>
<label for="ystep" id="ystepl">y-step</label>
</td>
<td>
<label for="ybound" id="yboundl">y-bounds</label>
</td>
<td>
<label for="freq" id="freql">frequency</label>
</td>
</tr>
</table>
<div id="clear"></div>
<div id="info">
<div id="text">
<h3>More?</h3>
<p>Explore the Gendy.js <a href="http://www.github.com/abbernie/gendy">API</a></p>
<p>Contribute this project on <a href="http://www.github.com/abbernie/gendy">Github</a></p>
<p> Peruse the work of the project's authors, <a href="http://www.andrewbernste.in">Andrew Bernstein</a> and <a href="http://www.whitechord.org"> Ben Taylor</a></p>
</div>
</div>
</body>
<script>
nx.onload = function(){
nx.sendsTo("js");
nx.showLabels = "true";
nx.setLabels("true");
nx.colorize("#007700");
toggle1.on('*',function(){
if(toggle1.val.value == 1){
gendy.connect(actx.destination);
canvasDraw();
gendy.start();
} else if(toggle1.val.value == 0){
gendy.disconnect(actx.destination);
}
});
number1.decimalPlaces = 0;
number1.set({value:15});
gendy.breakpoints = 15;
number1.on("*", function(){
gendy.breakpoints = number1.val.value;
gendy.init();
context.fillStyle = "#ffffff";
context.fillRect(0,0,canvas.width,canvas.height);
console.log("breakpoints", gendy.breakpoints)
})
slider1.label = "x step";
slider1.set({value:.56});
gendy.xStep = 28;
slider1.on("*", function(){
gendy.xStep = slider1.val.value * 50;
console.log("xstep", gendy.xStep);
});
slider3.set({value:0.256});
gendy.yMin = -0.256;
gendy.yMax = 0.256;
slider3.on("*", function(){
gendy.yMax = slider3.val.value;
gendy.yMin = slider3.val.value*(-1);
console.log("ymax", gendy.yMax);
});
slider2.set({value:0.508});
gendy.yStep = 0.508;
slider2.on("*", function(){
gendy.yStep = slider2.val.value;
console.log("ystep", gendy.yStep);
});
slider4.set({value:.1});
gendy.freq = 0.1;
slider4.on("*", function(){
gendy.freq = slider4.val.value*10;
console.log("freq", gendy.freq);
});
}
var canvas = document.getElementById("canvas");
var context = canvas.getContext('2d');
canvas.width = 600;
canvas.height = 300
var actx = new (AudioContext || wedkitAudioContext)();
var gendy = new Gendy(actx);
gendy.breakpoints = 15;
function canvasDraw(){
window.requestAnimationFrame(canvasDraw);
context.globalAlpha = 0.2
context.fillStyle = "#ffffff"
context.fillRect(0,0,canvas.width,canvas.height)
context.globalAlpha = 1
context.strokeStyle = "#black";
context.lineWidth = 6;
context.beginPath();
context.moveTo(0,canvas.height/2)
for (var i=0;i<gendy.breakpoint.length;i++) {
context.lineTo((gendy.breakpoint[i].x/gendy.scriptNode.bufferSize)*canvas.width/2 ,gendy.breakpoint[i].y*(canvas.height/2)+canvas.height/2)
}
context.stroke()
context.closePath()
}
</script>
</html>