Last active
December 24, 2015 09:18
-
-
Save Informer/6775850 to your computer and use it in GitHub Desktop.
A simple Processing sketch that writes a string array to screen horizontally, with the font size of each element changing depending on the tweeted frequency of that element.
This file contains hidden or 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
// use textWidth(yourword)... this function returns how wide in px a word will be | |
/************** scripted by James Heffernan September 2013 *******************/ | |
// to experiment with this sketch in processing you will need to make your own version of the "ArialMT" font. | |
String[] words={"tree","bus","car","building","church","ground", | |
"landscape","roof","dog","cat","owl","pea","carrot","frog","hat","cloud","sky","grass","dawn","tree", | |
"sandwich","parrot","night","sun","moon","flower" | |
}; | |
int[] tweetV={2200,3000,1000,545,660,1000,1200,2000,2800,3200,650,800, | |
3200,1900,3000}; | |
int[] wordlength = new int [words.length]; | |
PFont font; | |
float fontSize; | |
float ratio; | |
float wordWidth = 0; | |
int lineNo = 0; | |
int maxV; | |
int xpos = 50; | |
int ypos; | |
int wordOnLine; | |
void setup(){ | |
background(255); | |
size(600,600); | |
fill(0); | |
smooth(); | |
font = loadFont("ArialMT-48.vlw"); | |
textFont(font,48); | |
textAlign(LEFT); | |
} | |
void draw(){ | |
maxV = max(tweetV); | |
for(int j = 0; j<tweetV.length; j++) | |
{ | |
// divide each tvalue[] by max for unique ratio | |
ratio = float(tweetV[j])/maxV; | |
wordlength[j] = int(textWidth(words[j])); | |
// if the width of the text exceeds 450 increment the line number | |
if(xpos > 450){ | |
lineNo = lineNo + 1; | |
xpos = 50; | |
//xpos = xpos + ((wordlength[j])+5); | |
} | |
// if the line number increments so does the yposition | |
if(lineNo == 0){ | |
ypos= 100; | |
} | |
if(lineNo == 1){ | |
ypos= 150; | |
} | |
if(lineNo == 2){ | |
ypos= 200; | |
} | |
if(lineNo == 3){ | |
ypos= 250; | |
} | |
//xpos = xpos + int(textWidth(words[j])+1); | |
text(words[j],xpos,ypos); | |
xpos = (xpos+40) + ((wordlength[j])); | |
textSize(ratio*56); | |
//50*(i+1) | |
} | |
// fill(255,0,0); | |
//text(wordlength[0],width/2,height/2); | |
noLoop(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment