xonecas.io
208
2p

2d-particle-experiements / commit 2fe131b

examples

xonecas2012-07-16 2fe131b4adb58098fc29b34be159077035759602 parent daf283c

2 files changed

js/script.js+9−5
@@ -72,7 +72,7 @@
7272 particles.push(particle);
7373 particle.draw();
7474
75- c.restore();
75+ c.restore();
7676 }
7777
7878 c.restore();
@@ -81,9 +81,9 @@
8181 /* recursion play */
8282 function fractal () {
8383 var gens = 0,
84- max = 5,
85- size = 10,
86- startColor = rrange(1, 360);
84+ max = 10,
85+ size = 2,
86+ startColor = rrange(260, 360);
8787
8888 canvas.width = canvas.width;
8989 canvas.height = canvas.height;
@@ -114,12 +114,16 @@
114114 new Particle(0, 0, size, color).draw();
115115
116116 color = color >= 360 ? 1 : color + 20 * gens;
117+
117118 _init(rrange(1, 270), color, rrange(200, 300),
118119 rrange(0.75, 1, true));
120+
119121 _init(rrange(1, 270), color, rrange(200, 300),
120122 rrange(0.75, 1, true));
123+
121124 _init(rrange(1, 270), color, rrange(200, 300),
122125 rrange(0.75, 1, true));
126+
123127 _init(rrange(1, 270), color, rrange(200, 300),
124128 rrange(0.75, 1, true));
125129 }
@@ -178,7 +182,7 @@
178182 }
179183
180184 //spiral();
181- //fractal();
185+ fractal();
182186 //rain();
183187
184188 redrawRain.addEventListener('click', function (ev) {
node.js+54−55
@@ -1,62 +1,61 @@
1-/*jshint node:true, curly:true, eqeqeq:true, onevar:true */
2-
3-var _http = require('http'),
4- _path = require('path'),
5- _fs = require('fs'),
6- _url = require('url'),
7- PORT = 8080,
8- HTDOCS = __dirname,
9- CACHE = 0, // 1000 * 60 * 60 * 24 * 30, /* one month */
10- EXTNAMES = {
11- 'html': 'text/html',
12- 'htm' : 'text/html',
13- 'css' : 'text/css',
14- 'js' : 'application/javascript'
15- };
1+/*jslint node:true, nomen:true */
2+
3+var _http = require('http'),
4+ _path = require('path'),
5+ _fs = require('fs'),
6+ _url = require('url'),
7+ PORT = 8080,
8+ HTDOCS = __dirname,
9+ CACHE = 0, // 1000 * 60 * 60 * 24 * 30, /* one month */
10+ EXTNAMES = {
11+ 'html': 'text/html',
12+ 'htm' : 'text/html',
13+ 'css' : 'text/css',
14+ 'js' : 'application/javascript'
15+ };
1616
1717
1818 _http.createServer(function (req, res) {
19- var url, pathname;
20-
21- /* I only want GET requests */
22- if (req.method === 'GET') {
23- url = _url.parse(req.url, true);
24-
25- /* fix / (root) request */
26- if (url.pathname === '/') {
27- url.pathname = '/index.html';
28- }
29-
30- /* make sure we only serve files within HTDOCS */
31- pathname = HTDOCS + url.pathname;
32- _path.exists(pathname, function (exists) {
33- if (!exists) { /* @TODO check for .dotfiles */
34- res.writeHead(404);
35- return res.end("Sorry, no file for you.");
36- }
37-
38- pathname = _path.resolve(HTDOCS + url.pathname);
39- _fs.readFile(pathname, 'utf8', function (err, out) {
40- var extname = _path.extname(url.pathname).substring(1),
41- contentType = EXTNAMES[extname];
42-
43- if (err) {
44- res.writeHead(500);
45- res.end("Could not resolve path request");
46- throw err;
19+ var url, pathname;
20+
21+ /* I only want GET requests */
22+ if (req.method === 'GET') {
23+ url = _url.parse(req.url, true);
24+
25+ /* fix / (root) request */
26+ if (url.pathname === '/') {
27+ url.pathname = '/index.html';
28+ }
29+
30+ /* make sure we only serve files within HTDOCS */
31+ pathname = HTDOCS + url.pathname;
32+ _path.exists(pathname, function (exists) {
33+ if (!exists) { /* @TODO check for .dotfiles */
34+ res.writeHead(404);
35+ return res.end("Sorry, no file for you.");
4736 }
4837
49- res.writeHead(200, {
50- "content-type" : contentType +", charset=UTF-8",
51- "content-length" : out.length,
52- "cache-control" : "public, max-age="+CACHE
38+ pathname = _path.resolve(HTDOCS + url.pathname);
39+ _fs.readFile(pathname, 'utf8', function (err, out) {
40+ var extname = _path.extname(url.pathname).substring(1),
41+ contentType = EXTNAMES[extname];
42+
43+ if (err) {
44+ res.writeHead(500);
45+ res.end("Could not resolve path request");
46+ throw err;
47+ }
48+
49+ res.writeHead(200, {
50+ "content-type": contentType + ", charset=UTF-8",
51+ "content-length": out.length,
52+ "cache-control": "public, max-age=" + CACHE
53+ });
54+ res.end(out);
5355 });
54- res.end(out);
55-
56- });
57- });
58- } else {
59- res.writeHead(405);
60- res.end('Sorry, only taking GET requests right now.');
61- }
56+ });
57+ } else {
58+ res.writeHead(405);
59+ res.end('Sorry, only taking GET requests right now.');
60+ }
6261 }).listen(PORT);