xxxxxxxxxx
157
let branchLength;
let xplus;
var xpos;
let color1 = ["#c79092", "#cba761", "#7a3340"];
let color2 = ["#01739d", "#7a95a4", "#9DAC6B"];
let color3 = ["#82A699", "#B3938F", "#cba761"];
let leafColor1; let leafColor2; let leafColor3;
let layer2;
let cloud;
let quilt;
function preload() {
cloud = loadImage('sky.jpg');
quilt = loadImage('AmeliaBennetHousetop.jpeg');
}
function setup() {
createCanvas(600, 500);
//background("#99DAF7");
background(quilt);
// background('#305632');
layer2 = createGraphics(width, height);
//corner sun
//layer2.imageMode(CENTER);
// layer2.background(sky);
// layer2.erase();
// layer2.ellipse(105, 95, 190, 190);
// layer2.noErase();
// image(layer2, width/2, height/2);
//sun
// var sky = color('#ffdf81');
// noStroke();
// for (i = 500; i > 0; i -= 50) {
// fill(sky);
// sky = lerpColor(sky, color('#FBEE79'), .25);
// ellipse(width/2, 300, i);
// }
//groud
noStroke();
fill("#83AB85");
rect(0, 455, width, 55);
// cloud
fill('#f9f5e5');
arc(430, 140, 180, 60, PI + .1, -0.1, OPEN);
arc(490, 130, 50, 50, PI + .1, -0.1, OPEN);
arc(430, 120, 80, 80, PI + .1, -0.1, OPEN);
arc(470, 130, 50, 50, PI + .1, -0.1, OPEN);
let turtleString = "B";
// storing string as variable B
// for loop allows code to run more than once
for(let i=0; i<7; i++){
turtleString = turtleString.replaceAll("B", "F[+BB][-BB]")
}
translate(width/2, height - 50);
strokeWeight(3);
stroke("#58825A" );
renderString(turtleString);
}
function draw(){
}
function renderString(string) {
branchLength = random(60, 85);
print('branchLength', branchLength);
xpos = random(width);
let angle = Math.PI/13;
for (let character of string) {
if (character == 'F') {
strokeWeight(branchLength/11);
line(0, 0, 0, -branchLength);
translate(0, -branchLength);
} else if (character == '+') {
rotate(random());
} else if (character == '-') {
rotate(-random());
} else if (character == '[') {
branchLength = branchLength / 1.5
print('newbranchLength', branchLength);
push();
} else if (character == ']') {
branchLength = branchLength * 1.5
pop();
}
//leaves!
if(branchLength < 15){
noStroke();
if (xpos <= 200){
leafColor1=random(color1);
fill(leafColor1);
//print('leaf color', leafColor)
}
if (xpos >= 400){
leafColor2=random(color2);
fill(leafColor2);
//print('leaf color', leafColor)
}
if (xpos < 400 && xpos > 200){
leafColor3=random(color3);
fill(leafColor3);
//print('leaf color', leafColor)
}
rect(0, 0, random(10, 5), random(10, 5))
}
}
}
function mousePressed(){
let turtleString = "B";
// storing string as variable B
// for loop allows code to run more than once
for(let i=0; i<6; i++){
turtleString = turtleString.replaceAll("B", "F[+BB][-BB]")
}
xpos = random(width);
translate(xpos, height);
print('xpos', xpos);
renderString(turtleString);
}