Last active
December 29, 2015 09:29
-
-
Save brysonian/7650432 to your computer and use it in GitHub Desktop.
Test of processing.js gist hosting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>Programming Media I</title> | |
<meta name="description" content=""> | |
</head> | |
<body> | |
<div> | |
<canvas id="sketch" data-processing-sources="walker_array.pde" | |
width="600" height="600"> | |
<p>Your browser does not support the canvas tag.</p> | |
<!-- Note: you can put any alternative content here. --> | |
</canvas> | |
</div> | |
<script type="text/javascript" src="http://classes.dma.ucla.edu/Fall13/252A/js/vendor/processing.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Walker[] walkers = new Walker[1000]; | |
void setup() { | |
size(1000, 500); | |
background(0); | |
smooth(); | |
noStroke(); | |
for (int i=0; i<walkers.length; i++) { | |
float x = random(0, width); | |
float y = random(0, height); | |
walkers[i] = new Walker(x, y); | |
} | |
} | |
void draw() { | |
for (int i=0; i<walkers.length; i++) { | |
walkers[i].display(); | |
walkers[i].move(); | |
} | |
} | |
// ------------------------------------ | |
class Walker | |
{ | |
float x; | |
float y; | |
color clr; | |
// constructor | |
Walker(float ax, float ay) { | |
x = ax; | |
y = ay; | |
if (random(0, 100) < 50) { | |
clr = color(255, 10); | |
} else { | |
clr = color(0, 10); | |
} | |
} | |
void display() { | |
/* | |
fill(clr); | |
ellipse(x, y, 20, 20); | |
*/ | |
stroke(clr); | |
pushMatrix(); | |
translate(x, y); | |
rotate(random(0, radians(360))); | |
line(0, 0, 10, 0); | |
popMatrix(); | |
} | |
void move() { | |
x += random(-1, 1); | |
y += random(-1, 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment