You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

122 lines
2.9 KiB

"use strict"
class Tree{
constructor(brick){
this.pos = brick.pos;
this.dim = createVector(random(10, 30), random(100, 200));
this.current = createVector(0, 0);
this.dispoX = random(brick.dim.x - 40) + 20;
this.colorSetup();
}
show(){
//Wood
fill(this.color.wood);
rect(this.pos.x + this.dispoX, this.pos.y - this.dim.y, this.dim.x, this.dim.y);
//Leaf
fill(this.color.leaf);
for (let i = 0; i <= TWO_PI; i += PI / 4){
let x = this.dispoX + this.pos.x + this.dim.x / 2 + this.dim.x * 2 * sin(i);
let y = this.pos.y - this.dim.y + this.dim.x * 2 * cos(i);
ellipse(x, y, this.dim.x * 3);
}
ellipse(this.dispoX + this.pos.x + this.dim.x / 2, this.pos.y - this.dim.y, this.dim.x * 3);
}
colorSetup(){
let l = color(colors.brick.tree.leaf),
w = color(colors.brick.tree.wood);
colorMode(HSB);
let leaf = color(hue(l), saturation(l), brightness(l) + random(-10, 10)),
wood = color(hue(w), saturation(w), brightness(w) + random(-10, 10));
colorMode(RGB);
this.color = {
leaf: leaf,
wood: wood
};
}
}
class Grass{
constructor(parent, dispoX){
this.pos = parent.pos;
this.dispoX = dispoX;
this.positions = [];
this.flower = ranBool() ? new Flower(this) : null;
for (let i = HALF_PI + 0.25; i < HALF_PI + PI - 0.25; i += random(PI / 8, PI / 16)) this.positions.push(createVector(sin(i) * 15, cos(i) * 25));
}
show(){
if (this.flower){
this.flower.show();
}
fill(colors.brick.grass);
for (let p of this.positions){
let x1 = this.pos.x + this.dispoX + p.x;
let x2 = this.pos.x + this.dispoX + p.x * 0.5;
let y = this.pos.y + p.y;
triangle(x1, y, this.pos.x + this.dispoX, this.pos.y, x2, y);
}
}
}
class Flower{
constructor(grass){
this.pos = grass.pos;
this.dim = createVector(3, random(25, 50));
this.dispoX = grass.dispoX;
this.colorSetup();
let cr = random(2, 5);
this.radius = {
center: cr,
petal: cr + random(2, 4)
};
this.petals = [];
for (let i = 0; i < TWO_PI; i += PI / 2){
let x = this.dispoX + sin(i) * this.radius.center * 2;
let y = cos(i) * this.radius.center * 2;
this.petals.push(createVector(x, y));
}
}
show(){
//Haulm
strokeWeight(this.dim.x);
stroke(colors.brick.flower.haulm);
line(this.pos.x + this.dispoX, this.pos.y, this.pos.x + this.dispoX, this.pos.y - this.dim.y);
//Center
noStroke();
fill(this.color.center);
ellipse(this.pos.x + this.dispoX, this.pos.y - this.dim.y, this.radius.center * 2);
//Petals
fill(this.color.petal);
for (let p of this.petals){
ellipse(p.x + this.pos.x, p.y + this.pos.y - this.dim.y, this.radius.petal * 2);
}
}
colorSetup(){
let c = color(colors.brick.flower.center),
p = color(colors.brick.flower.petal);
colorMode(HSB);
let center = color(int(random(360)), saturation(c), brightness(c));
let petal = color(int(random(360)), saturation(p), brightness(p));
colorMode(RGB);
this.color = {
center: center,
petal: petal
};
}
}