Ingram Chung's Generative Flower
function setup() { createCanvas(1700, 800); //frameRate(5); noLoop() } let shapes = ["ellipse","triangle","rect"]; let colors = ["pink","yellow","white","red","lavender"] function pick (inputArray) { return inputArray[Math.floor(inputArray.length * Math.random())] } // start from 75 (tip of ellipse, 150/2), since ellipse is 150 wide function buildArray (n, fillFunction) { let outputArray = []; for (let i = 0; i < n; i++) { outputArray.push(fillFunction(i)) } return outputArray } function randomRange (min, max) { return min + ((max-min) * Math.random()) } class RandomShape { constructor (maxSize,myColor) { this.color = pick(colors); this.shape = pick(shapes);// start from 75 (tip of ellipse, 150/2), since ellipse is 150 wide this.xposition = randomRange(400,1750); this.yposition = randomRange(50,750); this.size = randomRange(1,maxSize); } draw () { if (this.color == "white") {this.xposition > 275 && this.xposition < 800; } if (this.color == "pink" && "red") {this.size * 2; } //if (this.xposition > 500 && (this.xposition = 600)); if (this.xposition > 500); { stroke(255); // fill(255, 244, 25); // left side random color flowers fill(this.color); translate(this.xposition,this.yposition); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); } // right side flowers stroke(255); fill(255, 244, 25); translate(this.xposition,this.yposition); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); rotate(radians(40)); ellipse(75, 0, 150 * this.size, 50); //center of flower translate (-250,-250) stroke(255); fill(color(random(0,255),random(0,255),random(0,255))); ellipse(250, 250, 150*this.size, 150*this.size); // random shapes fill(this.color); if (this.shape == "rect" ) {rect(this.xposition, this.yposition,this.size,this.size)} //else if (this.shape == "ellipse") //{ellipse(this.xposition, this.yposition,this.size,this.size)} else {triangle(this.xposition, this.yposition,this.xposition + this.size, this.yposition + this.size,this.xposition - this.size, this.yposition + this.size)} resetMatrix() } } // check buildArray on the wiki to make 10 objects let flowers = buildArray (200, x => new RandomShape(1.2,"red")); flowers[flowers.length - 1].size = 3; flowers[flowers.length - 1].color = "blue"; function draw() { background(20); let shape1 = new RandomShape(); shape1.draw(); console.log (flowers); flowers.forEach ( x => x.draw()); }