// Two Paintings by John Clavin -- May 21, 2016 var society_1; var society_2; function setup() { createCanvas(1080, 580); background(250); society_1 = new Society(); society_2 = new Society(); for (var i = 0; i < 420; i++) { var paintColor = color(random(255), random(255), random(255)); var p = new Person(paintColor); society_1.addPerson(p); } for (var j = 0; j < 420; j++) { paintColor = color(random(255), random(255), random(255)); p = new Person(paintColor); society_2.addPerson(p); } } function draw() { society_1.runSociety(); translate(500, 0); society_2.runSociety(); if (frameCount > 3200) { noLoop(); } } Society = function() { this.people = []; } Society.prototype.addPerson = function(p) { this.people.push(p); } Society.prototype.runSociety = function() { for (var i = 0; i < this.people.length; i++) { this.people[i].runPeople(); } } function Person(c) { this.position = createVector(random(100, 480), random(100, 480)); this.infection = 0; this.colorType = c; } Person.prototype.runPeople = function() { this.setColor(); this.render(); this.spreadInfection(); } Person.prototype.spreadInfection = function() { this.x_decision = int(random(3, 6)); if (this.x_decision == 3) { this.spreadto_x = -1; } else if (this.x_decision == 4) { this.spreadto_x = 0; } else { this.spreadto_x = 1; } this.y_decision = int(random(3, 6)); if (this.y_decision == 3) { this.spreadto_y = -1; } else if (this.y_decision == 4) { this.spreadto_y = 0; } else { this.spreadto_y = 1; } this.spreadto_x += this.position.x; this.spreadto_y += this.position.y; this.position.x = this.spreadto_x; this.position.y = this.spreadto_y; } Person.prototype.setColor = function() { stroke(this.colorType); } Person.prototype.render = function() { point(this.position.x, this.position.y); }