xxxxxxxxxx
56
let fruits = []; // declaring an array
let img;
function setup() {
createCanvas(windowWidth, windowHeight);
img = loadImage("cherry.png")
fruits[0] = random(windowWidth); // adding values to an array
fruits[1] = 160;
fruits[2] = "mango";
fruits[3] = "🍓";
fruits[4] = loadImage("grapefruit.png");
}
function draw() {
background(255, 234, 230);
image(img, width/2, height/2, 100, 100);
noStroke();
fill(255,0,0);
textSize(24);
/* using information saved in our array throughout the sketch */
text(fruits[2], mouseX, mouseY);
for (let x = 0; x < 100; x++) {
text(fruits[3], x * 40, 60);
}
tomato(fruits[0], fruits[1]); // calling the fruits function
image(fruits[4], width/4, 400, 200, 200);
}
function tomato(x, y) {
fill(255, 66, 33);
noStroke();
ellipse(x, y, 100, 90);
let leafY = y - 20;
fill(34, 139, 34);
triangle(x-20, leafY + 15, x-15, leafY, x, leafY + 5);
triangle(x+25, leafY + 15, x+20, leafY, x, leafY + 5);
triangle(x-20, leafY - 15, x-15, leafY, x, leafY - 5);
triangle(x+25, leafY - 15, x+20, leafY, x, leafY - 5);
ellipse(x + 3, leafY, 35, 10);
stroke(15, 112, 10);
strokeWeight(6);
line(x, leafY, x, leafY-10);
}