Zoey Lin's Generative Flower
Made by Zoey
function setup() { createCanvas(1700, 800); frameRate(1); } 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()) } function pick (inputArray) { return inputArray[Math.floor(inputArray.length * Math.random())] } class Flower { constructor(xposition,size,yposition) { this.xposition = xposition; this.size = size this.flowerColor = ["yellow","pink","blue","orange", "purple"]; this.yposition = yposition this.petalN = Math.floor(randomRange(5,10)); } draw() { let colorPicker = pick(this.flowerColor) //BODY// noStroke(); translate(this.xposition, this.yposition); if(this.colorPicker=="pink"){ fill(214,213,183) }else if(colorPicker=="orange"){ fill(209,186,116) }else if(colorPicker=="blue"){ fill(230,206,172) }else if(colorPicker=="purple"){ fill(236,173,158) }else{ fill( 244,96,108) } for (let i = 0; i < this.petalN; i++) { ellipse(0, 0, this.size, this.size/2); rotate(PI / 5); } fill(255); circle(0, 0, this.size/3); resetMatrix(); } } class Background { constructor (yposition,xposition, size, bColor, bposition) {this.yposition = yposition; this.xposition = xposition; this.backgroundSize = size; this.backgroundColor = bColor; this.backgroundposition = bposition; this.fillColors = [190,237,199] } draw () { noStroke(); fill(color("beige")) for(let i = 0 ; i < this.fillColors.length; i++){ let colorPicker = pick(this.fillColors) fill(colorPicker); rect(this.xposition,this.yposition,100,100); fill(255); rect(this.xposition+10,this.yposition+10,80,80); }} } function backgroundArray (n) { let outputArray = []; for (let i = 0; i < n ; i++) { outputArray.push(new Background (1 + (i*100),1, 1, 1)) } return outputArray } let myBackgrounds = backgroundArray(17); function draw() { background(0); let x = 0 let y = 0 for(let i = 0; i < 500; i++){ let background1 = new Background (y, x, 1000,1000); background1.draw(); let flower1 = new Flower (x,randomRange(70, 70) , y); flower1.draw(); x = x + 100 if(x == 1800){ x = x - 1800 y = y + 100 } } }