Last active
July 27, 2016 11:25
-
-
Save vogelino/d62089af3ddf6c62653429ae0f8c15fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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