xonecas.io
208
2p

2d-particle-experiements / commit 0206d9c

changes lol

xonecas2013-02-28 0206d9c2450edf60d184c06712d4fd27641fe298 parent 4e6bc78

4 files changed

css/style.css+7−4
@@ -12,8 +12,11 @@ body {
1212 }
1313
1414 canvas {
15- position: fixed;
16- top: 0;
17- left: 0;
18- z-index: -1;
15+ margin: 0 auto;
16+ display: block;
17+}
18+
19+.example {
20+ color: #6F56FE;
21+ background-color: #2EFED2;
1922 }
index.html+10−13
@@ -15,7 +15,16 @@
1515 <div class="navbar navbar-fixed-top">
1616 <div class="navbar-inner">
1717 <div class="container">
18- <ul class="nav pull-right">
18+ <p class="navbar-text pull-right">
19+ Open your console for more instructions
20+ </p>
21+ <a class="brand" href="//github.com/xonecas/2d-particle-experiements">
22+ Particle Playground
23+ </a>
24+ <a href="/">
25+ <small class="navbar-text">(click to reset)</small>
26+ </a>
27+ <ul class="nav">
1928 <li class="dropdown">
2029 <a href="#" class="dropdown-toggle" data-toggle="dropdown">Functions<b class="caret"></b></a>
2130 <ul class="dropdown-menu">
@@ -28,18 +37,6 @@
2837 </ul>
2938 </li>
3039 </ul>
31-
32- <p class="navbar-text pull-right">
33- Open your console for instructions
34- </p>
35-
36- <a class="brand" href="//github.com/xonecas/2d-particle-experiements">
37- Particle Playground
38- </a>
39-
40- <a href="/">
41- <small class="navbar-text">(click to reset)</small>
42- </a>
4340 </div>
4441 </div>
4542 </div>
js/script.js+92−24
@@ -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));
node.js+2−4
@@ -19,8 +19,6 @@
1919 _http.createServer(function (req, res) {
2020 var url, pathname;
2121
22- console.log('Incoming request.', req.method);
23-
2422 /* I only want GET requests */
2523 if (req.method === 'GET') {
2624 url = _url.parse(req.url, true);
@@ -48,7 +46,7 @@
4846 console.log('Error: 500, Cannot read file', pathname);
4947 res.writeHead(500);
5048 res.end("Could not resolve path request");
51- throw err;
49+ console.log(err, err.stack);
5250 }
5351
5452 res.writeHead(200, {
@@ -57,7 +55,7 @@
5755 "cache-control": "public, max-age=" + CACHE
5856 });
5957 res.end(out);
60- console.log('Success: 200');
58+ console.log('Success: 200', url.pathname);
6159 });
6260 });
6361 } else {