// Circular Painting 1 // September 27, 2017 -- John Clavin var center_X; var center_Y; var polarRadius; var controlCounter; var numOfObjects = 2000; var numOfpPoints = 200; var restartFlag = false; function setup() { createCanvas(800, 800); frameRate(60); background(246); noStroke(); center_X = width / 2; center_Y = height / 2; polarRadius = width / 2; initialize(); } function draw() { controlCounter++; painting.run(); if (controlCounter > 500) { restartFlag = true; noLoop(); } } function mousePressed() { if (restartFlag === true) { if (isMouseOver() === true) { initialize(); restartFlag = false; loop(); } } return false; } function Painting() { this.paintObjects = []; this.colorArray = []; this.addObject = function(pos, oColor) { var p = new PaintObject(pos, oColor); this.paintObjects.push(p); } this.createColors = function() { this.colorArray[0] = color(random(140), random(160), random(160), 120); this.colorArray[1] = color(random(20), random(200), random(100), 120); this.colorArray[2] = color(random(20), random(100), random(200), 120); this.colorArray[3] = color(random(200), random(100), random(20), 120); this.colorArray[4] = color(random(160), random(160), random(160), 120); this.colorArray[5] = color(random(20), random(200), random(100), 120); this.colorArray[6] = color(random(20), random(100), random(200), 120); this.colorArray[7] = color(random(200), random(100), random(20), 120); this.colorArray[8] = color(random(160), random(140), random(140), 120); this.colorArray[9] = color(random(20), random(200), random(100), 120); } this.run = function() { for (var i = 0; i < this.paintObjects.length; i++) { this.paintObjects[i].update(); this.paintObjects[i].render(); } } } function PaintObject(pos, objectColor) { this.circlePos = pos; this.objectColor = objectColor; this.movingPos = this.circlePos; this.update = function() { var moveAmt = 2; this.x_decision = floor(random(3, 6)); if (this.x_decision == 3) { this.spreadto_x = -moveAmt; } else if (this.x_decision == 4) { this.spreadto_x = 0; } else { this.spreadto_x = moveAmt; } this.y_decision = floor(random(3, 6)); if (this.y_decision == 3) { this.spreadto_y = -moveAmt; } else if (this.y_decision == 4) { this.spreadto_y = 0; } else { this.spreadto_y = moveAmt; } this.spreadto_x += this.movingPos.x; this.spreadto_y += this.movingPos.y; this.movingPos.x = this.spreadto_x; this.movingPos.y = this.spreadto_y; } this.render = function() { var pointSize = 3; fill(this.objectColor); ellipse(this.movingPos.x, this.movingPos.y, pointSize, pointSize); } } function initialize() { background(230); controlCounter = 0; painting = new Painting(); painting.createColors(); var jcRadians = 0; var polarPoint_X; var polarPoint_Y; for (var i = 0; i < numOfpPoints; i++) { var colorIndex = 0; jcRadians = jcRadians + 0.0315; for (var radius = 0; radius < polarRadius; radius = radius + 40) { polarPoint_X = center_X + cos(jcRadians) * radius; polarPoint_Y = center_Y + sin(jcRadians) * radius; var oColor = painting.colorArray[colorIndex]; colorIndex++; painting.addObject(createVector(polarPoint_X, polarPoint_Y), oColor); } } } function isMouseOver() { if ((mouseX < 0) || (mouseX > width) || (mouseY < 0) || (mouseY > height)) { return false; } else { return true; } }