Hey everyone,
my problem is that I cannot figure out how to loop text.
In other words: If the text string leaves the canvas to the left side I want it to enter the canvas on the right side.
My approach is to set the text’s x variable to the starting point when its value is passing beneath the width of the canvas using an if loop.
Another way could be adding the text’s size to the xposition.
Maybe something like that:
if(xspeed+decrease < speed-textwidth) { decrease = decrease + textWidth; }
Is there a function for getting the width of a text?
If somebody could help I would be very thankful! Here’s the code:
var cooper;
function preload()
{
cooper = loadFont('data/CooperHewitt-Bold.otf');
}
function setup()
{
createCanvas(1500,900);
textFont(cooper);
textSize(300);
}
function draw() {
textAlign(CENTER,TOP);
background(0);
var FontSize = 100;
var lineHeight = FontSize ;
var xspeed1 =1900;
var xspeed2 =1800;
var xspeed3 =2000;
var decrease = -millis()*0.5;
fill('#FFFFFF');
text('SOCIETY SOCIETY SOCIETY', xspeed1+decrease, 0);
fill('#2502C9');
text('ARTIFICIAL INTELLIGENCE', xspeed2+decrease, 300 );
fill('#FFFFFF');
text('TECHNOLOGY TECHNOLOGY ', xspeed3+decrease, 600 );
}