// rss feed String url = "http://www.independent.co.uk/news/uk/rss"; //xml arrays XMLElement xml; XMLElement[] title; XMLElement[] pubDate; XMLElement[] value; PFont font; PImage img; String fontFile = "Georgia-48.vlw"; int fSize =96; int maxSize = 50; int minSize = 15; String[] words; int[] count; int most; int least; float currentSize; int currentIndex; void setup(){ //background(255); XMLElement rss = new XMLElement(this, url); title = rss.getChildren("channel/item/title"); pubDate = rss.getChildren("channel/item/pubDate"); value = rss.getChildren("channel/item/description"); size(330, 500); colorMode(HSB, TWO_PI, 1, 1, 1); rectMode(CORNER); //background(color(PI/6,0.94,0.86)); smooth(); font = loadFont(fontFile); initializeWords(); noLoop(); } void draw() { while(currentIndex < words.length) { float relsize = map(count[currentIndex],least,most,minSize,maxSize); boolean drawn = false; while (!drawn) { drawn = drawWord(words[currentIndex], relsize); if (!drawn) println("redrawing "+words[currentIndex]); relsize = relsize * 0.95; } currentIndex++; } } boolean drawWord(String word, float wordSize) { int intSize = (int)wordSize; textFont(font, wordSize); int w = int(textWidth(word)); PGraphics g = createGraphics(w, intSize, JAVA2D); g.beginDraw(); g.fill(color(0,0,99)); g.textAlign(CENTER,CENTER); g.translate(w/2, wordSize/2); g.scale(wordSize / fSize*2); g.textFont(font); g.text(word, 0, 0); g.endDraw(); PGraphics gMask = createGraphics(w, intSize, P2D); gMask.beginDraw(); gMask.background(color(0,99,0)); gMask.image(g, 0, 0); gMask.filter(ERODE); gMask.filter(ERODE); gMask.endDraw(); for (int tries=50; tries>0; tries--) { int x = (int)random(width-w); int y = (int)random(height-intSize); boolean fits = true; for (int dx = 0; dx