xxxxxxxxxx
74
function setup() {
createCanvas(400, 400);
frameRate(100);
angleMode(DEGREES);
}
function draw() {
background(0);
captureMousePoints();
//drawLines();
drawRects();
}
let mousePoints = [];
function drawRects() {
for(let i=1; i<mousePoints.length; i=i+10) {
new RotatedRect(
mousePoints[i][0],
mousePoints[i][1],
25,
45
).draw();
}
//console.log(mousePoints.length);
//let tamanho = mousePoints.length;
// new RotatedRect( mousePoints[tamanho-1][0],
// mousePoints[tamanho-1][1],
// 25,
// 45).draw();
}
class RotatedRect {
constructor(x,y,len,rot) {
this.x = x;
this.y = y;
this.len = len;
this.rot = rot;
}
draw() {
let x1 = 0 - this.len/2;
let y1 = 0 - this.len/2;
push();
translate(this.x, this.y);
rotate(this.rot);
rect(x1,y1,this.len,this.len);
translate(-this.x, -this.y);
pop();
}
}
function captureMousePoints() {
mousePoints.push([mouseX, mouseY]);
if(mousePoints.length > 100) {
mousePoints.shift();
}
}
function drawLines() {
stroke(255);
strokeWeight(1);
for(let i=1; i<mousePoints.length; i++) {
line(mousePoints[i-1][0],mousePoints[i-1][1],
mousePoints[i][0],mousePoints[i][1])
}
}