======Olivia Wang's Generative Flower====== by [[Olivia-Wang|Olivia Wang]] function adjustPosition (objectArray, functionName){ return functionName} function buildArray (numberOfShapes, fillFunction) { let outputArray = []; for (let i = 0; i < numberOfShapes; i++) { outputArray.push(fillFunction(i)) } return outputArray} function circularPositions (startingX , startingY,numberOfShapes,cSize) { let positionArray = buildArray(numberOfShapes, (i) => new Point(startingX, startingY)); let testCircle = adjustPosition(positionArray, circlePattern(cSize, positionArray)); return testCircle } function circlePattern (cSize, cPosition){ let angle=360/cPosition.length return cPosition.map((p,i) => {return p.moveByAngle(i*angle,cSize)}) } class RandomShape { constructor(x){ this.position=x; this.shape=shapeSelector(); this.color=colorSelector(); this.size=randomRange(10, 35) this.width=this.size this.height=this.size } draw(){ if (this.shape=="Flower"){ fill(this.color) let petalN = 6; if (this.color == "white") { fill(255, 238, 230); petalN = 5; } if (this.color == "green") { fill(255, 204, 204); petalN = 11; } if (this.color == "darkpink") { fill(255, 128, 128); petalN = 9; } if (this.color == "lightpink") { fill(255, 128, 128); petalN = 7; } let Leaf=circularPositions(this.position.x,this.position.y,petalN, 10); fill(178, 178, 102); Leaf.forEach(x => circle(x.x+15,x.y-10,this.size-15)); let flowerA=circularPositions(this.position.x,this.position.y,10, 10); console.log(flowerA.length) fill(255, 128, 128); flowerA.forEach(x=>circle(x.x,x.y,this.size)); flowerA.forEach(x=>circle(x.x-50,x.y,this.size)); flowerA.forEach(x=>circle(x.x+50,x.y,this.size)); circle(this.position.x,this.position.y,this.size); let flowerB=circularPositions(this.position.x,this.position.y,petalN, 10); fill(255, 179, 179); flowerB.forEach(x=>circle(x.x,x.y-100,this.size-15)) flowerB.forEach(x=>circle(x.x-50,x.y,this.size-15)) flowerB.forEach(x=>circle(x.x+50,x.y,this.size-15)) fill("white") circle(this.position.x,this.position.y,this.size-20) } } } function colorSelector () { let colors = ["lightpink", "green", "white", "darkpink"]; return colors[Math.floor(randomRange(0,4))] } function shapeSelector () { let colors = ["Flower"]; return colors[Math.floor(randomRange(0,1))] } function randomRange (min, max) { return min + ((max-min) * Math.random()) } function flower () { fill (240, 173, 178); stroke("white"); circle(705, 390, 300); circle(1055, 390, 300); circle(745 , 567, 300); circle(1015 ,567, 300); circle(880, 200, 300); //2 fill(237, 190, 194); circle(705, 390, 250); circle(1055, 390, 250); circle(765 , 567, 250); circle(1000,567, 250); circle(880, 200, 250); circle(880, 395, 200); } class Point { constructor(x,y) { this.x = x; this.y = y; } move(xDistance, yDistance) { return new Point(this.x + xDistance, this.y + yDistance) } moveByAngle (angle, distance) { let r = angle * Math.PI / 180; return new Point(this.x + distance*Math.sin(r), this.y + distance*Math.cos(r)) } } function setup() { createCanvas(1700, 800); noLoop() } function BuildArray (numberOfShapes, fillFunction) { let outputArray = []; for (let i = 0; i < numberOfShapes; i++) { outputArray.push(fillFunction(i)) } return outputArray} let shapesXYSetCounter= 0 let shapesXYSetY=0 function shapesXYSet (i){ shapesXYSetCounter+=1 if(shapesXYSetCounter>10){shapesXYSetY+=200;shapesXYSetCounter=1} return new Point(200*shapesXYSetCounter,100+shapesXYSetY) } let shapesXY = BuildArray(100,shapesXYSet) console.log(shapesXY) let shapesNow = shapesXY.map(x=>new RandomShape(x)) function draw() { background(237, 190, 194); flower(); shapesNow.forEach((x) => x.draw()); }