xxxxxxxxxx
86
// rotation learned from http://learn.digitalharbor.org/courses/creative-programming/lessons/p5-js-transformations-rotate/
// func from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
}
let colours = ["#6EEB83", "#1be7ff", "#FFB800", "#ff5714"];
let one = [];
function setup() {
// frameRate(5);
createCanvas(400, 400);
angleMode(DEGREES);
one[1] = new Flower(random(90,100), colours[getRandomInt(0,colours.length-1)]);
}
function draw() {
// background(0);
if (one[one.length-1].get_size() > 700)
{
one[one.length] = new Flower(random(90,100), colours[getRandomInt(0,colours.length-1)]);
}
one[one.length-1].build();
print(one[one.length-1].get_size());
}
class Flower{
constructor(pos,clr){
this.width=random(10,30);
this.current_angle = 0;
this.posY = pos;
this.posX = pos;
this.clr = clr;
this.sizeA = 30;
this.sizeB = 30;
}
rotate(){
this.current_angle = this.current_angle + 1;
}
print_pos(){
print(this.posY, this.posX)
}
inc_size(){
this.sizeA = this.sizeA +1;
}
get_size(){
return this.sizeA;
}
build(){
this.rotate();
this.inc_size();
translate(this.posY,this.posX);
rotate(this.current_angle);
rectMode(CENTER);
// fill(this.clr);
self.squareColor = color(this.clr);
self.squareColor.setAlpha(random(0,10));
fill(self.squareColor);
noStroke();
rect(0, 0, this.sizeA, this.sizeB*2);
rect(0, 0, this.sizeB*2, this.sizeA);
}
}