/* Copyright (C) 2007 Andre Seidelt, All Rights Reserved. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ static final int NUM_WORDS = 6; ArrayList words = new ArrayList(); void setup() { size(300, 300, P3D); PFont f = loadFont("SegoePrint-Bold-64.vlw"); textFont(f); textAlign(CENTER); colorMode(HSB, 255); // create 6 words for(int i = 0; i < NUM_WORDS; i++) { words.add(new Word(generate())); } } synchronized void draw() { // clear screen and draw all words background(0); for(int i = 0; i < words.size(); i++) { ((Word) words.get(i)).paint(); } } // generate a random string. rules: // - always start with a consonant // - a consonant is always followed by a vowel // - two vowels are always followed by a consonant String generate() { int id = new Random().nextInt(Integer.MAX_VALUE); final char[] consonants = { 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z' }; final char[] vocals = { 'A', 'E', 'I', 'O', 'U' }; StringBuilder sb = new StringBuilder(); int numCon = 0; int numVoc = 2; while (id > 0) { if (numCon >= 1) { // generate vowel int ch = (id % vocals.length); id /= vocals.length; sb.append(vocals[ch]); numCon = 0; numVoc++; } else if (numVoc >= 2) { // generate consonant int ch = (id % consonants.length); id /= consonants.length; sb.append(consonants[ch]); numVoc = 0; numCon++; } else { // generate vocal or consonant int ch = (id % (vocals.length + consonants.length)); id /= vocals.length + consonants.length; if (ch < vocals.length) { // this shall be a vocal sb.append(vocals[ch]); numCon = 0; numVoc++; } else { // this shall be a consonant sb.append(consonants[ch - vocals.length]); numVoc = 0; numCon++; } } } return sb.toString(); }