forked from aaronsnoswell/recanvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·520 lines (362 loc) · 15.1 KB
/
index.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
<!doctype html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<!-- Use the .htaccess and remove these lines to avoid edge case issues.
More info: h5bp.com/b/378 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile viewport optimized: h5bp.com/viewport -->
<meta name="viewport" content="width=device-width,initial-scale=1">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory: mathiasbynens.be/notes/touch-icons -->
<link rel="stylesheet" href="css/style.css">
<!-- More ideas for your <head> here: h5bp.com/d/head-Tips -->
<!-- All JavaScript at the bottom, except this Modernizr build incl. Respond.js
Respond is a polyfill for min/max-width media queries. Modernizr enables HTML5 elements & feature detects;
for optimal performance, create your own custom Modernizr build: www.modernizr.com/download/ -->
<script src="js/libs/modernizr-2.0.6.min.js"></script>
<!-- JQuery UI styles -->
<link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.18.custom.css">
<!-- CodeMirror styles -->
<link rel="stylesheet" href="js/libs/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="js/libs/codemirror/lib/util/simple-hint.css">
<link rel="stylesheet" href="js/libs/codemirror/doc/docs.css">
<!-- Get CodeMirror -->
<script src="js/libs/codemirror/lib/codemirror.js"></script>
<script src="js/libs/codemirror/lib/util/simple-hint.js"></script>
<script src="js/libs/codemirror/lib/util/javascript-hint.js"></script>
<script src="js/libs/codemirror/mode/javascript/javascript.js"></script>
</head>
<body class="recanvas">
<!-- Fork me on github link -->
<a href="https://github.com/aaronsnoswell/recanvas"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub"></a>
<!-- Credit link -->
<a id="made_with_love" href="http://elucidatedbinary.com/about/" taget="_blank" >Made with <3 by Aaron</a>
<div id="main" >
<header>
<span id="export" class="header">
<input type="button" value="Export .png" id="export" />
</span>
<span id="preset" class="header">
<select id="preset_opt">
<option value=""></option>
<optgroup label="Basic">
<option value="dotti">Dotti</option>
<option value="checkerboard">Checkerboard</option>
<option value="odd">Odd Texture</option>
</optgroup>
<optgroup label="Procedural Textures">
<option value="perlin_noise">Perlin Noise</option>
<option value="waterfall">Waterfall</option>
<option value="spherical_nebula">Spherical Nebula</option>
<option value="green_fibre">Green Fibre Bundle</option>
<option value="orange_blue_marble">Orange-Blue Marble</option>
<option value="blood_maze">Blood Maze</option>
<option value="yellow_lightning">Yellow Lightning</option>
<option value="rainbow_wipe">Rainbow Wipe</option>
<option value="noisy_rainbow">Noisy Rainbow</option>
<option value="burning_cross">Burning Cross</option>
</optgroup>
<optgroup label="Interactive Examples">
<option value="colored_rectangles">Colored Rectangles</option>
</optgroup>
</select>
</span>
</header>
<div id="notepad">
<div class="page">
<canvas id="canvas">
<p>REcanvas requires Canvas support - go figure!</p>
</canvas>
</div>
<div class="page">
<div id="code-wrapper">
<textarea id="code">
// l33t codes go here
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
</textarea>
</div>
</div>
<div class="pagecurl"></div>
</div>
<div class="assets">
<img id="img-sprite" src="img/sprite.png">
<!-- Procedural Textures from Kas Thomas' blog http://asserttrue.blogspot.com -->
<script type="text/x-recanvas-script" id="preset_perlin_noise"><![CDATA[// Perlin Noise via Ken Perlin's original Java implementation
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var scale = 10,
val = Utils.perlin(x/imdata.width*scale, y/imdata.height*scale, 0.8) * 255,
pix = new Utils.Pixel(val, val, val, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_waterfall"><![CDATA[// Odd 'waterfall' pattern
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var nx = x / 30,
ny = y / (3 * (y+nx)/imdata.width),
n = Utils.perlin(nx, ny, .18);
var b = Math.round(255*n);
var g = b - 255;
var r = 0;
var pix = new Utils.Pixel(r, g, b, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_spherical_nebula"><![CDATA[// Glowing nebula pattern
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var centerx = imdata.width/2;
centery = imdata.height/2,
dx = x - centerx,
dy = y - centery,
dist = (dx*dx + dy*dy)/6000,
n = Utils.perlin(x/5, y/5, .18);
var r = 255 - dist*Math.round(255*n);
var g = r - 255;
var b = 0;
var pix = new Utils.Pixel(r, g, b, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_green_fibre"><![CDATA[// Green Fibres
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var nx = x / imdata.width,
ny = y / imdata.height,
sizex = 3,
sizey = 66,
n = Utils.perlin(sizex*nx, sizey*ny, .1);
nx = (1+Math.sin(3.14*nx))/2;
ny = (1+Math.sin(n*8*ny))/2;
var b = n*ny*nx*255;
var r = ny*b;
var g = ny*255;
var pix = new Utils.Pixel(r, g, b, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_orange_blue_marble"><![CDATA[// Orange-Blue marble
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var centerx = imdata.width/2,
centery = imdata.height/2,
dx = x - centerx,
dy = y - centery,
dist = 1.2*Math.sqrt(dx*dx + dy*dy),
n = Utils.perlin(x/30,y/110,.28),
dterm = (dist/88)*Math.round(255*n);
var r = dist < 150 ? dterm : 255;
var b = dist < 150 ? 255-r : 255;
var g = dist < 151 ? dterm/1.5 : 255;
var pix = new Utils.Pixel(r, g, b, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_blood_maze"><![CDATA[// A blood-stained maze
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var n = Utils.perlin(x/45, y/120, .74);
n = Math.cos( n * 85);
var r = Math.round(n * 255);
var b = 255 - r;
var g = r - 255 ;
var pix = new Utils.Pixel(r, g, b, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_yellow_lightning"><![CDATA[// Whispy Yellow Lightning
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var n = Utils.perlin(x/45, y/120, .74);
n = Math.cos( n * 85);
var nx = x / imdata.width,
ny = y / imdata.height,
sizex = 1.5,
sizey = 10,
n = Utils.perlin(sizex*nx, sizey*ny, 0.4);
nx = (1+Math.cos(n+2*Math.PI*nx-.5));
nx = Math.sqrt(nx);
ny *= ny;
var r= 255-nx*255;
var g=255-n*nx*255;
var b=ny*255;
var pix = new Utils.Pixel(r, g, b, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_rainbow_wipe"><![CDATA[// Rainbow Wipe
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
// This uses no Perlin noise.
var nx = x / imdata.width,
ny = y / imdata.height;
var b = 255 - ny*255*(1 + Math.sin(6.3*nx))/2;
var g = 255 - ny*255*(1 + Math.cos(6.3*nx))/2;
var r = 255 - ny*255*(1 - Math.sin(6.3*nx))/2;
var pix = new Utils.Pixel(r, g, b, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_noisy_rainbow"><![CDATA[// Noisy Rainbow
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var nx = x / imdata.width,
ny = y / imdata.height,
size = 20,
n = Utils.perlin(size*nx, size*ny, .9);
var b = 255 - 255*(1 + Math.sin(n+6.3*nx))/2;
var g = 255 - 255*(1 + Math.cos(n+6.3*nx))/2;
var r = 255 - 255*(1 - Math.sin(n+6.3*nx))/2;
var pix = new Utils.Pixel(r, g, b, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_burning_cross"><![CDATA[// Burning Cross
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var nx = x / imdata.width,
ny = y / imdata.height,
size = 19,
n = Utils.perlin(size*nx, size*ny, .9);
nx = (1+Math.cos(n+2*Math.PI*nx-.5));
ny = (1+Math.cos(2*Math.PI*ny));
var r = 255-ny*nx*n*255;
var g = r;
var b=255-r;
var pix = new Utils.Pixel(r, g, b, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_dotti"><![CDATA[// Dotti
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var scale = 10,
nx = x/scale,
ny = y/scale
val = Math.round(Math.sin(nx) + Math.sin(ny))*255;
var pix = new Utils.Pixel(val, val, val, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_checkerboard"><![CDATA[// Checkerboard
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var scale = 40,
nx = Math.floor(x/scale),
ny = Math.floor(y/scale);
var val = 0;
if((nx%2 == 0 && ny%2 != 0) || (nx%2 != 0 && ny%2 == 0)) val = 255;
var pix = new Utils.Pixel(val, val, val, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_odd"><![CDATA[// Odd texture who's name I can't remember
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var imdata = ctx.createImageData(400, 400);
Utils.loopxy(imdata.width, imdata.height, function(x, y) {
var scale = 1.6,
nx = Math.round(x/scale),
ny = Math.round(y/scale);
var val = Math.min((nx * ny)%255, 255);
var pix = new Utils.Pixel(val, val, val, 255);
Utils.putpix(imdata, x, y, pix);
});
ctx.putImageData(imdata, 0, 0);
]]></script>
<script type="text/x-recanvas-script" id="preset_colored_rectangles"><![CDATA[// Colored rectangles
// Try clicking on the canvas!
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
function redraw() {
Utils.clear(canvas, ctx);
for(var i=0; i<500; i++) {
var color = (Math.floor(Math.random()*16*16*16)).toString(16)
while (color.length < 3) color = '0' + color;
ctx.fillStyle = "#" + color;
ctx.fillRect(
Math.random() * canvas.width,
Math.random() * canvas.height,
20,
20
);
}
}
canvas.onmousedown = redraw;
redraw();
]]></script>
</div>
</div>
<footer>
</footer>
<!-- JavaScript at the bottom for fast page loading -->
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
<!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>-->
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script>
<script src="js/libs/jquery-ui-1.8.18.custom.min.js"></script>
<!-- scripts concatenated and minified via build script -->
<script defer src="js/plugins.js"></script>
<script defer src="js/script.js"></script>
<!-- end scripts -->
<!-- Asynchronous Google Analytics snippet. Change UA-XXXXX-X to be your site's ID.
mathiasbynens.be/notes/async-analytics-snippet -->
<script>
var _gaq=[['_setAccount','UA-26952610-2'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
<!-- Prompt IE 6 users to install Chrome Frame. Remove this if you want to support IE 6.
chromium.org/developers/how-tos/chrome-frame-getting-started -->
<!--[if lt IE 7 ]>
<script defer src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
<script defer>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
<![endif]-->
</body>
</html>