@@ -1,4 +1,4 @@
1-/*jslint browser:true, nomen:true, devel:true */
1+/*jslint browser:true, plusplus:true, devel:true */
22 /*global $:false */
33 (function (win, doc) {
44 'use strict';
@@ -9,8 +9,8 @@
99 radians = Math.PI / 180;
1010
1111 body.appendChild(canvas);
12- canvas.width = win.innerWidth - 10;
13- canvas.height = win.innerHeight - 10;
12+ canvas.width = win.innerWidth - 20;
13+ canvas.height = win.innerHeight - 20 - 40;
1414
1515 /* tool */
1616 function rrange(min, max, noFloor) {
@@ -18,6 +18,19 @@
1818 return noFloor ? result : Math.floor(result);
1919 }
2020
21+ function stop() {
22+ if (win.interval) {
23+ clearInterval(win.interval);
24+ }
25+
26+ return "Stopped";
27+ }
28+
29+ function clean() {
30+ canvas.width = canvas.width;
31+ canvas.height = canvas.height;
32+ }
33+
2134 function Particle(x, y, size, color) {
2235 this.x = x;
2336 this.y = y;
@@ -36,7 +49,68 @@
3649 }
3750 };
3851
39- /* first routine */
52+ function tiles() {
53+ var w = canvas.width,
54+ h = canvas.height,
55+ r = 20,
56+ rows = Math.floor(w / r),
57+ cols = Math.floor(h / r),
58+ color = 0,
59+ n,
60+ m;
61+
62+ for (n = 0; n < cols; ++n) {
63+ for (m = 0; m < rows; ++m) {
64+
65+ c.strokeStyle = "hsl(" +
66+ (color === 360 ? color = 0 : color += 0.2) +
67+ ", 100%, 50%)";
68+
69+ c.beginPath();
70+
71+ c.arc(r + n * (r * 2),
72+ r + m * (r * 2),
73+ Math.floor(r / 4) * 3,
74+ 0,
75+ Math.PI * 2, true);
76+ c.stroke();
77+
78+ }
79+ }
80+
81+ }
82+
83+ function grid() {
84+ var w = canvas.width,
85+ h = canvas.height,
86+ mod = 100,
87+ size = Math.floor(w / mod),
88+ i;
89+
90+ canvas.width = size * mod + 2;
91+ canvas.style.width = size * mod + 2;
92+
93+ c.save();
94+ c.moveTo(0, 0);
95+ i = mod;
96+ while (i) {
97+ c.moveTo(size * i, 0);
98+ c.lineTo(size * i, h);
99+ --i;
100+ }
101+
102+ c.moveTo(0, 0);
103+ i = Math.floor(h / size);
104+ while (i) {
105+ c.moveTo(0, size * i);
106+ c.lineTo(w, size * i);
107+ --i;
108+ }
109+
110+ c.stroke();
111+ c.restore();
112+ }
113+
40114 function spiral() {
41115 var particle,
42116 particles = [],
@@ -48,8 +122,7 @@
48122 xyModifier = 1.1,
49123 color = 180;
50124
51- canvas.width = canvas.width;
52- canvas.height = canvas.height;
125+ clean();
53126
54127 c.save();
55128 c.translate(canvas.width / 2, canvas.height / 2);
@@ -84,14 +157,13 @@
84157 size = 4,
85158 startColor = rrange(260, 360);
86159
87- canvas.width = canvas.width;
88- canvas.height = canvas.height;
160+ clean();
89161
90162 c.save();
91163 c.translate(canvas.width / 2, canvas.height / 2);
92164 new Particle(0, 0, size, startColor).draw();
93165
94- (function _init(angle, color, distance, scale) {
166+ (function init(angle, color, distance, scale) {
95167 gens++;
96168 angle = angle || rrange(1, 90);
97169
@@ -112,10 +184,10 @@
112184
113185 color = color >= 360 ? 1 : color + 20 * gens;
114186
115- _init(rrange(1, 270), color, rrange(200, 300),
187+ init(rrange(1, 270), color, rrange(200, 300),
116188 rrange(0.75, 1, true));
117189
118- _init(rrange(1, 270), color, rrange(200, 300),
190+ init(rrange(1, 270), color, rrange(200, 300),
119191 rrange(0.75, 1, true));
120192 }
121193
@@ -140,8 +212,7 @@
140212 startLeap = 0.5,
141213 endLeap = 3;
142214
143- canvas.width = canvas.width;
144- canvas.height = canvas.height;
215+ clean();
145216
146217 if (win.interval) {
147218 clearInterval(win.interval);
@@ -193,8 +264,7 @@
193264 c.fillRect(0, 0, canvas.width, canvas.height);
194265 c.restore();
195266 } else {
196- canvas.width = canvas.width;
197- canvas.height = canvas.height;
267+ clean();
198268 }
199269
200270 c.save();
@@ -233,18 +303,11 @@
233303
234304 }
235305
236- function stop() {
237- if (win.interval) {
238- clearInterval(win.interval);
239- }
240-
241- return "Stopped";
242- }
243-
244306 win.spiral = spiral;
245307 win.fractal = fractal;
246308 win.rain = rain;
247309 win.stop = stop;
310+ win.clean = clean;
248311 win.circle = circle;
249312 win.tracking = trackingCircle;
250313
@@ -265,11 +328,16 @@
265328 'You can see this prompt by calling help();'
266329 ].join('\n'));
267330 };
268- win.help();
269331
270332 $('.fn').click(function (e) {
271333 var fn = $(e.target).data('fn');
272334 win[fn]();
273335 });
274336
337+ $(function () {
338+ win.help();
339+ //grid();
340+ tiles();
341+ });
342+
275343 }(window, document));