xxxxxxxxxx
150
var fruits = ["Apple", "Banana", "grapes", "cherries", "watermelon"];
var pic =[];
var pos = 0;
var sizeOfGrape = 40;
function preload(){
pic[0] = loadImage('kiwi.png');
pic[1] = loadImage('starw.png');
pic[2] = loadImage('lemon.png');
}
function setup() {
createCanvas(500, 500);
background(245, 228, 231);
textSize(20);
text("welcome to fruit factory >.<", width/2-120, height/2);
}
function draw() {
if (frameCount%1000 == 0) {
//text("welcome to fruit factory >.<", width/2-120, height/2);
background(245, 228, 231);
}
if(mouseIsPressed){
randomnlyDrawing([drawApple, drawBanana, drawGrapes, drawCherries, drawCherries, drawWatermelon]);
}
if(keyIsPressed){
image(pic[0], random, 320, 100, 100 );
image(pic[1], 100, 320, 100, 100 );
}
}
function drawApple(){
strokeWeight(4);
fill(204, 55, 51);
ellipseMode(CENTER);
ellipse(250, 200, 200, 180);
stroke(78, 38, 0);
push();
strokeWeight(10);
line(250, 150, 260, 85);
pop();
push();
rotate(295);
fill(39, 166, 21);
ellipse(190, 186, 30, 70);
pop();
}
function drawBanana(){
//reference https://editor.p5js.org/mhf273/sketches/BJY2oi66W
fill(247, 223, 5);
beginShape();
translate(width/2-130, height/2-50);
scale(5);
vertex(0,0);
quadraticVertex(25,25, 50, 0);
//vertex(50, 0);
quadraticVertex(50 + 10, 10, 50, 20);
quadraticVertex(25, 40, 0, 20);
quadraticVertex(-10, 10, 0, 0);
endShape();
beginShape();
stroke(74, 66, 5);
strokeWeight(1);
vertex(5, 15);
quadraticVertex(30, 30, 50 -5, 15);
endShape();
rotate(10);
fill(74, 66, 5);
ellipse(0,-4,4,8);
}
function drawGrapes(){
noFill();
scale(2);
stroke(58, 13, 84);
strokeWeight(2);
arc(220, 40, 170, 70, PI, PI + QUARTER_PI);
fill(153, 62, 207);
push();
translate(width/2-200, height/2-190);
ellipse(30,30,sizeOfGrape,sizeOfGrape);
ellipse(60,35,sizeOfGrape,sizeOfGrape);
ellipse(85,50,sizeOfGrape,sizeOfGrape);
ellipse(115,50,sizeOfGrape,sizeOfGrape);
ellipse(130,60,sizeOfGrape,sizeOfGrape);
ellipse(140,80,sizeOfGrape,sizeOfGrape);
ellipse(105,70,sizeOfGrape,sizeOfGrape);
ellipse(66,80,sizeOfGrape,sizeOfGrape);
ellipse(50,60,sizeOfGrape,sizeOfGrape);
ellipse(25,65,sizeOfGrape,sizeOfGrape);
ellipse(35,97,sizeOfGrape,sizeOfGrape);
ellipse(95,97,sizeOfGrape,sizeOfGrape);
ellipse(130,100,sizeOfGrape,sizeOfGrape);
ellipse(90,130,sizeOfGrape,sizeOfGrape);
ellipse(60,110,sizeOfGrape,sizeOfGrape);
ellipse(120,125,sizeOfGrape,sizeOfGrape);
ellipse(90,155,sizeOfGrape,sizeOfGrape);
ellipse(70,140,sizeOfGrape,sizeOfGrape);
ellipse(45,130,sizeOfGrape,sizeOfGrape);
ellipse(60,165,sizeOfGrape,sizeOfGrape);
pop();
}
function drawCherries(){
push();
noFill();
scale(3);
// stroke(58, 13, 84);
strokeWeight(2);
arc(140, 70, 170, 170, PI, PI + QUARTER_PI);
translate(5,30);
rotate(75);
arc(140, 70, 170, 170, PI, PI + QUARTER_PI);
pop();
strokeWeight(2);
fill(201, 36, 36);
ellipse(150,220,155,150);
ellipse(290,220,155,150);
}
function drawWatermelon(){
translate(width/2-400, height/2-450);
scale(2);
fill(16, 131, 41);
arc(200, 150, 300, 300, 1, PI - 1, PIE);
fill(226, 255, 198);
arc(200, 150, 290, 290, 1, PI - 1, PIE);
fill(251, 30, 63);
arc(200, 150, 255, 255, 1, PI - 1, PIE);
fill(0);
ellipse(170, 230, 5, 10);
ellipse(230, 220, 5, 10);
ellipse(190, 190, 5, 10);
ellipse(210, 200, 5, 10);
ellipse(200, 240, 5, 10);
}
function randomnlyDrawing(funcs){
push();
let choice = floor(random(0, funcs.length));
translate(random(width), random(height));
scale(random(-1));
rotate(random(PI * 2));
funcs[choice]();
pop();
}