xxxxxxxxxx
75
let myStr = 'issa string '
let charlist = [];
function setup() {
angleMode(DEGREES);
createCanvas(600, 600);
textFont("Courier New", 25);
const centerX = width/2;
const centerY = height/2;
const radius = 80;
for(let i=0; i < myStr.length; i++){
angle = 360/myStr.length * i;
let dx = cos(angle) * radius;
let dy = sin(angle) * radius;
charlist.push(new MovingChar(myStr.charAt(i),dx+centerX, dy+centerY))
}
}
function mouseClicked(){
for(let i=0; i < charlist.length; i++){
charlist[i].updateMovement();
}
}
function draw() {
background(220);
for(let i=0; i < charlist.length; i++){
charlist[i].run();
}
}
class MovingChar{
constructor(_chr, _posX, _posY){
this.chr = _chr;
this.initposX = _posX;
this.initposY = _posY;
this.posX = _posX;
this.posY = _posY;
this.dx = 0;
this.dy = 0;
}
draw(){
text(this.chr, this.posX, this.posY);
}
update(){
this.checkCollision();
this.dx *= 0.98;
this.dy *= 0.98;
this.posX += this.dx;
this.posY += this.dy;
}
run(){
this.draw();
this.update();
}
gohome(){
}
updateMovement(){
this.dx = random(-10,10);
this.dy = random(-10,10);
}
checkCollision(){
if(this.posX > width-textWidth(this.chr)){
this.posX -= width;
}
if(this.posX<textWidth(this.chr)){
this.posX = width+this.posX
}
if(this.posY > height-textWidth(this.chr)){
this.posY -= height;
}
if(this.posY < textWidth(this.chr)){
this.posY += height;
}
}
}