xxxxxxxxxx
58
var pos, acc, head;
var tex = 'henlo';
var limit = tex.length;
var spot = 0;
var post = [];
var content = '';
var c = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
acc = createVector(random(5),random(5));
pos = createVector(random(width),random(height));
head = createElement('h1','');
}
function draw() {
background(255);
scroller();
c++;
}
function bounds() {
if (pos.x > width || pos.x <0) {
acc.x *= -1;
}
if (pos.y > height || pos.y < 0) {
acc.y *= -1;
}
}
function scroller() {
if (c % 10 == 0 && spot < limit) {
for (let i = 0; i <= spot; i++) {
post.push(tex[i]);
}
spot++;
content = join(post,'');
head.html(content);
post = [];
} else if ((c % 10 == 0 && spot >= limit) && spot < (limit-1)*2) {
for (let i = 0; i <= spot-limit; i++) {
post.push(tex[limit-1-i]);
}
spot++
content = join(post,'');
head.html(content);
post = [];
} else if (spot > (limit-1)*2) {
spot = 0;
head.html(content);
post = [];
}
pos.add(acc);
head.position(pos.x,pos.y);
bounds();
}