xxxxxxxxxx
46
function setup() {
createCanvas(window.innerWidth, window.innerHeight);
}
function draw() {
background("black");
let anchorX = 80;
let anchorY = 80;
let length = mouseX - anchorX;
let breadth = mouseY - anchorY;
stroke("white");
fill(0, 224, 208, 100);
rect(anchorX, anchorY, length, breadth);
fill(255, 49, 99, 100);
ellipse(anchorX + length / 2, anchorY + breadth / 2, length, breadth);
fill(0, 149, 237, 100);
let tri_x1 = anchorX + length / 2;
let tri_y1 = anchorY;
let tri_x2 = anchorX + length;
let tri_y2 = anchorY + breadth;
let tri_x3 = anchorX;
let tri_y3 = anchorY + breadth;
triangle(tri_x1, tri_y1, tri_x2, tri_y2, tri_x3, tri_y3);
let area_rect = Math.abs(length * breadth);
let area_ellipse = Math.abs(PI * (length / 2) * (breadth / 2));
let area_triangle = 0.5 * area_rect;
textSize(16);
noStroke();
fill("white");
text("Area of Rectangle : " + area_rect + " sq pixels", 400, 120);
text("Area of Ellipse : " + round(area_ellipse, 2) + " sq pixels", 400, 150);
text(
"Area of Triangle : " + round(area_triangle, 2) + " sq pixels",
400,
180
);
}