Skip to content

Instantly share code, notes, and snippets.

Created December 8, 2012 10:05
Show Gist options
  • Save anonymous/4239676 to your computer and use it in GitHub Desktop.
Save anonymous/4239676 to your computer and use it in GitHub Desktop.
{
"libraries": [
"Processing"
],
"mode": "javascript",
"layout": "fullscreen mode (vertical)"
}
pre {
position: absolute;
color: #FFF;
background: #000;
}
<canvas></canvas>
var numberOfIterations = 10000;
// walker prototype
var particle = {
x: null,
y: null,
init: function(startX, startY) {
this.x = startX;
this.y = startY;
},
display: function(p) {
p.stroke(0);
p.point(this.x, this.y);
},
step: function(p) {
this.x += rand() * 2 - 1;
this.y += rand() * 2 - 1;
}
};
// walker "object"
function Walker(x, y) {
function F() {};
F.prototype = particle;
var f = new F();
f.init(x, y);
return f;
}
// processing sketch
function sketch(p) {
var walker;
p.setup = function() {
p.size($(window).width()*0.99, $(window).height()*0.99);
walker = Walker(p.width/2, p.height/2);
p.background(245);
walker.display(p);
for (var i = 0; i < numberOfIterations; i++) {
walker.step(p);
walker.display(p);
}
};
}
var canvas = $('canvas').get(0);
var processingInstance = new Processing(canvas, sketch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment