Created
April 21, 2017 22:43
-
-
Save catarak/051573209002d100ce7743f5a4e54cf6 to your computer and use it in GitHub Desktop.
This file contains 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
// ONE | |
function Agent() { | |
this.position = createVector(random(width), random(height)); | |
} | |
Agent.prototype.update = function() { | |
ellipse(this.position.x, this.position.y, 50, 50); | |
} | |
//// | |
var agents = []; | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
for (var i = 0; i < 100; i++) { | |
agents.push(new Agent()); | |
} | |
} | |
function draw() { | |
for (var i = 0; i < 100; i++) { | |
agents[i].update(); | |
} | |
} | |
// TWO | |
function Agent() { | |
this.position = createVector(random(width), random(height)); | |
} | |
Agent.prototype.draw = function() { | |
ellipse(this.position.x, this.position.y, 50, 50); | |
} | |
Agent.prototype.update = function() { | |
this.position.x += random(2) - 1; | |
this.position.y += random(2) - 1; | |
if (this.isOffscreen()) { | |
this.position.set(random(width), random(height)); | |
} | |
} | |
Agent.prototype.isOffscreen = function() { | |
return this.position.x < 0 || this.position.x > width | |
|| this.position.y < 0 || this.position.y > height; | |
} | |
//// | |
var agents = []; | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
for (var i = 0; i < 100; i++) { | |
agents.push(new Agent()); | |
} | |
} | |
function draw() { | |
for (var i = 0; i < 100; i++) { | |
agents[i].draw(); | |
agents[i].update(); | |
} | |
} | |
////THREE | |
function Agent() { | |
this.position = createVector(random(width), random(height)); | |
this.lastPosition = this.position.copy(); | |
} | |
Agent.prototype.draw = function() { | |
line(this.lastPosition.x, this.lastPosition.y, this.position.x, this.position.y); | |
} | |
Agent.prototype.update = function() { | |
this.lastPosition = this.position.copy(); | |
this.position.x += random(8) - 4; | |
this.position.y += random(8) - 4; | |
if (this.isOffscreen()) { | |
this.position.set(random(width), random(height)); | |
this.lastPosition = this.position.copy(); | |
} | |
} | |
Agent.prototype.isOffscreen = function() { | |
return this.position.x < 0 || this.position.x > width | |
|| this.position.y < 0 || this.position.y > height; | |
} | |
//// | |
var agents = []; | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
for (var i = 0; i < 100; i++) { | |
agents.push(new Agent()); | |
} | |
} | |
function draw() { | |
for (var i = 0; i < 100; i++) { | |
agents[i].draw(); | |
agents[i].update(); | |
} | |
} | |
////FOUR | |
function Agent() { | |
this.position = createVector(random(width), random(height)); | |
this.lastPosition = this.position.copy(); | |
this.angle = 0; | |
} | |
Agent.prototype.draw = function() { | |
line(this.lastPosition.x, this.lastPosition.y, this.position.x, this.position.y); | |
} | |
Agent.prototype.update = function() { | |
this.lastPosition = this.position.copy(); | |
this.angle = noise(this.position.x * 0.03, this.position.y * 0.03)*10; | |
this.position.x += cos(this.angle) * 4; | |
this.position.y += sin(this.angle) * 4; | |
if (this.isOffscreen()) { | |
this.position.set(random(width), random(height)); | |
this.lastPosition = this.position.copy(); | |
} | |
} | |
Agent.prototype.isOffscreen = function() { | |
return this.position.x < 0 || this.position.x > width | |
|| this.position.y < 0 || this.position.y > height; | |
} | |
//// | |
var agents = []; | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
for (var i = 0; i < 100; i++) { | |
agents.push(new Agent()); | |
} | |
} | |
function draw() { | |
for (var i = 0; i < 100; i++) { | |
agents[i].draw(); | |
agents[i].update(); | |
} | |
} | |
////FIVE | |
function Agent() { | |
this.position = createVector(random(width), random(height)); | |
this.lastPosition = this.position.copy(); | |
this.angle = 0; | |
this.stepSize = random(1, 5); | |
} | |
Agent.prototype.draw = function(alpha, strokeWidth) { | |
stroke(0, alpha); | |
strokeWeight(this.stepSize * strokeWidth); | |
line(this.lastPosition.x, this.lastPosition.y, this.position.x, this.position.y); | |
} | |
Agent.prototype.update = function(noiseScale, noiseStrength) { | |
this.lastPosition = this.position.copy(); | |
this.angle = noise(this.position.x * noiseScale, this.position.y * noiseScale)*noiseStrength; | |
this.position.x += cos(this.angle) * this.stepSize; | |
this.position.y += sin(this.angle) * this.stepSize; | |
if (this.isOffscreen()) { | |
this.position.set(random(width), random(height)); | |
this.lastPosition = this.position.copy(); | |
} | |
} | |
Agent.prototype.isOffscreen = function() { | |
return this.position.x < 0 || this.position.x > width | |
|| this.position.y < 0 || this.position.y > height; | |
} | |
//// | |
var agents = []; | |
var numAgents = 2000; | |
var noiseScale = 0.003; | |
var noiseStrength = 10; | |
var agentAlpha = 90; | |
var strokeWidth = 0.3; | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
for (var i = 0; i < numAgents; i++) { | |
agents.push(new Agent()); | |
} | |
} | |
function draw() { | |
background(255, 5); | |
for (var i = 0; i < numAgents; i++) { | |
agents[i].draw(agentAlpha, strokeWidth); | |
agents[i].update(noiseScale, noiseStrength); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment