import com.gravitymonkey.deliciousclassifier.*; import processing.opengl.*; PFont pfont; PFont psmall; DeliciousClassifier delc; float xmag, ymag = 0; float newXmag, newYmag = 0; int popsel = 0; boolean clear; int offsetZ = -20; String currentURL; boolean changeNow; boolean showText; String cpcontent; String[] cpcontentArray; int counter; String bestMatch; double totalMatch = 0.0; int totalMatchCounter = 0; void setup(){ String uname = param("username"); String sourceSite = param("site"); String loadIt = param("loadRemote"); boolean loadRemote = false; showText = false; if (uname == null){ uname = "gravitymonkey"; } if (loadIt != null){ if (loadIt.equals("yes")){ loadRemote = true; } else { loadRemote = false; } } delc = new DeliciousClassifier(uname, loadRemote, sourceSite); if (online){ delc.ONLINE = true; } size(640,480, P3D); clear = false; bestMatch = null; pfont = loadFont("trebuchet.vlw"); psmall = loadFont("Silkscreen-8.vlw"); framerate(10); // loop(); background(255,255,255); } void draw(){ background(25,0,50); lights(); noStroke(); fill(100,100,100,80); rect(0,460,width,20); fill(255,255,255,180); textFont(psmall, 8); String[] popstrings = delc.getPopularList(); String mstatus = ""; if (popstrings != null){ if (popstrings.length > 0){ mstatus = popstrings[popsel]; if (currentURL != null){ if (currentURL.equals(mstatus)){ changeNow = false; } else { currentURL = mstatus; changeNow = true; } if (cpcontent != null){ if (!cpcontent.equals(delc.getCurrentPageContent())){ if (cpcontent != null){ cpcontent = delc.getCurrentPageContent(); cpcontentArray = cpcontent.split(" "); bestMatch = null; } } } else { if (!clear){ cpcontent = delc.getCurrentPageContent(); if (cpcontent != null){ cpcontentArray = cpcontent.split(" "); } } } } else { currentURL = mstatus; } } } else { mstatus = delc.getStatus(); } if (popstrings != null){ if (mouseX > 0 && mouseX < 100 && mouseY > 459 && mouseY < height && !delc.loadingTestPage){ fill(100,100,100,80); rect(0,459,95,20); fill(255,255,255,180); } else if (mouseX > 598 && mouseX < width && mouseY > 458 && mouseY < height && !delc.loadingTestPage){ fill(100,100,100,80); rect(598,459,95,20); fill(255,255,255,180); } else if (mouseX > 558 && mouseX < 599 && mouseY > 458 && mouseY < height && !delc.loadingTestPage){ fill(100,100,100,80); rect(558,459,40,20); fill(255,255,255,180); } if (!delc.loadingTestPage){ text("click here to load", 2, 470); text("clear", 600,470); text("toggle", 560, 470); } } boolean addel = false; if (mstatus != null){ while (textWidth(mstatus) > 480){ mstatus = mstatus.substring(0,mstatus.length() - 1); addel = true; } } if (addel) mstatus = mstatus + "..."; if (mstatus != null && !delc.loadingTestPage){ text(mstatus, 100, 470); } if (!clear){ String nurl = delc.getCurrentPageURL(); fill(255,255,255, 180); if (delc.loadingTestPage){ StringBuffer sbl = new StringBuffer(); sbl.append("loading"); for (int r = 0; r < counter % 50; r++){ sbl.append("."); } text(sbl.toString(), 2, 20); } else { if (nurl != null){ nurl = "showing " + delc.getUsername() + "'s tags-n-terms over " + nurl; boolean fine = true; while (textWidth(nurl) > (width - 10)){ nurl = nurl.substring(0, nurl.length() - 1); fine = false; } if (!fine) nurl = nurl + "..."; text(nurl, 2, 20); } if (bestMatch != null && nurl != null){ text("relevant tag(s): " + bestMatch, 2, 30); text("overall rating: " + totalMatch/totalMatchCounter, 2, 40); } } } translate(width/8, height/5 - 50, offsetZ); newXmag = mouseX/(float)(width*4) * TWO_PI; newYmag = (height - mouseY)/(float)(height*4) * TWO_PI; float diff = xmag-newXmag; if (abs(diff) > 0.01) { xmag -= diff/4.0; } diff = ymag-newYmag; if (abs(diff) > 0.01) { ymag -= diff/4.0; } rotateX(-ymag); rotateY(-xmag); double bestMatchD = 0.0; totalMatch = 0.0; totalMatchCounter = 0; Hashtable currentPageRankings = null; String[] tags = delc.getTags(); if (tags != null){ textFont(pfont, 20); int startX = 10; int maxX = 480; int rowCounter = 0; int maxZ = 0; // println("i have " + tags.length + " tags"); currentPageRankings = delc.getCurrentPageContentRankings(); String sourceWord = null; boolean showedSourceWord = false; if (cpcontentArray != null){ if (cpcontentArray.length > 0){ sourceWord = cpcontentArray[counter % cpcontentArray.length]; } } for (int w = 0; w < tags.length; w++){ String myTag = tags[w].trim(); // println(myTag); //ok, so we have a tag now, does it have terms? String[] terms = delc.getTerms(myTag); int zval = delc.getNumPagesPerTag(myTag); double dx = 0.0; if (terms == null){ fill(100,100,100,100); } else { int malpha = 255; if (currentPageRankings != null && !clear){ Object od = currentPageRankings.get(myTag); if (od != null){ dx = ((Double)od).doubleValue(); totalMatch = totalMatch + dx; totalMatchCounter++; if (dx > bestMatchD){ // bestMatch = myTag; bestMatchD = dx; } malpha = (int)(malpha * dx); zval = (int)(25 * dx); } } fill(200,200,200,malpha); } if ((zval * -10) < offsetZ){ offsetZ = zval * -10; // println(offsetZ); } text(myTag + " ", startX, (rowCounter + 2) * 20, (zval * 20)); if (dx > 0.0){ textFont(pfont, 8); String ttx = "" + dx; if (ttx.length() > 5){ ttx = ttx.substring(0,5); } text(ttx, startX, (rowCounter + 2) * 20 + 10, (zval * 20)); textFont(pfont, 20); } if ((zval * 20) > maxZ){ maxZ = zval * 20; } String[] currentTerms = delc.getCurrentPageTerms(); if (terms != null){ for (int q = 0; q < terms.length; q++){ if (showText){ fill(50,50,50, 100); } else { fill(255, random(50,150), random(50,150), 10); } String myTerm = terms[q].trim(); if (currentTerms != null && !clear){ for (int r = 0; r < currentTerms.length; r++){ if (currentTerms[r].equals(myTerm)){ if (showText){ fill(50,50,200,100); } else { fill(50,50,200,10); } } if (sourceWord != null){ if (!showedSourceWord && sourceWord.equals(myTerm)){ fill(200,100,100,200); text(myTerm, startX, (rowCounter + 2) * 20, (zval * 20) - (10 * (q + 1))); showedSourceWord = true; } } } } //each word if (showText || showedSourceWord){ text(myTerm, startX, (rowCounter + 2) * 20, (zval * 20) - (10 * (q + 1))); showedSourceWord = false; } else { pushMatrix(); translate(startX + (textWidth(myTag)/2), (rowCounter + 2) * 20, (zval * 20) - (10 * (q + 1))); box(textWidth(myTag),20,20); popMatrix(); } } } //increment the drawing for the tags startX = startX + (int)textWidth(myTag + " "); if (startX > maxX){ startX = 10; rowCounter++; } } if (!showedSourceWord){ if (sourceWord != null && !clear && !delc.loadingTestPage){ textFont(pfont, 50); fill(200,100,100,100); text(sourceWord, (maxX - startX)/2,((rowCounter + 2) * 20)/2, maxZ); } } // println("bestMatch " + bestMatch + " at " + bestMatchD); } if (currentPageRankings != null){ for (int w = 0; w < tags.length; w++){ String myTag = tags[w].trim(); if (bestMatch == null) bestMatch = ""; Object od = currentPageRankings.get(myTag); if (od != null){ double tdx = ((Double)od).doubleValue(); // println("currentpage rankings for " + myTag + " " + tdx + " versus " + bestMatchD); if (bestMatchD == tdx){ bestMatch = myTag + " "; } } } if (bestMatch.equals("")){ bestMatch = null; } else { bestMatch = bestMatch + " (" + bestMatchD + ")"; } } if(keyPressed) { if (key == 's' || key == 'S'){ showText = !showText; } } if (mousePressed){ if (mouseX > 0 && mouseX < 100 && mouseY > 459 && mouseY < height){ println("load"); clear = false; if (popstrings != null){ if (popstrings.length > popsel){ if (!delc.loadingTestPage){ delc.testPage(popstrings[popsel]); popsel++; } } } } else if (mouseX > 598 && mouseX < width && mouseY > 458 && mouseY < height){ println("clear"); clear = true; } else if (mouseX > 558 && mouseX < 600 && mouseY > 458 && mouseY < height){ showText = !showText; } } counter++; // saveFrame(); }