void setup() { size(600, 600); fill(0); // 1. populate an array with random characters int num = 10; char[] chars = populate(num); // 2. render characters renderChars(chars); // 3. get a reversed string String rev = combine(chars); renderString(rev); // 4. shuffle initial array char[] rchars = randomise(chars); renderChars2(rchars); save("assignment7.png"); } char[] populate(int num) { char[] chars = new char[num]; for(int i=0; i < num; i++) { char c = (char)random(97,122); chars[i] = c; print(c); } return chars; } void renderChars(char[] chars) { fill(0); textSize(16); text("1. Rendering " + chars.length + " random characters: ", 20, 70); for(int i=0; i < chars.length; i++) { text(chars[i], 20 + (i*10), 100); } } String combine(char[] chars) { String s = ""; for(int i=chars.length - 1; i >= 0; i--) { s += chars[i] + " "; } return s; } void renderString(String s) { fill(0); textSize(16); text("2. Rendering reversed string: ", 20, 140); text(s, 20 , 170); } char[] randomise(char[] chars) { char[] rchars = new char[chars.length]; for(int i=0; i < chars.length; i++) { int j = (int)random(0, chars.length); char c = rchars[j]; while(c != '\u0000') { j = (int)random(0, chars.length); c = rchars[j]; } rchars[j] = chars[i]; } return rchars; } void renderChars2(char[] chars) { fill(0); textSize(16); text("3. Rendering with random order: ", 20, 210); for(int i=0; i < chars.length; i++) { text(chars[i], 20 + (i*10), 240); } }