// Continuous accumulated deviation of normal distribution 3 // by John Clavin - August 2015 Point[] points; int middle; int numOfPoints; int xSpace; void setup() { size(450, 660); // 50 x 9 frameRate(30); noStroke(); background(220); middle = height/2; xSpace = width/9; numOfPoints = 160; // 20 x 8 points = new Point[numOfPoints]; for (int i = 0; i < points.length; i++) { int xPlacement = ((i % 8) + 1) * xSpace; points[i] = new Point(xPlacement); } } void draw() { background(220); stroke(160); strokeWeight(1); for (int i = 1; i < 9; i++) { line(i * xSpace, 15, i * xSpace, height - 15); } stroke(0); strokeWeight(1); line(0, middle, width, middle); for (int i = 0; i < points.length; i++) { Point a = points[i]; a.setPoint(); } for (int i = 0; i < points.length; i++) { Point b = points[i]; fill(b.objectFill); ellipse(b.xPosition, middle + b.randCount, 6, 6); } } void mousePressed() { reStart(); } void reStart() { for (int i = 0; i < points.length; i++) { Point c = points[i]; c.resetObjects(); } background(220); } class Point { float rand; int randCount; int xPosition; color objectFill; Point(int xPos) { xPosition = xPos; setColor(); } void setPoint() { rand = random(1); if (rand >= .5) randCount += 1; else randCount -= 1; } void setColor() { objectFill = color(random(200), random(200), random(200)); } void resetObjects() { randCount = 0; // setColor(); } }