// Ethan Miller 2005 http://dma.sjsu.edu/~emiller ... ethanton1 - yahoo - com // using nanoXML library by cyberElf (http://nanoxml.sourceforge.net/orig/) // and help from Toxi's nanoxml example (http://www.toxi.co.uk/p5/nanoxmltest/xml_test.pde) int drop_rate = 50; // how many loops before dropping a new text int drop_counter = 0; int sz = 10; //cell size int top_banner_sz = 68; int most_connections = 1; //reference for the greatest number of connections between any two cells --- see global_prop() int most_between2 = 1; //greatest number of connections between any two texts - used for line brightness int[] dist_maxmin = {20, 250}; int txt_selected = -1; int txt_hover = -1; XMLElement xml; ArrayList xml_text; ArrayList noise_words; ArrayList txt_cells; //------------------------------ end global vars ---------------------------- void setup() { size(500, 500 + top_banner_sz); PFont myFont; myFont = loadFont("Crisp-12.vlw"); textFont(myFont); ellipseMode(CENTER_RADIUS); // load & parse noise_words noise_words = new ArrayList(); String[] a_noise = loadStrings("noise_words.txt"); String[] spl; for(int i = 0; i< a_noise.length; i++){ spl = split(a_noise[i], ','); for(int ii = 0; ii < spl.length; ii++){ noise_words.add(spl[ii].trim()); } } initialize(); } // ----------------------------- initialization -------------------------------- void initialize(){ // load & parse XML xml = new XMLElement(); String xmlString = ""; String[] lines = loadStrings("source.xml"); for(int i = 0; i < lines.length; i++) xmlString += lines[i]; xml.parseString(xmlString); // retrieve all childnodes and store them in an arraylist xml_text = new ArrayList(xml.getChildren()); //for(int i = 0; i < xml_text.size(); i++){ // println(xml_text.get(i)); //} txt_cells = new ArrayList(); drop_counter = 0; most_connections = 1; } // ----------------------------- mouse clicked ----------------------------- void mouseReleased(){ for (int i = 0; i < txt_cells.size(); i++){ txt tc = (txt)txt_cells.get(i); if(tc.mouseOn()){ tc.selected = true; txt_selected = i; return; } } txt_selected = -1; } // ----------------------------- Key press ---------------------------------------- void keyPressed(){ if(key == 'r') println("selected : " + txt_selected + " hovered : " + txt_hover); //initialize(); } // ----------------------------- main loop --------------------------------------------- void draw(){ background(22,31,15); fill(0); rect(0,0, width, top_banner_sz); stroke(34, 47, 23); line(0, (height - top_banner_sz)/2 + top_banner_sz, width, (height - top_banner_sz)/2 + top_banner_sz); line(width/2, top_banner_sz, width/2, height); drop_counter %= drop_rate; if(drop_counter == 0 && xml_text.size() > 0){ float x = random(width); float y = random(top_banner_sz, height); int indx = txt_cells.size(); txt_cells.add(new txt( x, y, sz, xml_text.get(0), indx)); xml_text.remove(0); } drop_counter += 1; for (int i = 0; i < txt_cells.size(); i++){ txt tc = (txt)txt_cells.get(i); tc.render(0); } boolean hovering = false; for (int i = 0; i < txt_cells.size(); i++){ txt tc = (txt)txt_cells.get(i); tc.render(1); if(tc.hover) hovering = true; } if(!hovering) txt_hover = -1; // title of selected / hovered texts at top of applet String t = ""; if(txt_selected >= 0){ txt tc = (txt)txt_cells.get(txt_selected); t = tc.title; } if(txt_hover >= 0 && txt_hover != txt_selected){ txt tc = (txt)txt_cells.get(txt_hover); if(t.length() > 0) t += "\nand\n" + tc.title; else t = tc.title; } if(t.length() > 0){ fill(200); text(t, 5,18); } } // ----------------------------- get appropriate distance from center based on # of links ------------------------------- float global_prop(int connections){ if(connections > most_connections){ most_connections = connections;} // cells with the most connections are closest... twice the size of a cell // (distance) y1, y2 = (10, 250) ... (connections) x1, x2 = ([max], 0) float slope = (dist_maxmin[1]*1.0 - dist_maxmin[0]*1.0)/most_connections*-1.0; //b is a y minus slope * an x return (slope*connections*1.0) + dist_maxmin[1]*1.0; }