forked from davidedc/livecodelab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·5783 lines (5107 loc) · 193 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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<title>Livecodelab</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src="vendor/three.js/Three.js"></script>
<script src="vendor/three.js/Detector.js"></script>
<script src="vendor/three.js/Stats.js"></script>
<script src="vendor/threex/THREEx.WindowResize.js"></script>
<script type="text/javascript" src="coffee-script.js"></script>
<script src="vendor/three.js/ShaderExtras.js"></script>
<script src="vendor/three.js/postprocessing/EffectComposer.js"></script>
<script src="vendor/three.js/postprocessing/RenderPass.js"></script>
<script src="vendor/three.js/postprocessing/ShaderPass.js"></script>
<!--
surprisingly MaskPass.js is needed even though masks are not
explicitely used
-->
<script src="vendor/three.js/postprocessing/MaskPass.js"></script>
<script src="vendor/three.js/postprocessing/SavePass.js"></script>
<link href="css/main.css" rel="stylesheet"/>
<link rel="stylesheet" href="codemirror.css">
<script src="codemirror.js"></script>
<link rel="stylesheet" href="night.css">
<script src="coffeescript-livecodelab-mode.js"></script>
<script src="jquery.min.js"></script>
<style type="text/css">
.CodeMirror {border: none; }
</style>
<style type="text/css">
a:hover {cursor: default;}
.dd_menu {background:#000000; border-bottom: 1px; border-bottom-color: white; border-bottom-style: dotted; padding:0px; margin:0; list-style-type:none; height:30px;}
.dd_menu li {float:left; height:30px; border-right: solid 1px white; border-right-style: dotted;}
.dd_menu li a {padding:9px 20px; display:block; color:#fff; text-decoration:none; font:12px arial, verdana, sans-serif; font-weight: bold; }
.dd_menu li:hover a {color:black;}
.dd_menu ul { position:absolute; left:-9999px; top:-9999px; list-style-type:none;}
.dd_menu li:hover {position:relative; background:white;}
.dd_menu li:hover ul {left:0px; top:30px; background:#000000; padding:3px; border:0px solid white; width:160px;}
.dd_menu li:hover ul li {height:18px; border:none; }
.dd_menu li:hover ul li a {height:18px; padding:0px; display:block; font-size:11px; width:158px; line-height:18px; text-indent:15px; color:white; background-color:#000000; text-decoration:none; border-top: 1px; border-top-color: #333; border-top-style: dotted;}
.dd_menu li:hover ul li a:hover {height:18px; background:silver; color:#000; border:solid 1px #444; }
#dangerSignText {color:#000000; text-decoration:none;}
#dangerSign:hover {background:#000000;}
#errorMessageText {text-decoration:none;}
#errorMessage:hover {background:#000000;}
.verticalMiddleOfScreen
{
color: white;
background-color: transparent;
text-align: center;
position: absolute;
top: 50%;
left: 0px;
width: 100%;
height: 1px;
overflow: visible;
visibility: visible;
display: block
}
.fakeAnimationContent
{
font-family: Verdana, Geneva, Arial, sans-serif;
background-color: transparent;
margin-left: -1.5em;
position: absolute;
top: -1.1em;
left: 50%;
width: 3em;
height: 2em;
padding-top: 0px;
visibility: visible
}
</style>
<!-- end of second drop-down menu -->
<!-- start simple modal -->
<!-- Page styles -->
<link type='text/css' href='simpleModal/css/demo.css' rel='stylesheet' media='screen' />
<!-- Contact Form CSS files -->
<link type='text/css' href='simpleModal/css/basic.css' rel='stylesheet' media='screen' />
<!-- Scripts -->
<script type='text/javascript' src='simpleModal/js/jquery.js'></script>
<script type='text/javascript' src='simpleModal/js/jquery.simplemodal.js'></script>
<!-- end simple modal -->
</head>
<body>
<div class="verticalMiddleOfScreen" id="toMove" style="font-size:30em;">
<div class="fakeAnimationContent" >
<p id="caption"></p>
</div>
</div>
<div class="verticalMiddleOfScreen" id="justForFakeCursor" style="font-size:30em;">
<div class="fakeAnimationContent" >
<p id="fakeStartingBlinkingCursor">|</p>
</div>
</div>
<!-- preload the images -->
<div style='display:none'>
<img src='simpleModal/img/basic/x.png' alt='' />
</div>
<div id='startingCourtainScreen' style='width:100%; height:100%; background-color:white; position: absolute; z-index:4; top: 0px; left: 0px;'>
<div class="verticalMiddleOfScreen" id="loading" style="font-size:3em; color: red">
loading /</div>
</div>
<!-- modal content -->
<div id="aboutWindow">
<h3>What's this?</h3>
<p>This is a toy live coding environment: programs run immediately as they are typed.<br><br>Pick something from the "Demos" menu or try the tutorials.</p>
<p>Want more info? <a href="http://www.sketchpatch.net/labs/livecodelabIntro.html"> See this.</a></p>
<p>Want to hack this? <a href="https://github.com/davidedc/livecodelab"> Grab the source code!</a></p>
</div>
<div id="noWebGLMessage">
<h3>Drag!</h3>
<p>Your browser doesn't seem to support 3D acceleration.</p>
<p>You'll still have fun, but you really want to try to <a href="http://www.khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" target="_blank">get the 3D party going in your browser</a>.</p>
<p>(psst! - it's worth it!). </p>
</div>
<div id="exampleNeedsWebgl">
<h3>Oh nooo.</h3>
<p>All these examples starting with "webgl" are going to look silly in your browser (which doesn't seem to support 3D acceleration).</p>
<p>Why not try to <a href="http://www.khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" target="_blank">get some awesome 3D action started</a>?</p>
</div>
<div id="noAudioMessage">
<h3>Snap!</h3>
<p>Your browser doesn't seem to support audio.</p>
<p>Be a champion and try <a href="http://browsehappy.com/" target="_blank">a newer browser</a>.</p>
<p>(while you are at it, pick one that supports 3D such as Chrome or Firefox).</p>
</div>
<div id="soundSystemIsMangledMessage">
<h3>Congrats!</h3>
<p>You've unlocked the "I borked the sound system" badge!</p>
<p>This sometime happens when playing lots of music.</p>
<p>Just re-start the browser to get everything back to normal.</p>
<p>(We know it's fun, we do this all the time, it's OK).</p>
</div>
<div id="noCanvasMessage">
<h3>Oh my!</h3>
<p>Your browser is way old.</p>
<p>We understand. We were there 5 years ago. Why not try <a href="http://browsehappy.com/" target="_blank">a shinier browser</a>?</p>
<p>(while you are at it, pick one that supports 3D such as Chrome or Firefox).</p>
</div>
<div id="theMenu" style="position: absolute; z-index:3; top: 0px; left: 0px; width:100%">
<ul class='dd_menu' >
<li><a href="javascript:void(0)" onclick="$('#aboutWindow').modal();$('#simplemodal-container').height(250);" style="text-decoration:none; color:red;">LIVECODELAB</a>
</li>
<li><a href="javascript:void(0)" style="text-decoration:none;" id="demoMenu">Demos</a>
<ul>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('simpleCubeDemo');" id="simpleCubeDemo">Simple cube</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('cubesAndSpikes');" id="cubesAndSpikes">Cubes and spikes</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('littleSpiralOfCubes');" id="littleSpiralOfCubes">Little spiral</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('tentacleDemo');" id="tentacleDemo">Tentacle</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('springysquaresDemo');" id="springysquaresDemo">Springy squares</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('diceDemo');" id="diceDemo">Dice</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('lampDemo');" id="lampDemo">Lamp</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('trillionfeathersDemo');" id="trillionfeathersDemo">A trillion feathers</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('monsterblobDemo');" id="monsterblobDemo">Monster blob</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('industrialMusicDemo');" id="industrialMusicDemo">Sound: Industrial</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('trySoundsDemo');" id="trySoundsDemo">Sound: Try them all</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('webglalmostvoronoiDemo');" id="webglalmostvoronoiDemo">WebGL: Almost Voronoi</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('webglshardsDemo');" id="webglshardsDemo">WebGL: Shards</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('webglredthreadsDemo');" id="webglredthreadsDemo">WebGL: Red threads</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('webgltwocubesDemo');" id="webgltwocubesDemo">WebGL: Two cubes</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('webglturbineDemo');" id="webglturbineDemo">WebGL: Turbine</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('webglzfightartDemo');" id="webglzfightartDemo">WebGL: Z-fight art!</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('webglnuclearOctopusDemo');" id="webglnuclearOctopusDemo">WebGL: Nuclear octopus</a></li>
</ul>
</li>
<li><a href="javascript:void(0)" style="text-decoration:none;" id="tutorialsMenu">Tutorials</a>
<ul>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('introTutorial');" id="introTutorial">intro</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('helloworldTutorial');" id="helloworldTutorial">hello world</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('somenotesTutorial');" id="somenotesTutorial">some notes</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('rotateTutorial');" id="rotateTutorial">rotate</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('frameTutorial');" id="frameTutorial">frame</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('timeTutorial');" id="timeTutorial">time</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('moveTutorial');" id="moveTutorial">move</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('scaleTutorial');" id="scaleTutorial">scale</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('timesTutorial');" id="timesTutorial">times</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('fillTutorial');" id="fillTutorial">fill</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('strokeTutorial');" id="strokeTutorial">stroke</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('colornamesTutorial');" id="colornamesTutorial">color by name</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('lightsTutorial');" id="lightsTutorial">lights</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('backgroundTutorial');" id="backgroundTutorial">background</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('gradientTutorial');" id="gradientTutorial">gradient</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('lineTutorial');" id="lineTutorial">line</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('ballTutorial');" id="ballTutorial">ball</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('pushpopMatrixTutorial');" id="pushpopMatrixTutorial">push and pop</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('animationstyleTutorial');" id="animationstyleTutorial">animation style</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('doonceTutorial');" id="doonceTutorial">do once</a></li>
<li><a href="javascript:void(0)" onclick="loadDemoOrTutorial('autocodeTutorial');" id="autocodeTutorial">autocode</a></li>
</ul>
</li>
<li id="autocodeIndicatorContainer" onClick="toggleAutocode();"><a id="autocodeIndicator" href="javascript:void(0)" style="text-decoration:none;">Autocode: off</a>
</li>
<li id="resetButtonContainer" onClick="triggerReset();"><a id="resetButton" href="javascript:void(0)" style="text-decoration:none;" >Reset</a>
</li>
<li id="dangerSign" style="border-right:none;"><a href="" id="dangerSignText" style="font-size:2em;margin-top:-0.3em;">!</a>
</li>
<li id="errorMessage" style="border-right:none;"><a href="javascript:void(0)" id="errorMessageText" ></a>
</li>
</ul>
</div>
<div name="miao" id="miao" style="position: absolute; top: 30px; left: 0px; width: 100%; font-size: 3em;">
<canvas id="backGroundCanvas" style="position: absolute; z-index:-3; top: 0px; left: 0px;" width="100" height="100"></canvas>
<canvas id="finalRenderWithSceneAndBlendCanvas" style="position: absolute; z-index:-2; top: 0px; left: 0px;" width="100" height="100"></canvas>
<form id="formCode" autocapitalize="off" autocorrect="off" wrap="off" ><textarea id="code" name="code" style="z-index:1;" autocapitalize="off" autocorrect="off" wrap="off" ></textarea></form>
</div>
<!-- three.js container -->
<div id="container" style="position: absolute; z-index:-1; top: 0px; left: 0px;"></div>
<script type="text/javascript">
var stats, scene, renderer;
var camera;
// creating a geometry is expensive
// so we need to create ONE cube of dimensions 1,1,1
// if we need a cube of different size, then we need to
// scale it. Note that the scale for the specific cube shouldn't
// influence the stack, so we need to create a scale node,
// and then go up a node.
var isWebGLUsed = false;
var linesPool = [];
var rectanglesPool = [];
var boxesPool = [];
var cylindersPool = [];
// spheres have different geometries
// depending on the detail level,
// which can be set at whim
var spheresPool = {};
var sphereGeometriesPool = {};
var ambientLightsPool = [];
var pointLightsPool = [];
var usedLines = 0;
var usedRectangles = 0;
var usedBoxes = 0;
var usedCylinders = 0;
var usedAmbientLights = 0;
var usedPointLights = 0;
var usedSpheres = {};
var ballDefaultDetLevel;
var ballDetLevel;
var currentStrokeSize = 1;
var cubeGeometry = new THREE.CubeGeometry(1,1,1);
var planeGeometry = new THREE.PlaneGeometry(1,1);
var lineGeometry = new THREE.Geometry();
var cylinderGeometry = new THREE.CylinderGeometry(0.5, 0.5, 1, 32);
lineGeometry.vertices.push(new THREE.Vertex(new THREE.Vector3(0, -0.5, 0)));
lineGeometry.vertices.push(new THREE.Vertex(new THREE.Vector3(0, 0.5, 0)));
// loads identity matrix
var worldMatrix = new THREE.Matrix4();
var frenchVersion = false;
var forceCanvasRenderer = false;
var backgroundScene;
var backgroundSceneContext;
var sceneRenderingCanvas;
var sceneRenderingCanvasContext;
var previousRenderForBlending;
var previousRenderForBlendingContext;
var finalRenderWithSceneAndBlend;
var finalRenderWithSceneAndBlendContext;
var useRequestAnimationFrame = true;
// if you put to -1 then it means that
// requestAnimationFrame will try to go as fast as it
// can.
var wantedFramesPerSecond = -1;
var backGroundFraction = 15;
var scaledBackgroundWidth;
var scaledBackgroundHeight;
var repaintBackroundEveryFrame = true;
var fullScreenifyBackground = true;
var animationStyleValue = 0;
var previousanimationStyleValue = 0;
var currentGradientStackValue = '';
var previousGradientStackValue = 0;
var blendAmount = 0;
var normal = 0;
var paintOver = 1;
var motionBlur = 2;
var soundLoops = [];
soundLoops.soundIDs = [];
soundLoops.beatStrings = [];
var programHasBasicError = false;
var reasonOfBasicError = "";
var consecutiveFramesWithoutRunTimeError = 0;
var out;
var lastStableProgram;
// the "spinthingy" is because we want
// users who type "box" to see that it's actually
// a 3d environment. So the first few primitives
// spin for a few moments when they are created.
var doTheSpinThingy = true;
var resetTheSpinThingy = false;
var SPINFRAMES = 30;
var userWarnedAboutWebglExamples = false;
function isCanvasSupported(){
var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d'));
}
// Color constants, modified from processing.js
// with added the missing ones from the CSS standard,
// which includes the spelling "grey" on top of "gray"
aliceblue = 0xfff0f8ff ;
antiquewhite = 0xfffaebd7 ;
aqua = 0xff00ffff ;
aquamarine = 0xff7fffd4 ;
azure = 0xfff0ffff ;
beige = 0xfff5f5dc ;
bisque = 0xffffe4c4 ;
black = 0xff000000 ;
blanchedalmond = 0xffffebcd ;
blue = 0xff0000ff ;
blueviolet = 0xff8a2be2 ;
brown = 0xffa52a2a ;
burlywood = 0xffdeb887 ;
cadetblue = 0xff5f9ea0 ;
chartreuse = 0xff7fff00 ;
chocolate = 0xffd2691e ;
coral = 0xffff7f50 ;
cornflowerblue = 0xff6495ed ;
cornsilk = 0xfffff8dc ;
crimson = 0xffdc143c ;
cyan = 0xff00ffff ;
darkblue = 0xff00008b ;
darkcyan = 0xff008b8b ;
darkgoldenrod = 0xffb8860b ;
darkgray = 0xffa9a9a9 ;
darkgrey = 0xffa9a9a9 ;
darkgreen = 0xff006400 ;
darkkhaki = 0xffbdb76b ;
darkmagenta = 0xff8b008b ;
darkolivegreen = 0xff556b2f ;
darkorange = 0xffff8c00 ;
darkorchid = 0xff9932cc ;
darkred = 0xff8b0000 ;
darksalmon = 0xffe9967a ;
darkseagreen = 0xff8fbc8f ;
darkslateblue = 0xff483d8b ;
darkslategray = 0xff2f4f4f ;
darkslategrey = 0xff2f4f4f ;
darkturquoise = 0xff00ced1 ;
darkviolet = 0xff9400d3 ;
deeppink = 0xffff1493 ;
deepskyblue = 0xff00bfff ;
dimgray = 0xff696969 ;
dimgrey = 0xff696969 ;
dodgerblue = 0xff1e90ff ;
firebrick = 0xffb22222 ;
floralwhite = 0xfffffaf0 ;
forestgreen = 0xff228b22 ;
fuchsia = 0xffff00ff ;
gainsboro = 0xffdcdcdc ;
ghostwhite = 0xfff8f8ff ;
gold = 0xffffd700 ;
goldenrod = 0xffdaa520 ;
gray = 0xff808080 ;
grey = 0xff808080 ;
green = 0xff008000 ;
greenyellow = 0xffadff2f ;
honeydew = 0xfff0fff0 ;
hotpink = 0xffff69b4 ;
indianred = 0xffcd5c5c ;
indigo = 0xff4b0082 ;
ivory = 0xfffffff0 ;
khaki = 0xfff0e68c ;
lavender = 0xffe6e6fa ;
lavenderblush = 0xfffff0f5 ;
lawngreen = 0xff7cfc00 ;
lemonchiffon = 0xfffffacd ;
lightblue = 0xffadd8e6 ;
lightcoral = 0xfff08080 ;
lightcyan = 0xffe0ffff ;
lightgoldenrodyellow = 0xfffafad2 ;
lightgrey = 0xffd3d3d3 ;
lightgray = 0xffd3d3d3 ;
lightgreen = 0xff90ee90 ;
lightpink = 0xffffb6c1 ;
lightsalmon = 0xffffa07a ;
lightseagreen = 0xff20b2aa ;
lightskyblue = 0xff87cefa ;
lightslategray = 0xff778899 ;
lightslategrey = 0xff778899 ;
lightsteelblue = 0xffb0c4de ;
lightyellow = 0xffffffe0 ;
lime = 0xff00ff00 ;
limegreen = 0xff32cd32 ;
linen = 0xfffaf0e6 ;
magenta = 0xffff00ff ;
maroon = 0xff800000 ;
mediumaquamarine = 0xff66cdaa ;
mediumblue = 0xff0000cd ;
mediumorchid = 0xffba55d3 ;
mediumpurple = 0xff9370d8 ;
mediumseagreen = 0xff3cb371 ;
mediumslateblue = 0xff7b68ee ;
mediumspringgreen = 0xff00fa9a ;
mediumturquoise = 0xff48d1cc ;
mediumvioletred = 0xffc71585 ;
midnightblue = 0xff191970 ;
mintcream = 0xfff5fffa ;
mistyrose = 0xffffe4e1 ;
moccasin = 0xffffe4b5 ;
navajowhite = 0xffffdead ;
navy = 0xff000080 ;
oldlace = 0xfffdf5e6 ;
olive = 0xff808000 ;
olivedrab = 0xff6b8e23 ;
orange = 0xffffa500 ;
orangered = 0xffff4500 ;
orchid = 0xffda70d6 ;
palegoldenrod = 0xffeee8aa ;
palegreen = 0xff98fb98 ;
paleturquoise = 0xffafeeee ;
palevioletred = 0xffd87093 ;
papayawhip = 0xffffefd5 ;
peachpuff = 0xffffdab9 ;
peru = 0xffcd853f ;
pink = 0xffffc0cb ;
plum = 0xffdda0dd ;
powderblue = 0xffb0e0e6 ;
purple = 0xff800080 ;
red = 0xffff0000 ;
rosybrown = 0xffbc8f8f ;
royalblue = 0xff4169e1 ;
saddlebrown = 0xff8b4513 ;
salmon = 0xfffa8072 ;
sandybrown = 0xfff4a460 ;
seagreen = 0xff2e8b57 ;
seashell = 0xfffff5ee ;
sienna = 0xffa0522d ;
silver = 0xffc0c0c0 ;
skyblue = 0xff87ceeb ;
slateblue = 0xff6a5acd ;
slategray = 0xff708090 ;
slategrey = 0xff708090 ;
snow = 0xfffffafa ;
springgreen = 0xff00ff7f ;
steelblue = 0xff4682b4 ;
tan = 0xffd2b48c ;
teal = 0xff008080 ;
thistle = 0xffd8bfd8 ;
tomato = 0xffff6347 ;
turquoise = 0xff40e0d0 ;
violet = 0xffee82ee ;
wheat = 0xfff5deb3 ;
white = 0xffffffff ;
whitesmoke = 0xfff5f5f5 ;
yellow = 0xffffff00 ;
yellowgreen = 0xff9acd32 ;
// Functions taken from processing.js
/**
* NOTE: in releases we replace symbolic Constants.* names with their values.
* Using Constants.* in code below is fine. See tools/rewrite-pconstants.js.
*/
var Constants = {
// Color modes
RGB: 1,
ARGB: 2,
HSB: 3,
ALPHA: 4,
CMYK: 5,
// Blend modes
REPLACE: 0,
BLEND: 1 << 0,
ADD: 1 << 1,
SUBTRACT: 1 << 2,
LIGHTEST: 1 << 3,
DARKEST: 1 << 4,
DIFFERENCE: 1 << 5,
EXCLUSION: 1 << 6,
MULTIPLY: 1 << 7,
SCREEN: 1 << 8,
OVERLAY: 1 << 9,
HARD_LIGHT: 1 << 10,
SOFT_LIGHT: 1 << 11,
DODGE: 1 << 12,
BURN: 1 << 13,
// Color component bit masks
ALPHA_MASK: 0xff000000,
RED_MASK: 0x00ff0000,
GREEN_MASK: 0x0000ff00,
BLUE_MASK: 0x000000ff,
};
var doFill = true,
fillStyle = [1.0, 1.0, 1.0, 1.0],
isFillDirty = true,
doStroke = true,
strokeStyle = [0.0, 0.0, 0.0, 1.0],
isStrokeDirty = true,
lineWidth = 1,
colorModeA = 255,
colorModeX = 255,
colorModeY = 255,
colorModeZ = 255,
curColorMode = Constants.RGB;
/**
* Determines the largest value in a sequence of numbers.
*
* @param {int|float} value1 int or float
* @param {int|float} value2 int or float
* @param {int|float} value3 int or float
* @param {int|float} array int or float array
*
* @returns {int|float}
*
* @see min
*/
max = function() {
if (arguments.length === 2) {
return arguments[0] < arguments[1] ? arguments[1] : arguments[0];
}
var numbers = arguments.length === 1 ? arguments[0] : arguments; // if single argument, array is used
if (! ("length" in numbers && numbers.length > 0)) {
throw "Non-empty array is expected";
}
var max = numbers[0],
count = numbers.length;
for (var i = 1; i < count; ++i) {
if (max < numbers[i]) {
max = numbers[i];
}
}
return max;
};
/**
* Determines the smallest value in a sequence of numbers.
*
* @param {int|float} value1 int or float
* @param {int|float} value2 int or float
* @param {int|float} value3 int or float
* @param {int|float} array int or float array
*
* @returns {int|float}
*
* @see max
*/
min = function() {
if (arguments.length === 2) {
return arguments[0] < arguments[1] ? arguments[0] : arguments[1];
}
var numbers = arguments.length === 1 ? arguments[0] : arguments; // if single argument, array is used
if (! ("length" in numbers && numbers.length > 0)) {
throw "Non-empty array is expected";
}
var min = numbers[0],
count = numbers.length;
for (var i = 1; i < count; ++i) {
if (min > numbers[i]) {
min = numbers[i];
}
}
return min;
};
function color$4(aValue1, aValue2, aValue3, aValue4) {
var r, g, b, a;
if (curColorMode === Constants.HSB) {
var rgb = color.toRGB(aValue1, aValue2, aValue3);
r = rgb[0];
g = rgb[1];
b = rgb[2];
} else {
r = Math.round(255 * (aValue1 / colorModeX));
g = Math.round(255 * (aValue2 / colorModeY));
b = Math.round(255 * (aValue3 / colorModeZ));
}
a = Math.round(255 * (aValue4 / colorModeA));
// Limit values less than 0 and greater than 255
r = (r < 0) ? 0 : r;
g = (g < 0) ? 0 : g;
b = (b < 0) ? 0 : b;
a = (a < 0) ? 0 : a;
r = (r > 255) ? 255 : r;
g = (g > 255) ? 255 : g;
b = (b > 255) ? 255 : b;
a = (a > 255) ? 255 : a;
// Create color int
return (a << 24) & Constants.ALPHA_MASK | (r << 16) & Constants.RED_MASK | (g << 8) & Constants.GREEN_MASK | b & Constants.BLUE_MASK;
}
function color$2(aValue1, aValue2) {
var a;
if (aValue1 === angleColor) return angleColor;
// Color int and alpha
if (aValue1 & Constants.ALPHA_MASK) {
a = Math.round(255 * (aValue2 / colorModeA));
// Limit values less than 0 and greater than 255
a = (a > 255) ? 255 : a;
a = (a < 0) ? 0 : a;
return aValue1 - (aValue1 & Constants.ALPHA_MASK) + ((a << 24) & Constants.ALPHA_MASK);
}
// Grayscale and alpha
if (curColorMode === Constants.RGB) {
return color$4(aValue1, aValue1, aValue1, aValue2);
}
if (curColorMode === Constants.HSB) {
return color$4(0, 0, (aValue1 / colorModeX) * colorModeZ, aValue2);
}
}
function color$1(aValue1) {
// Grayscale
if (aValue1 <= colorModeX && aValue1 >= 0) {
if (curColorMode === Constants.RGB) {
return color$4(aValue1, aValue1, aValue1, colorModeA);
}
if (curColorMode === Constants.HSB) {
return color$4(0, 0, (aValue1 / colorModeX) * colorModeZ, colorModeA);
}
}
// Color int
if (aValue1) {
if (aValue1 > 2147483647) {
// Java Overflow
aValue1 -= 4294967296;
}
return aValue1;
}
}
/**
* Creates colors for storing in variables of the color datatype. The parameters are
* interpreted as RGB or HSB values depending on the current colorMode(). The default
* mode is RGB values from 0 to 255 and therefore, the function call color(255, 204, 0)
* will return a bright yellow color. More about how colors are stored can be found in
* the reference for the color datatype.
*
* @param {int|float} aValue1 red or hue or grey values relative to the current color range.
* Also can be color value in hexadecimal notation (i.e. #FFCC00 or 0xFFFFCC00)
* @param {int|float} aValue2 green or saturation values relative to the current color range
* @param {int|float} aValue3 blue or brightness values relative to the current color range
* @param {int|float} aValue4 relative to current color range. Represents alpha
*
* @returns {color} the color
*
* @see colorMode
*/
var color = function(aValue1, aValue2, aValue3, aValue4) {
//alert("color");
// 4 arguments: (R, G, B, A) or (H, S, B, A)
if (aValue1 !== undefined && aValue2 !== undefined && aValue3 !== undefined && aValue4 !== undefined) {
return color$4(aValue1, aValue2, aValue3, aValue4);
}
// 3 arguments: (R, G, B) or (H, S, B)
if (aValue1 !== undefined && aValue2 !== undefined && aValue3 !== undefined) {
return color$4(aValue1, aValue2, aValue3, colorModeA);
}
// 2 arguments: (Color, A) or (Grayscale, A)
if (aValue1 !== undefined && aValue2 !== undefined) {
return color$2(aValue1, aValue2);
}
// 1 argument: (Grayscale) or (Color)
if (typeof aValue1 === "number") {
return color$1(aValue1);
}
// Default
return color$4(colorModeX, colorModeY, colorModeZ, colorModeA);
};
// Ease of use function to extract the colour bits into a string
color.toString = function(colorInt) {
return "rgba(" + ((colorInt & Constants.RED_MASK) >>> 16) + "," + ((colorInt & Constants.GREEN_MASK) >>> 8) +
"," + ((colorInt & Constants.BLUE_MASK)) + "," + ((colorInt & Constants.ALPHA_MASK) >>> 24) / 255 + ")";
};
// Easy of use function to pack rgba values into a single bit-shifted color int.
color.toInt = function(r, g, b, a) {
return (a << 24) & Constants.ALPHA_MASK | (r << 16) & Constants.RED_MASK | (g << 8) & Constants.GREEN_MASK | b & Constants.BLUE_MASK;
};
// Creates a simple array in [R, G, B, A] format, [255, 255, 255, 255]
color.toArray = function(colorInt) {
return [(colorInt & Constants.RED_MASK) >>> 16, (colorInt & Constants.GREEN_MASK) >>> 8,
colorInt & Constants.BLUE_MASK, (colorInt & Constants.ALPHA_MASK) >>> 24];
};
// Creates a WebGL color array in [R, G, B, A] format. WebGL wants the color ranges between 0 and 1, [1, 1, 1, 1]
color.toGLArray = function(colorInt) {
return [((colorInt & Constants.RED_MASK) >>> 16) / 255, ((colorInt & Constants.GREEN_MASK) >>> 8) / 255,
(colorInt & Constants.BLUE_MASK) / 255, ((colorInt & Constants.ALPHA_MASK) >>> 24) / 255];
};
// HSB conversion function from Mootools, MIT Licensed
color.toRGB = function(h, s, b) {
// Limit values greater than range
h = (h > colorModeX) ? colorModeX : h;
s = (s > colorModeY) ? colorModeY : s;
b = (b > colorModeZ) ? colorModeZ : b;
h = (h / colorModeX) * 360;
s = (s / colorModeY) * 100;
b = (b / colorModeZ) * 100;
var br = Math.round(b / 100 * 255);
if (s === 0) { // Grayscale
return [br, br, br];
}
var hue = h % 360;
var f = hue % 60;
var p = Math.round((b * (100 - s)) / 10000 * 255);
var q = Math.round((b * (6000 - s * f)) / 600000 * 255);
var t = Math.round((b * (6000 - s * (60 - f))) / 600000 * 255);
switch (Math.floor(hue / 60)) {
case 0:
return [br, t, p];
case 1:
return [q, br, p];
case 2:
return [p, br, t];
case 3:
return [p, q, br];
case 4:
return [t, p, br];
case 5:
return [br, p, q];
}
};
function colorToHSB(colorInt) {
var red, green, blue;
red = ((colorInt & Constants.RED_MASK) >>> 16) / 255;
green = ((colorInt & Constants.GREEN_MASK) >>> 8) / 255;
blue = (colorInt & Constants.BLUE_MASK) / 255;
var max = max(max(red,green), blue),
min = min(min(red,green), blue),
hue, saturation;
if (min === max) {
return [0, 0, max*colorModeZ];
}
saturation = (max - min) / max;
if (red === max) {
hue = (green - blue) / (max - min);
} else if (green === max) {
hue = 2 + ((blue - red) / (max - min));
} else {
hue = 4 + ((red - green) / (max - min));
}
hue /= 6;
if (hue < 0) {
hue += 1;
} else if (hue > 1) {
hue -= 1;
}
return [hue*colorModeX, saturation*colorModeY, max*colorModeZ];
}
/**
* Extracts the brightness value from a color.
*
* @param {color} colInt any value of the color datatype
*
* @returns {float} The brightness color value.
*
* @see red
* @see green
* @see blue
* @see hue
* @see saturation
*/
brightness = function(colInt){
return colorToHSB(colInt)[2];
};
/**
* Extracts the saturation value from a color.
*
* @param {color} colInt any value of the color datatype
*
* @returns {float} The saturation color value.
*
* @see red
* @see green
* @see blue
* @see hue
* @see brightness
*/
saturation = function(colInt){
return colorToHSB(colInt)[1];
};
/**
* Extracts the hue value from a color.
*
* @param {color} colInt any value of the color datatype
*
* @returns {float} The hue color value.
*
* @see red
* @see green
* @see blue
* @see saturation
* @see brightness
*/
hue = function(colInt){
return colorToHSB(colInt)[0];
};
/**
* Extracts the red value from a color, scaled to match current colorMode().
* This value is always returned as a float so be careful not to assign it to an int value.
*
* @param {color} aColor any value of the color datatype
*
* @returns {float} The red color value.
*
* @see green
* @see blue
* @see alpha
* @see >> right shift
* @see hue
* @see saturation
* @see brightness
*/
redF = function(aColor) {
return ((aColor & Constants.RED_MASK) >>> 16) / 255 * colorModeX;
};
/**
* Extracts the green value from a color, scaled to match current colorMode().
* This value is always returned as a float so be careful not to assign it to an int value.
*
* @param {color} aColor any value of the color datatype
*
* @returns {float} The green color value.
*
* @see red
* @see blue
* @see alpha
* @see >> right shift
* @see hue
* @see saturation
* @see brightness
*/
greenF = function(aColor) {
return ((aColor & Constants.GREEN_MASK) >>> 8) / 255 * colorModeY;
};
/**
* Extracts the blue value from a color, scaled to match current colorMode().
* This value is always returned as a float so be careful not to assign it to an int value.
*
* @param {color} aColor any value of the color datatype
*
* @returns {float} The blue color value.
*
* @see red
* @see green
* @see alpha
* @see >> right shift
* @see hue
* @see saturation
* @see brightness
*/
blueF = function(aColor) {
return (aColor & Constants.BLUE_MASK) / 255 * colorModeZ;
};
/**
* Extracts the alpha value from a color, scaled to match current colorMode().
* This value is always returned as a float so be careful not to assign it to an int value.
*
* @param {color} aColor any value of the color datatype
*
* @returns {float} The alpha color value.
*
* @see red
* @see green
* @see blue
* @see >> right shift
* @see hue
* @see saturation
* @see brightness
*/
alpha = function(aColor) {
return ((aColor & Constants.ALPHA_MASK) >>> 24) / 255 * colorModeA;
};
alphaZeroToOne = function(aColor) {
return ((aColor & Constants.ALPHA_MASK) >>> 24) / 255;
};
/**
* Calculates a color or colors between two colors at a specific increment.
* The amt parameter is the amount to interpolate between the two values where 0.0
* equal to the first point, 0.1 is very near the first point, 0.5 is half-way in between, etc.
*
* @param {color} c1 interpolate from this color
* @param {color} c2 interpolate to this color
* @param {float} amt between 0.0 and 1.0
*
* @returns {float} The blended color.
*
* @see blendColor
* @see color
*/
lerpColor = function(c1, c2, amt) {
var r, g, b, a, r1, g1, b1, a1, r2, g2, b2, a2;
var hsb1, hsb2, rgb, h, s;
var colorBits1 = color(c1);
var colorBits2 = color(c2);
if (curColorMode === Constants.HSB) {
// Special processing for HSB mode.
// Get HSB and Alpha values for Color 1 and 2
hsb1 = colorToHSB(colorBits1);
a1 = ((colorBits1 & Constants.ALPHA_MASK) >>> 24) / colorModeA;
hsb2 = colorToHSB(colorBits2);
a2 = ((colorBits2 & Constants.ALPHA_MASK) >>> 24) / colorModeA;
// Return lerp value for each channel, for HSB components
h = lerp(hsb1[0], hsb2[0], amt);
s = lerp(hsb1[1], hsb2[1], amt);
b = lerp(hsb1[2], hsb2[2], amt);
rgb = color.toRGB(h, s, b);
// ... and for Alpha-range
a = lerp(a1, a2, amt) * colorModeA;