We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello Anyone reading this,
I have to loop the alphabet across the top of my canvas, so far I have got the alphabet to only go once... How do i get it too loop forever.
final int SPEED = 2;
char alphabet = 'Z';
char nextChar;
float chatX = 100;
int spacing;
void setup(){
size(500,500);
spacing = width/25;
}
void draw(){
background(200);
float nextChatX = chatX;
for( int i = 0; i < 26 ; i++){
nextChar = char(alphabet - i);
fill(0);
textSize(25);
text( nextChar , (nextChatX) - (spacing * i), 25);
}
if(chatX > 0)
chatX = (chatX + SPEED);
}
Answers
draw loops on and on
So add some x to text and increase x every time draw() runs
No that does not do it, the idea is that as soon as "A" appears a "Z" will be right behind it and this will continue until the program is closed
Modify N or modify the algorithm so to reset chatX in order to get truly infinite looping of characters.
Kf
This is a good solution. The main drawback with this approach is that the lack of kerning makes the text look awkward. For example, the W is wider than other letters, so it bangs up against them; the I is narrow, so it leaves a big gap.
Some different ways around that:
Each has its own advantages and drawbacks.
Here is an example of the string sliding method (as an alternative to the character-based method):
In fact this is just a single double-alphabet strip being slide back and forth like a typewriter carriage, but it creates an illusion of endless forward motion. To reveal the moment that it pops back, add an extra character here:
or just play it on a much shorter string: