problem with array - (newbie)
in
Programming Questions
•
3 years ago
Hi, this is my first project with Processing. Sorry if questions are very basic.
I have an array with all the letters of the alphabet. They show up on the stage one by one, randomly, in random positions on certain event (currently keypress).
Now, this is what I'm stuck with:
I need every new choice to be done on the letters left (no repetitions should occur before finishing the series). When the last letter is on stage, the whole process should restart with a fully available array and an empty screen.
As you may see in the code below, the function that should subtract the letter from its array is lacking. I've been trying with "subset", "shorten" and ArrayList... and got nothing inspiring. (I cleaned all failed code to avoid confusion).
Could you give me a clue?
Second question:
I felt little ridiculous while typing 27 times the same lines for a little variation (what if it were 2300 elements instead?). What could be another way to call a specific element from an array and apply it a function without typing the function for every element?
Many thanks in advance.
I have an array with all the letters of the alphabet. They show up on the stage one by one, randomly, in random positions on certain event (currently keypress).
Now, this is what I'm stuck with:
I need every new choice to be done on the letters left (no repetitions should occur before finishing the series). When the last letter is on stage, the whole process should restart with a fully available array and an empty screen.
As you may see in the code below, the function that should subtract the letter from its array is lacking. I've been trying with "subset", "shorten" and ArrayList... and got nothing inspiring. (I cleaned all failed code to avoid confusion).
Could you give me a clue?
Second question:
I felt little ridiculous while typing 27 times the same lines for a little variation (what if it were 2300 elements instead?). What could be another way to call a specific element from an array and apply it a function without typing the function for every element?
Many thanks in advance.
- PFont fuente;
char alfa[] = {
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','ñ','o','p','q','r','s','t','u','v','w','x','y','z'};
void setup(){
background (0);
size (screen.width,screen.height);
fuente =loadFont ("Avian-100.vlw");
textFont (fuente,100);
textAlign (CENTER,CENTER);
frameRate (7);
}
void draw (){
if (keyPressed == true) {
int index = int(random(alfa.length));
println (alfa[index]);
for (int i = 0; i < 1; i++){
if (index == 0){
text ('a',random(width) , random(height));
}
if (index == 1){
text ('b',random(width) , random(height));
}
if (index == 2){
text ('c',random(width) , random(height));
}
if (index == 3){
text ('d',random(width) , random(height));
}
if (index == 4){
text ('e',random(width) , random(height));
}
if (index == 5){
text ('f',random(width) , random(height));
}
if (index == 6){
text ('g',random(width) , random(height));
}
if (index == 7){
text ('h',random(width) , random(height));
}
if (index == 8){
text ('i',random(width) , random(height));
}
if (index == 9){
text ('j',random(width) , random(height));
}
if (index == 10){
text ('k',random(width) , random(height));
}
if (index == 11){
text ('l',random(width) , random(height));
}
if (index == 12){
text ('m',random(width) , random(height));
}
if (index == 13){
text ('n',random(width) , random(height));
}
if (index == 14){
text ('ñ',random(width) , random(height));
}
if (index == 15){
text ('o',random(width) , random(height));
}
if (index == 16){
text ('p',random(width) , random(height));
}
if (index == 17){
text ('q',random(width) , random(height));
}
if (index == 18){
text ('r',random(width) , random(height));
}
if (index == 19){
text ('s',random(width) , random(height));
}
if (index == 20){
text ('t',random(width) , random(height));
}
if (index == 21){
text ('u',random(width) , random(height));
}
if (index == 22){
text ('v',random(width) , random(height));
}
if (index == 23){
text ('w',random(width) , random(height));
}
if (index == 24){
text ('x',random(width) , random(height));
}
if (index == 25){
text ('y',random(width) , random(height));
}
if (index == 26){
text ('z',random(width) , random(height));
}
}
}
}
1