xxxxxxxxxx
108
// Vivianna Mo
// Intro to IM - Shiloh
// Sept. 20 2022
// Assignment 3: Object Oriented Programming
// Description: flowers falling off the tree branches
flowerColors = ["#EC275F", "#F25477", "#E476A6", "#F3868C"];
let oneFlower = [];
let angle = 30;
function setup() {
createCanvas(550, 550);
// so I was experimenting with my code and it crashed before I could save it, which meant I lost the link to the reference that helped me figure out that floor is needed in order to randomly generate a number for colors, which is an array.
// this is a similar code but not the one I used: https://editor.p5js.org/LizPina/sketches/9LF5GRL7
pickAColor = floor(random(flowerColors.length));
angleMode(DEGREES);
for (let i = 0; i < 200; i++) {
oneFlower[i] = new Flowers(
random(540),
random(540),
random(-360, 360),
random(-360, 360),
random(50, 70)
);
}
}
function draw() {
background("#AEEDFC");
noStroke();
push();
stroke("#694333");
strokeWeight(1.5);
translate(width / 2, height);
branch(150);
pop();
for (let i = 0; i < oneFlower.length; i++) {
oneFlower[i].show();
oneFlower[i].breeze();
// oneFlower[i].growAndShrink();
}
}
function branch(len) {
line(0, 0, 0, -len);
translate(0, -len);
if (len > 8) {
push();
rotate(angle);
branch(len * 0.75);
pop();
push();
rotate(-angle);
branch(len * 0.75);
pop();
}
}
class Flowers {
constructor(x, y, arcPt1, arcPt2, size) {
this.pointX = x;
this.pointY = y;
this.arcPt1 = arcPt1;
this.arcPt2 = arcPt2;
this.size = size;
this.changeSize = 0.25;
this.color = color(flowerColors[pickAColor]);
}
breeze() {
if (this.pointX < this.pointX + 50) {
this.pointX += random(-1, 1);
this.pointY += 0.75;
}
}
// This code made the flower grow, but that didn't really make sense
// growAndShrink() {
// this.size += this.changeSize;
// if(this.size > 80) {
// this.size;
// }
// //this did something weird where it would randomly pop up as a full circle, whereas I wanted it to slowly grow into a circle
// // if(this.arcPt1 + this.arcPt2 < 360) {
// // this.arcPt1 += this.changeSize;
// // }
// }
show() {
this.color.setAlpha(100);
fill(this.color);
arc(
this.pointX,
this.pointY,
this.size,
this.size,
this.arcPt1,
this.arcPt2
);
}
}