xxxxxxxxxx
104
function setup() {
createCanvas(600, 400);
land();
//button
var patternButton = createButton('New Pattern');
patternButton.mousePressed(picture);
}
function land() {
//background colors but not neccesary since it is in the picture function
background("#5db1f5");
fill("green");
noStroke();
rect(0, 280, 600, 280);
}
function apple(x, y) {
// general shape of apple
noStroke();
fill("red");
circle(x, y, 22 / 2);
circle(x + 12 / 2, y, 22 / 2);
ellipse(x + 6 / 2, y + 4 / 2, 29 / 2, 21 / 2);
// stem
fill("brown");
rect(x + 3.5 / 2, y - 15 / 2, 5 / 2, 10 / 2);
//shine
fill("#f7f0f0");
circle(x + 15 / 2, y - 3 / 2, 5 / 2);
}
function mountain(x) {
// main part
fill("grey");
triangle(x, 50, x - 200, 280, x + 200, 280);
//tip
fill(255);
triangle(x, 50, x - 57, 115, x + 57, 115);
}
function tree(x) {
g = random(175, 240); //height starting point
h = random(105, 160); // length of tree
//trunk
fill("brown");
rect(x, g, 46, h);
//leaves
fill("#83fa0c");
circle(x + 23, g, 100);
// add the apple function to the tree
for (i = 0; i < random(0, 10); i++) {
apple(x + 23 + random(-25, 25), g + random(-25, 25));
}
}
function picture() {
//background
background("#5db1f5");
fill("green");
noStroke();
rect(0, 280, 600, 280);
//all together
mountain(random(100, 500));
for (var x = 40; x < 517; x = x + 118) {
let r = random(0,100);
if (r > 40){
tree(x);
}
}
}