// Random Distribution Bell Curve // With 2 Random Distributions in // a Cartesian Coordinate View // by John Clavin - April 2, 2017 var dots_X = []; var PolarDots = []; var numOfDots = 200; var bellHeight = 151; var loopCount = 0; function setup() { createCanvas(600, 600); noStroke(); background(176); for (var a = 0; a < numOfDots; a++) { var aa = new PolarDot(); PolarDots.push(aa); } for (var b = 0; b < numOfDots; b++) { dots_X[b] = 0; } } function draw() { background(176, 8); var i; for (i = 0; i < 200; i++) { calculate_X(flipCoin()); } for (i = 0; i < 140; i++) { var k = PolarDots[i]; k.calcX_point(flipCoin()); k.calcY_point(flipCoin()); } for (i = 0; i < numOfDots; i++) { fill(0); ellipse(i * 3, height - dots_X[i], 3, 3); } for (i = 0; i < numOfDots; i++) { var j = PolarDots[i]; fill(254); ellipse(j.xLocation * 3, j.yLocation * 3, 3, 3); } if (loopCount < bellHeight) { loopCount++; } else { noLoop(); } } function calculate_X(hds) { var heads = hds; var xLocation; xLocation = heads - 900; // adjust to window dots_X[xLocation] += 1; } function flipCoin() { var rand; var headCount = 0; for (var c = 0; c < 2000; c++) { rand = random(1000); if (rand >= 500) { headCount += 1; } } return headCount; } function PolarDot() { this.xLocation; this.yLocation; this.calcX_point = function(hds) { this.heads = hds; this.xLocation = this.heads - 900; } this.calcY_point = function(hds) { this.heads = hds; this.yLocation = this.heads - 900; } }