// Square Painting 3x // August 11, 2019 -- John Clavin // San Bernardino, California var segment; var pRadius; var controlCounter; var numOfObjects = 500; var numOfPoints = 50; var restartFlag = false; function setup() { createCanvas(800, 800); frameRate(60); noStroke(); segment = width / 4; pRadius = 60; initialize(); } function draw() { controlCounter++; painting.run(); if (controlCounter > 740) { restartFlag = true; noLoop(); } } function mousePressed() { if (restartFlag === true) { if (isMouseOver() === true) { initialize(); restartFlag = false; loop(); } } return false; } function Painting() { this.paintObjects = []; this.colorArrays = []; this.addObject = function(pos, oColor) { var p = new PaintObject(pos, oColor); this.paintObjects.push(p); } this.createColors = function() { let dark = true; if ( random(100) > 50 ) { dark = false; } for (let h = 0; h < 9; h++) { this.colorArrays[h] = []; if ( dark ) { for (let i = 0; i < 3; i++) { this.colorArrays[h][i] = color(random(160), random(120), random(120)); } } else { for (let i = 0; i < 3; i++) { this.colorArrays[h][i] = color(random(40, 200), random(40, 200), random(40, 200)); } } } } 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(246); controlCounter = 0; painting = new Painting(); painting.createColors(); var jcRadians = 0; var cRadius = pRadius * 1.74; var center_X; var center_Y; var point_X; var point_Y; var colorIndex; var oColor; center_X = segment; center_Y = segment; for (let i = 0; i < numOfPoints; i++) { jcRadians = jcRadians + 0.126; // 0.0315 point_X = center_X + cos(jcRadians) * pRadius; point_Y = center_Y + sin(jcRadians) * pRadius; colorIndex = floor(random(3)); oColor = painting.colorArrays[0][colorIndex]; fill(oColor); ellipse(center_X, center_Y, cRadius, cRadius); painting.addObject(createVector(point_X, point_Y), oColor); } center_X = segment * 2; center_Y = segment; for (let i = 0; i < numOfPoints; i++) { jcRadians = jcRadians + 0.126; point_X = center_X + cos(jcRadians) * pRadius; point_Y = center_Y + sin(jcRadians) * pRadius; colorIndex = floor(random(3)); oColor = painting.colorArrays[1][colorIndex]; fill(oColor); ellipse(center_X, center_Y, cRadius, cRadius); painting.addObject(createVector(point_X, point_Y), oColor); } center_X = segment * 3; center_Y = segment; for (let i = 0; i < numOfPoints; i++) { jcRadians = jcRadians + 0.126; point_X = center_X + cos(jcRadians) * pRadius; point_Y = center_Y + sin(jcRadians) * pRadius; colorIndex = floor(random(3)); oColor = painting.colorArrays[2][colorIndex]; fill(oColor); ellipse(center_X, center_Y, cRadius, cRadius); painting.addObject(createVector(point_X, point_Y), oColor); } center_X = segment; center_Y = segment * 2; for (let i = 0; i < numOfPoints; i++) { jcRadians = jcRadians + 0.126; point_X = center_X + cos(jcRadians) * pRadius; point_Y = center_Y + sin(jcRadians) * pRadius; colorIndex = floor(random(3)); oColor = painting.colorArrays[3][colorIndex]; fill(oColor); ellipse(center_X, center_Y, cRadius, cRadius); painting.addObject(createVector(point_X, point_Y), oColor); } center_X = segment * 2; center_Y = segment * 2; for (let i = 0; i < numOfPoints; i++) { jcRadians = jcRadians + 0.126; point_X = center_X + cos(jcRadians) * pRadius; point_Y = center_Y + sin(jcRadians) * pRadius; colorIndex = floor(random(3)); oColor = painting.colorArrays[4][colorIndex]; fill(oColor); ellipse(center_X, center_Y, cRadius, cRadius); painting.addObject(createVector(point_X, point_Y), oColor); } center_X = segment * 3; center_Y = segment * 2; for (let i = 0; i < numOfPoints; i++) { jcRadians = jcRadians + 0.126; point_X = center_X + cos(jcRadians) * pRadius; point_Y = center_Y + sin(jcRadians) * pRadius; colorIndex = floor(random(3)); oColor = painting.colorArrays[5][colorIndex]; fill(oColor); ellipse(center_X, center_Y, cRadius, cRadius); painting.addObject(createVector(point_X, point_Y), oColor); } center_X = segment; center_Y = segment * 3; for (let i = 0; i < numOfPoints; i++) { jcRadians = jcRadians + 0.126; point_X = center_X + cos(jcRadians) * pRadius; point_Y = center_Y + sin(jcRadians) * pRadius; colorIndex = floor(random(3)); oColor = painting.colorArrays[6][colorIndex]; fill(oColor); ellipse(center_X, center_Y, cRadius, cRadius); painting.addObject(createVector(point_X, point_Y), oColor); } center_X = segment * 2; center_Y = segment * 3; for (let i = 0; i < numOfPoints; i++) { jcRadians = jcRadians + 0.126; point_X = center_X + cos(jcRadians) * pRadius; point_Y = center_Y + sin(jcRadians) * pRadius; colorIndex = floor(random(3)); oColor = painting.colorArrays[7][colorIndex]; fill(oColor); ellipse(center_X, center_Y, cRadius, cRadius); painting.addObject(createVector(point_X, point_Y), oColor); } center_X = segment * 3; center_Y = segment * 3; for (let i = 0; i < numOfPoints; i++) { jcRadians = jcRadians + 0.126; point_X = center_X + cos(jcRadians) * pRadius; point_Y = center_Y + sin(jcRadians) * pRadius; colorIndex = floor(random(3)); oColor = painting.colorArrays[8][colorIndex]; fill(oColor); ellipse(center_X, center_Y, cRadius, cRadius); painting.addObject(createVector(point_X, point_Y), oColor); } } function isMouseOver() { if ((mouseX < 0) || (mouseX > width) || (mouseY < 0) || (mouseY > height)) { return false; } else { return true; } }