xxxxxxxxxx
63
let cx, cy;
//size of rectangle
let rectWidth = 200;
let rectHeight = 200;
//movement veriable
let xMove = 0;
let yMove = 0;
function setup() {
createCanvas(400, 400);
//center coordinates
cx = width / 2 + xMove;
cy = height / 2 + yMove;
}
function draw() {
background(220);
//Top left
//center - width/2 = starting x coordinate
//center + height/2 = starting y coordinate
line(
cx - rectWidth / 2,
cy - rectHeight / 2,
cx + rectWidth / 2,
cy - rectHeight / 2
);
//Top Right
line(
cx + rectWidth / 2,
cy - rectHeight / 2,
cx + rectWidth / 2,
cy + rectHeight / 2
);
//Bottom Right
line(
cx + rectWidth / 2,
cy + rectHeight / 2,
cx - rectWidth / 2,
cy + rectHeight / 2
);
//Bottom left
line(
cx - rectWidth / 2,
cy + rectHeight / 2,
cx - rectWidth / 2,
cy - rectHeight / 2
);
// //line (x1, y1, x2, y2)
// line(width/4,height/4,width*3/4,height/4);
// //line (x2,y2, x3,y3)
// line(width*3/4,height/4,width*3/4,height*3/4);
// // line (x3, y3, x4, y4)
// line(width*3/4,height*3/4,width/4,height*3/4);
// // line (x4, y4, x1,y1)
// line(width/4,height*3/4,width/4,height/4);
}