xxxxxxxxxx
33
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
const degree1 = 0;
const degree2 = 45;
const distance1 = 100;
const distance2 = 144;
const center = new p5.Vector(width/2, height/2);
const point1 = p5.Vector.fromAngle(radians(degree1)).mult(distance1).add(center);
const point2 = p5.Vector.fromAngle(radians(degree1)).mult(distance2).add(center);
const point3 = p5.Vector.fromAngle(radians(degree2)).mult(distance2).add(center);
const point4 = p5.Vector.fromAngle(radians(degree2)).mult(distance1).add(center);
// draw the lines
stroke('black');
line(center.x, center.y, point2.x, point2.y);
line(center.x, center.y, point3.x, point3.y);
// draw the rectangle
fill('hotpink');
beginShape();
vertex(point1.x, point1.y);
vertex(point2.x, point2.y);
vertex(point3.x, point3.y);
vertex(point4.x, point4.y);
endShape(CLOSE);
}