Spacing out an array of randomly generated symbols
in
Programming Questions
•
3 months ago
I am trying to write a program that picks a symbol from a set randomly and prints in out onto the display, then repeats the process while moving the new symbol over about 20 pixels (eventually hopping to the next line after the horizontal line has filled with symbols and stopping at the end of the display -- keeping all on the screen.) I have gotten thus far (see below) in my program, but am having some major issues:
- The symbols seem to be running through the list and not randomly generating.
- The symbols are printing one on top of the previous.
Any help is greatly appreciated. Thank you.
PFont f;
char[] symbols = {
'?', '⅕', '*', '%', '#', '&', '☺', '❤', '❑', '⇧', '↮', '▦', '░', '▒',
'▓', '▂', '▨', '⟡'
};
void setup() {
size(800, 300);
background(255);
smooth();
strokeWeight(5);
translate(width/2, height/2);
f = createFont("FreeSans.ttf", 32, true);
fill(255);
}
void draw() {
int x = 10;
int index = int(random(symbols.length));
for(int i = 0; i < symbols[index].length(); i++) {
textFont(f, 50);
fill(0);
text(symbols[index].chatAt(i), x, height/2);
x += 50;
}
}
1