====== Yuna Wu's Generative Flower ====== By [[yuna-wu|Yuna Wu]] === My Code === This code is the code that I made Flowers. And this flower have eyes and it have many different colors. function setup() { createCanvas(1700, 800); //frameRate(5); noLoop(); } function pick (inputArray) { return inputArray[Math.floor(inputArray.length * Math.random())] } function randomRange (min, max) { return min + ((max-min) * Math.random()) } //The function that can choose a color function randomColor () { let colors=["lightcoral","pink","lightblue","yellow", "lavender", "orange"]; let colorNow = Math.floor(Math.random()*6); return colors[colorNow] } function buildArray (n, fillFunction) { let outputArray = []; for (let i = 0; i < n; i++) { outputArray.push(fillFunction(i)) } return outputArray } class Petals { constructor (startingX, startingY, pSize, Color) { this.positionX = startingX; this.positionY = startingY; this.size = pSize; this.color = Color; } draw() { if (this.color == "lightblue") {return ellipse(this.positionX+180-155, this.positionY+0, this.size/3, this. size);} else {} } } /*function twoRects (x,y,size,thinOrThick) { if (thinOrThick == "thin") {return rect (x,y,size/3,size)} else {return rect (x,y,size,size)} }*/ class Flower { constructor (fSizemin, fSizemax, Color, startingX, startingY) { this.size = randomRange(fSizemin, fSizemax); this.color = Color; this.positionX = startingX; this.positionY = startingY; if (this.color == "random") {this.color = randomColor()} } draw () { strokeWeight(2); stroke(0); //noStroke(); //if-staments if(this.color == "yellow") {this.positionX = randomRange(750, 1645); this.positionY = this.positionY + 100} else if (this.color == "lightcoral") {this.positionY=this.positionY + 400; this.positionX=randomRange(10, 690)} else if (this.color == "lavender") {this.positionX=randomRange(750, 1645); this.positionY=this.positionY + 400} else if (this.color == "orange") {this.positionX=randomRange(10, 700); this.positionY = this.positionY + 100} else if (this.color == "lightblue") {this.positionX=randomRange(10, 700); this.positionY = this.positionY + 250} else if (this.color == "pink") {this.positionX=randomRange(750, 1645); this.positionY = this.positionY + 250} //red fill(this.color); ellipse(this.positionX+180-155, this.positionY+0, this.size, this.size); //blue fill(this.color); ellipse(this.positionX+165-155, this.positionY+180-130, this.size, this.size); //purple fill(this.color); ellipse(this.positionX+0, this.positionY+150-130, this.size, this.size); //yellow fill(this.color); ellipse(this.positionX+197-155, this.positionY+181-130, this.size, this.size); //orange fill(this.color); ellipse(this.positionX+205-155, this.positionY+150-130, this.size, this.size); //center of flower fill(245, 233, 203); ellipse(this.positionX+180-155, this.positionY+160-130, 40, 40); fill("black") ellipse(this.positionX+172-155, this.positionY+156-130, 5, 15); ellipse(this.positionX+185-155, this.positionY+156-130, 5, 15); resetMatrix(); } } let randomFlowers = buildArray(600,i => new Flower(30, 35, "random", randomRange(0,250), 10)); let last5Random = buildArray(5,i => new Flower(30*2, 35*2, "random", randomRange(0,250), 10)); let bigFlower = buildArray(1,i => new Flower(30*3, 35*3, "orange", randomRange(0,250), 10)); //let Petals1 = buildArray(600,i => new Petals(30+Math.random()*255, 30+Math.random()*255,100,"lightblue")); let randomFlowers2 = buildArray(600,i => new Flower(30, 35, "random", randomRange(0,250), 500)); function draw() { background(140, 197, 237); //let flower1 = new Flower(30, 35, "lightcoral", randomRange(0,250), 80); //flower1.draw(); randomFlowers2.forEach(x => x.draw()) randomFlowers.forEach(x => x.draw()) last5Random.forEach(x => x.draw()) bigFlower.forEach(x => x.draw()) pick(10); //r1 = twoRects (100,100,100,'thin'); p1= new Petals(150,150,100,"lightblue"); }