Skip to content

Instantly share code, notes, and snippets.

@vogelino
Last active July 27, 2016 11:25
Show Gist options
  • Save vogelino/d62089af3ddf6c62653429ae0f8c15fa to your computer and use it in GitHub Desktop.
Save vogelino/d62089af3ddf6c62653429ae0f8c15fa to your computer and use it in GitHub Desktop.
var actualCharacterIndex = -1;
var alphabet = 'abcdefghijklmnopqrstuvwxyz!?1234567890 ';
var word = window.prompt('Please a word or sentence you think is funny',
'badibaduba');
function setup() {
colorMode(HSB, alphabet.length, word.length, 1, 1);
createCanvas(windowWidth, windowHeight);
}
function draw() {
var endOfWordReached = word.length - 1 === actualCharacterIndex;
actualCharacterIndex = !endOfWordReached ? actualCharacterIndex + 1 : -1;
var character = getCharacterByIndex(word, actualCharacterIndex);
colorize(character);
}
function getCharacterByIndex(string, index) {
return string.split('')[index];
}
function colorize(character) {
var positionInAlphabet = alphabet.indexOf(character);
background(positionInAlphabet, actualCharacterIndex, 1, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment