// Continuous accumulated deviation of normal distribution 2 by John Clavin // Converted to p5.js by John Clavin - August 2015 // Fixed Sept 30, 2017 - JC var points = []; var middle; var numOfPoints; var widthCount; var imageSize; function setup() { createCanvas(940, 660); imageSize = 4 * width * height; noStroke(); background(220); middle = height/2; numOfPoints = 30; widthCount = 0; for (let i = 0; i < numOfPoints; i++) { points[i] = new Point(); points[i].setColor(); } } function draw() { for (let i = 0; i < numOfPoints; i++) { points[i].setPoint(); } for (let i = 0; i < numOfPoints; i++) { fill(points[i].objectFill); ellipse(widthCount, middle + points[i].randCount, 3, 3); } if (widthCount > width - 5) { loadPixels(); for(let i = 0; i < imageSize; i = i + 4) { pixels[i] = pixels[i + 8] pixels[i + 1] = pixels[i + 9] pixels[i + 2] = pixels[i + 10] pixels[i + 3] = pixels[i + 11] } updatePixels(); } else { widthCount = widthCount + 2; } stroke(220); strokeWeight(5); line(0, 0, 0, height); noStroke(); } function reStart() { for (let i = 0; i < numOfPoints; i++) { points[i].resetObjects(); } widthCount = 0; background(220); } function Point() { this.randCount = 0; this.setPoint = function() { this.rand = random(1); if(this.rand >= 0.5) { this.randCount += 1; } else { this.randCount -= 1; } } this.setColor = function() { this.objectFill = color(random(200), random(200), random(200)); } this.resetObjects = function() { this.randCount = 0; } }