import processing.opengl.*; PFont meta24, meta12; ListeningHistory myHistory; Connections connections; Graph circleGraph; float radius; float offset; StringBuffer searchString; int logScaleFactor = 1000; Longtail longtail; MaxSlider maxslider; SpringSlider springSlider; SpacingSlider spacingSlider; float overallPop = 0.1; float maxPop = 0.1; void setup(){ size(800,800,OPENGL); frameRate(10); colorMode(HSB,1); smooth(); radius = (min(width,height)*0.5)/2; offset = 0; searchString = new StringBuffer(); meta24 = loadFont("MetaNormal-Roman-24.vlw"); meta12 = loadFont("MetaNormal-Roman-12.vlw"); myHistory = new ListeningHistory("megamu"); myHistory.loadData(); myHistory = myHistory.filterByPopularity(0.05); connections = new Connections(); connections.load(myHistory.getArtists()); longtail = new Longtail(this, new Box(this, 190, 50, 600, 10)); maxslider = new MaxSlider(this, new Box(this, 190, 30, 600, 70)); springSlider = new SpringSlider(this, new Box(this, 190, 30, 600, 725)); spacingSlider = new SpacingSlider(this, new Box(this, 190, 30, 600, 760)); circleGraph = new Graph(); for(int a=0; a= longtail.getRangeMin() && a.getPopularity() <= longtail.getRangeMax() && a.getMaxPopularity() >= maxslider.getPosition()){ pushMatrix(); rotate((n.position +offset)*TWO_PI); boolean highlighted = isHighlighted(a); fill(n.position,1,0.7, (highlighted?1:0.1)*(0.3 + 0.5*n.mass)); textSize(n.mass*24); text(a.getName(),radius,textAscent()/2); popMatrix(); } } // draw connections noFill(); Iterator connectionIterator = circleGraph.getConnections().values().iterator(); while(connectionIterator.hasNext()){ Graph.Node.Connection c = (Graph.Node.Connection) connectionIterator.next(); Artist a1 = (Artist) c.nodeFrom.get(); Artist a2 = (Artist) c.nodeTo.get(); if(a1.getPopularity() >= longtail.getRangeMin() && a1.getPopularity() <= longtail.getRangeMax() && a1.getMaxPopularity() >= maxslider.getPosition() && a2.getPopularity() >= longtail.getRangeMin() && a2.getPopularity() <= longtail.getRangeMax() && a2.getMaxPopularity() >= maxslider.getPosition()){ float fromPos = c.nodeFrom.position; float toPos = c.nodeTo.position; boolean highlighted = (isHighlighted((Artist) c.nodeFrom.get()) || isHighlighted((Artist) c.nodeTo.get())); stroke(0, (searchString.length()==0?0.1:(highlighted?1:0.03))*(c.strength)); float d = c.nodeFrom.distanceTo(c.nodeTo); float x1 = cos((fromPos +offset)*TWO_PI)*radius; float y1 = sin((fromPos +offset)*TWO_PI)*radius; float x2 = cos((toPos +offset)*TWO_PI)*radius; float y2 = sin((toPos +offset)*TWO_PI)*radius; bezier(x1, y1, x1*(0.95-d), y1*(0.95-d), x2*(0.95-d), y2*(0.95-d), x2, y2); } } popMatrix(); // draw search textFont(meta24); fill(0.6,0.8,0.8); text(searchString.toString(), 10, 10+textAscent()); longtail.draw(); maxslider.draw(); springSlider.draw(); spacingSlider.draw(); } float mouseGrab=0; float offsetGrab=0; void mousePressed(){ mouseGrab = atan2(height/2-mouseY,width/2-mouseX)/TWO_PI; offsetGrab = offset; } void mouseDragged(){ offset = offsetGrab + atan2(height/2-mouseY,width/2-mouseX)/TWO_PI - mouseGrab; } boolean isHighlighted(Artist a){ return (searchString.length()==0 || ( searchString.length()>0 && a.getName().toLowerCase().indexOf(searchString.toString().toLowerCase())!=-1 )); } /* if( target.toLowerCase().indexOf(search.toLowerCase()) != -1 ) return true; */ // search string! int lastPressed = 0; void keyPressed(){ // This is just for output!!! if(key==' '){ circleGraph.sortByPosition(); PrintWriter writer = createWriter("order.txt"); Iterator circleGraphIterator = circleGraph.listIterator(); while(circleGraphIterator.hasNext()){ Graph.Node n = (Graph.Node) circleGraphIterator.next(); Artist a = (Artist) n.get(); if(a.getPopularity() >= longtail.getRangeMin() && a.getPopularity() <= longtail.getRangeMax() && a.getMaxPopularity() >= maxslider.getPosition()) writer.println(nf(n.position,1,4) +" - "+ a.getName()); } writer.flush(); writer.close(); } // ========================== if(millis() - lastPressed > 4000) searchString = new StringBuffer(); lastPressed = millis(); if(key == BACKSPACE){ if(searchString.length()>0) searchString.deleteCharAt(searchString.length()-1); } else if(key >= 32 && key < 128){ searchString.append(key); } }