xxxxxxxxxx
49
let px, py;
let txt = 'hello this is kaspar'
let counter = 0;
function setup() {
createCanvas(400, 400);
fill(0);
noStroke();
rectMode(CENTER);
px = mouseX; // initializing the previous shape position
py = mouseY;
}
function draw() {
if(mouseIsPressed) { // is the mouse pressed
// calculating the distance between the mouse and the previous shape
let distance = dist(px,py,mouseX, mouseY);
if(distance > 10){ // checking if that distance is big enough
// calculating the distance between the mouse and the previous mouse
let distance2 = dist(pmouseX,pmouseY,mouseX, mouseY);
// drawing a square
let size = distance2/3;
//rect(mouseX, mouseY, size, size);
textSize(size*5);
angleMode(DEGREES);
let angle = atan2(mouseY - pmouseY, mouseX - pmouseX);
push();
translate(mouseX, mouseY)
rotate(angle);
text(txt[counter], 0, 0);
pop();
counter = counter + 1;
if(counter == txt.length){
counter = 0;
}
px = mouseX; // update previous shape position
py = mouseY;
}
}
}