Project 5

I really enjoyed making the avocado’s in the project and it reminded me of breakfast!

sketch
//Aadya Bhartia
//Section A

function setup() {
    createCanvas(600, 400);
    background(256,156,155);
    //text("p5.js vers 0.9.0 test.", 10, 15);
}

function draw() {
	var aX = 70;
	var bX = 60;
	var aY = 90;
	var bY = 60;

	for(var y =18;y<=height+20;y+=80){
		if(y == 18||y==178||y == 338){//checking for even rows 
			for(var x = 50;x<=width;x+=100){
				avo1(x,y);
			}
		}
		else{
			for(var x = 0;x<=width;x+=100){
				avo2(x,y)
			}
		}
	}
	noLoop();
}
function avo1(a,b){
	b = b+2;
	//avocado shadow 
	noStroke();
	fill(25, 68, 35, 170);
	var a1 = a+10;
	beginShape();
	curveVertex(a1,b-65);
	curveVertex(a1-10,b-63);
	curveVertex(a1-19,b-52);
	curveVertex(a1-21,b-30);
	curveVertex(a1-30,b+12);
	curveVertex(a1,b+32);
	curveVertex(a1+30,b+12);
	curveVertex(a1+21,b-30);
	curveVertex(a1+19,b-52);
	curveVertex(a1+10,b-63);
	endShape(CLOSE);
	//the green part of avocado
	stroke(25,68,35);
	strokeWeight(2);
	fill(240,255,196);
	beginShape();
	curveVertex(a,b-65);
	curveVertex(a-10,b-63);
	curveVertex(a-19,b-52);
	curveVertex(a-21,b-30);
	curveVertex(a-30,b+12);
	curveVertex(a,b+32);
	curveVertex(a+30,b+12);
	curveVertex(a+21,b-30);
	curveVertex(a+19,b-52);
	curveVertex(a+10,b-63);
	endShape(CLOSE);
	//seed
	fill(163, 107, 67);
	stroke(69,48,25);
	strokeWeight(1);
	ellipse(a,b+2,35);
	//seed highlight
	noFill();
	stroke(69,48,25);
	strokeWeight(3.5);
	arc(a+2, b+2, 20, 20, 0, HALF_PI);
}
function avo2(a,b){
	//avocado shadow - whole
	var a2 = a-6;
	noStroke();
	fill(25, 68, 35,100);
	beginShape();
	curveVertex(a2,b-50);
	curveVertex(a2-4,b-49);
	curveVertex(a2-9,b-42);
	curveVertex(a2-11,b-25);
	curveVertex(a2-18,b+5);
	curveVertex(a2,b+19);
	curveVertex(a2+18,b+5);
	curveVertex(a2+11,b-25);
	curveVertex(a2+9,b-42);
	curveVertex(a2+4,b-49);
	endShape(CLOSE);
	//Avocado as a whole 
	stroke(25,68,35);
	strokeWeight(2);
	fill(25, 68, 35);
	beginShape();
	curveVertex(a,b-50);
	curveVertex(a-4,b-49);
	curveVertex(a-9,b-42);
	curveVertex(a-11,b-25);
	curveVertex(a-18,b+5);
	curveVertex(a,b+19);
	curveVertex(a+18,b+5);
	curveVertex(a+11,b-25);
	curveVertex(a+9,b-42);
	curveVertex(a+4,b-49);
	endShape(CLOSE);
	//white specks on the avocado 
	noStroke();
	fill(255,255,255,50);
	for(var d = a-15;d<=a+20;d+=2){
		ellipse(d,random((b-30), b+30),2);
	}
}

Leave a Reply