You shouldn't do variable manipulation outside of a function in Processing. Before setup()
, you should declare your variables, but you give them values in setup()
. See here (under "Reading and Writing Text Files") for an example of this. Here is what you should do with your code:
String[] lines;
int[] freq;
void setup(){
size(600,600);
background(255);
lines = loadStrings("brown.txt");//the array with the words
if(lines == null){
print("error loading strings!");
}
String longString = join(lines, " "); //joining the array to a normal string of words
int characters = longString.length(); //used to find the amount of all the letters
String lowercase = longString.toLowerCase();//makes sure all the letters are lowercased
//setting up the letter frequency finder
char[] c = lowercase.toCharArray(); //used to make a character array
freq = new int[26];
for(int i = 0; i < c.length; i++){
//chars are really just numbers and a-z is consecutive, so 'a' - 'a' = 0, 'b' - 'a' = 1, 'c' - 'a' = 2...
// note that you can also check to see if a character is between a-z by doing if(chr >= 'a' && chr <= 'z'){}
freq[c[i] - 'a']++;
}
}
void draw() {}