/* WikiWeb - Version 2 by anthony mattox ahmattox (at) gmail (dot) com wikiweb.anthonymattox.com www.anthonymattox.com some rights reserved cc by-nc-sa */ // wikiweb ArrayList Pages; ArrayList DPages; ArrayList Links; ToolBar TB=new ToolBar(); PImage tbd; PImage tbe; PImage tbv; PImage tbdh; PImage tbeh; PImage tbvh; PImage tbeg; PImage helpim; PImage reset; PImage reseth; PImage qim; PImage qimh; PImage plink; PImage amlink; PImage wwlink; PImage plinkh; PImage amlinkh; PImage wwlinkh; float theta=0; int gen=-1; int target=-1; int tx=0; int ty=0; int sx=0; int sy=0; int ntx=0; int nty=0; PVector mid; boolean slide=false; boolean move=true; boolean help=false; boolean sm=true; void setup() { Pages=new ArrayList(); Links=new ArrayList(); DPages=new ArrayList(); size(800,600); ellipseMode(CENTER); rectMode(CENTER); background(255); frameRate(25); smooth(); mid=new PVector(width/2,height/2); Pages.add(new Page(mid.x,mid.y,"Main_Page")); Page p=(Page) Pages.get(0); p.p=false; //p.c=0; PFont font; font = loadFont("Geneva-20.vlw"); textFont(font, 12); tbd=loadImage("tb_del.gif"); tbe=loadImage("tb_ex.gif"); tbv=loadImage("tb_v.gif"); tbdh=loadImage("tb_delh.gif"); tbeh=loadImage("tb_exh.gif"); tbvh=loadImage("tb_vh.gif"); tbeg=loadImage("tb_ex2.gif"); helpim=loadImage("help.gif"); reset=loadImage("reset.gif"); reseth=loadImage("reseth.gif"); qim=loadImage("q.gif"); qimh=loadImage("qh.gif"); plink=loadImage("plink.gif"); amlink=loadImage("amlink.gif"); wwlink=loadImage("wwlink.gif"); plinkh=loadImage("plinkh.gif"); amlinkh=loadImage("amlinkh.gif"); wwlinkh=loadImage("wwlinkh.gif"); } void draw() { background(255); if (slide==true) { ntx=mouseX-sx; nty=mouseY-sy; if (ntx!=0 || nty!=0){ CrossHair(); } } if (keyPressed==true && key==' '){ CrossHair(); } translate(tx+ntx,ty+nty); if (gen>=0) { Page p=(Page) Pages.get(gen); getLinks(gen, p.t); gen=-1; } for(int i=Links.size()-1; i>=0;i--) { Link l=(Link) Links.get(i); if (l.dead) { //Links.remove(i); } else { l.force(); } } for(int i=Pages.size()-1;i>=0;i--) { Page pi=(Page) Pages.get(i); if (pi.dead) { kill(i); } else { for(int j=i-1; j>=0;j--) { Page pj=(Page) Pages.get(j); strokeWeight(1); float d=dist(pj.x,pj.y,pi.x,pi.y); if (d<=150) { float f=-sq((170-d)/80); theta=atan2((pi.y-pj.y),(pi.x-pj.x)); pi.x=pi.x-f*cos(theta); pi.y=pi.y-f*sin(theta); pj.x=pj.x+f*cos(theta); pj.y=pj.y+f*sin(theta); } } } } for(int i=Links.size()-1; i>=0;i--) { Link l=(Link) Links.get(i); l.rend(); } for(int i=Pages.size()-1;i>=0;i--) { Page p=(Page) Pages.get(i); if (target==i){ p.rend(true); } else { p.rend(false); } } for(int i=DPages.size()-1;i>=0;i--) { DPage dp=(DPage) DPages.get(i); dp.update(); if (dp.dead()) { DPages.remove(i); } else { dp.render(); } } if (keyPressed==true && key==CODED) { Scroll(); } if (target>=0){ Page tp=(Page) Pages.get(target); TB.x=tp.x; TB.y=tp.y; TB.rend(); } translate(-tx-ntx,-ty-nty); if (mouseX>=757 && mouseX<=785 && mouseY >=565 && mouseY <= 590) { image(reseth,757,565); } else { image(reset,757,565); } if (mouseX>=727 && mouseX<=746 && mouseY >=565 && mouseY <= 590) { image(qimh,727,565); } else { image(qim,727,565); } if (help==true) { image(helpim,119,86); if (mouseX>=135 && mouseX<=262 && mouseY >=480 && mouseY <= 495) { image(plinkh,135,480); } else { image(plink,135,480); } if (mouseX>=135 && mouseX<=292 && mouseY >=500 && mouseY <= 515) { image(amlinkh,135,500); } else { image(amlink,135,500); } if (mouseX>=135 && mouseX<=311 && mouseY >=520 && mouseY <= 535) { image(wwlinkh,135,520); } else { image(wwlink,135,520); } } } void kill(int n) { for (int j=Links.size()-1; j>=0;j--) { Link l=(Link) Links.get(j); if (l.pa==n) { Page pc=(Page) Pages.get(l.pb); pc.c--; Links.remove(j); } else if (l.pb==n){ Page pc=(Page) Pages.get(l.pa); pc.c--; Links.remove(j); } if (l.pa>n) { l.pa--; } if (l.pb>n) { l.pb--; } } Page pi=(Page) Pages.get(n); DPages.add(new DPage(new PVector(pi.x,pi.y), int(sqrt(pi.c))+6)); Pages.remove(n); } // ------- toolbar class ToolBar{ float x,y; ToolBar() { x=0; y=0; } void rend() { fill(100); noStroke(); pushMatrix(); translate(x,y+7); rect(20,20,68,24); beginShape(); vertex(0,0); vertex(5,9); vertex(-5,9); endShape(); Page pi=(Page) Pages.get(target); if (mouseX-tx <= pi.x+53 && mouseX-tx >= pi.x-11 && mouseY-ty <= pi.y+38 && mouseY-ty >= pi.y+18) { if (pi.im==false && pi.p==false) { if (mouseX-tx <= pi.x+10 && mouseX-tx >= pi.x-10) { image(tbeh,-12,10); } else { image(tbe,-12,10); } } else { image(tbeg,-12,10); } if (mouseX-tx <= pi.x+33 && mouseX-tx >= pi.x+11) { image(tbdh,10,10); } else { image(tbd,10,10); } if (mouseX-tx <= pi.x+53 && mouseX-tx >= pi.x+34) { image(tbvh,32,10); } else { image(tbv,32,10); } } else { if (pi.im==true || pi.p==true) { image(tbeg,-12,10); } else { image(tbe,-12,10); } image(tbd,10,10); image(tbv,32,10); } popMatrix(); } } // ----- page class class Page { float x, y; String t; boolean p, im, dead; int c; Page(float xpos, float ypos, String title) { x=xpos; y=ypos; t=title; p=false; im=false; c=1; dead=false; } void rend(boolean tar) { int d=int(dist(mouseX-tx-ntx,mouseY-ty-nty,x,y)); int ts= int(sqrt(c)); boolean h; if (d<=10+ts) { h=true; } else { h=false; } if (h==true) { fill(200,130,20); //status("http://en.wikipedia.org/wiki/"+t); } else { fill(100); //status(""); } if (tar==false) { noStroke(); } else { strokeWeight(3); stroke(0,142,186); } if (im==false) { ellipse(x,y,6+ts,6+ts); } else { rect(x,y,6+ts,6+ts); } if (d<=120 || p==true || tar==true) { if (p==true || tar==true){ textSize(12); if (h==true) { fill(200,130,20); } else { fill(0); } } else { textSize(constrain(int((130-d)/5),0,12)); if (h==true) { fill(200,130,20); } else { fill(0,255-int(d*3)); } } text(t,x+10,y+5); } if (c==0) { dead=true; } } } // ----- link class class Link { int pa, pb; boolean dead; Link(int pagea,int pageb){ pa=pagea; pb=pageb; dead=false; } void force() { Page pi=(Page) Pages.get(pa); Page pj=(Page) Pages.get(pb); float d=dist(pi.x,pi.y,pj.x,pj.y); float f=sq(d/80); theta=atan2((pi.y-pj.y),(pi.x-pj.x)); pi.x=pi.x-f*cos(theta); pi.y=pi.y-f*sin(theta); pj.x=pj.x+f*cos(theta); pj.y=pj.y+f*sin(theta); } void rend() { Page pi=(Page) Pages.get(pa); Page pj=(Page) Pages.get(pb); noFill(); stroke(210); strokeWeight(1); line(pi.x,pi.y,pj.x,pj.y); } } // ----- links (gathers links from web pages) void getLinks(int index, String begin) { int a=0; int c=0; boolean content=false; String lines[]=loadStrings("http://en.wikipedia.org/wiki/"+begin); int alimit=int(sqrt(lines.length)*2); for (int i=0; i")==true) { content=true; } } } else if (content==true) { c=c+1; for (int j=0; j10) { if (url.substring(0,7).equals("Portal:")==true) { create=false; } else if (url.substring(0,10).equals("Wikipedia:")==true) { create=false; } else if (url.substring(0,8).equals("Special:")==true) { create=false; } else if (url.substring(0,5).equals("Help:")==true) { create=false; } else if (url.substring(0,9).equals("Template:")==true) { create=false; } else if (url.substring(0,9).equals("Category:")==true) { create=false; } else if (url.substring(0,5).equals("Talk:")==true) { create=false; } else if (url.substring(0,5).equals("User:")==true) { create=false; } else if (url.substring(0,6).equals("Image:")==true) { pim=true; } } if (create==true) { boolean newurl=true; int dupurl=0; for (int o=Pages.size()-1; o>=0; o--) { Page p=(Page) Pages.get(o); if (url.equals(p.t)==true) { newurl=false; dupurl=o; } } if (newurl==true) { float r=random(TWO_PI); Page p=(Page) Pages.get(index); Pages.add(new Page(p.x+20*cos(r),p.y+20*sin(r),url)); if (pim==true) { Page q=(Page) Pages.get(Pages.size()-1); q.im=true; } p.c++; Links.add(new Link(index,Pages.size()-1)); a=a+1; } else { Links.add(new Link(index,dupurl)); Page p=(Page) Pages.get(index); p.c++; Page q=(Page) Pages.get(dupurl); q.c++; } } } } } if (lines[i].substring(j,j+20).equals("")==true) { content=false; break; } if (a>alimit){ break; } } } } } // ----- inputs void mousePressed() { if (help==true) { if (mouseX>=135 && mouseX<=262 && mouseY >=480 && mouseY <= 495) { link("http://www.processing.org", "_blank"); } else if (mouseX>=135 && mouseX<=292 && mouseY >=500 && mouseY <= 515) { link("http://www.anthonymattox.com", "_blank"); } else if (mouseX>=135 && mouseX<=311 && mouseY >=520 && mouseY <= 535) { link("http://wikiweb.anthonymattox.com", "_blank"); } else { help=false; } }else if(mouseX>=727 && mouseX<=746 && mouseY >=565 && mouseY <= 590) { if (help==true) { help=false; } else { help=true; } }else if(mouseX>=757 && mouseX<=785 && mouseY >=565 && mouseY <= 590) { Reset(); } else if (keyPressed==true && key==' ') { StartScroll(); } else if (mouseButton==LEFT){ boolean next=true; if (target>=0) { Page pi=(Page) Pages.get(target); if (mouseX-tx <= pi.x+53 && mouseX-tx >= pi.x-11 && mouseY-ty <= pi.y+38 && mouseY-ty >= pi.y+18) { if (mouseX-tx <= pi.x+10 && mouseX-tx >= pi.x-10) { Expand(target); } if (mouseX-tx <= pi.x+33 && mouseX-tx >= pi.x+11) { RemovePage(target); } if (mouseX-tx <= pi.x+53 && mouseX-tx >= pi.x+34) { View(target); } next=false; } } if (next==true) { move=true; Target(); if (move==true){ target=-1; StartScroll(); } if (mouseEvent.getClickCount()==2) { Expand(); } } } else if (mouseButton==RIGHT){ View(); } } void keyPressed() { if (target>=0) { if (key==BACKSPACE || key==DELETE || key=='x') { RemovePage(target); } else if (key==ENTER || key==RETURN) { Expand(target); } } /* if (key=='s') { saveFrame("wikiweb_v2-####.png"); } else */ if (key=='h') { if (help==true) { help=false; } else { help=true; } } else if (key=='a') { if (sm==true) { sm=false; noSmooth(); } else { sm=true; smooth(); } } } void mouseReleased() { EndScroll(); } // ----- functions void RemovePage() { for(int i=Pages.size()-1;i>=0;i--) { Page p=(Page) Pages.get(i); if (dist(mouseX-tx+ntx,mouseY-ty+nty,p.x,p.y)<10) { p.dead=true; for (int j=Links.size()-1; j>=0;j--) { Link l=(Link) Links.get(j); if (l.pa==i || l.pb==i) { l.dead=true; } } } } target=-1; } void RemovePage(int tar) { Page p=(Page) Pages.get(tar); p.dead=true; target=-1; } void Expand() { for(int i=Pages.size()-1;i>=0;i--) { Page p=(Page) Pages.get(i); if (dist(mouseX-tx+ntx,mouseY-ty+nty,p.x,p.y)<10 && p.im==false && p.p==false) { p.p=true; noStroke(); fill(0,170); rect(mid.x,mid.y,220,50); fill(255); textSize(12); text("Downloading Links...", mid.x-57, mid.y+6); gen=i; } } target=-1; } void Expand(int tar) { Page p=(Page) Pages.get(tar); if (p.im==false && p.p==false) { p.p=true; noStroke(); fill(0,170); rect(mid.x,mid.y,220,50); fill(255); textSize(12); text("Downloading Links...", mid.x-57, mid.y+6); gen=tar; } target=-1; } void Target() { for(int i=Pages.size()-1;i>=0;i--) { Page p=(Page) Pages.get(i); if (dist(mouseX-tx+ntx,mouseY-ty+nty,p.x,p.y)<10) { if (target==i) { target=-1; } else { target=i; } move=false; } } } void Reset() { for(int i=Links.size()-1;i>=0;i--){ Links.remove(i); } for(int i=Pages.size()-1;i>=0;i--){ if (i!=target) { Page pi=(Page) Pages.get(i); DPages.add(new DPage(new PVector(pi.x+tx,pi.y+ty), int(sqrt(pi.c))+6)); Pages.remove(i); } } if (target==-1) { Pages.add(new Page(mid.x,mid.y,"Main_Page")); } else { Page p=(Page) Pages.get(0); p.x=mid.x; p.y=mid.y; p.p=false; p.c=1; } target=-1; tx=0; ty=0; } void View(int tar) { Page p=(Page) Pages.get(tar); link("http://en.wikipedia.org/wiki/"+p.t, "_blank"); } void View() { for(int i=Pages.size()-1;i>=0;i--) { Page p=(Page) Pages.get(i); if (dist(mouseX-tx+ntx,mouseY-ty+nty,p.x,p.y)<10) { link("http://en.wikipedia.org/wiki/"+p.t, "_blank"); } } } void StartScroll() { slide=true; sx=mouseX; sy=mouseY; } void EndScroll() { if (slide==true){ tx=tx+ntx; ty=ty+nty; sx=0; sy=0; ntx=0; nty=0; slide=false; } } void Scroll() { if (keyCode==UP){ ty=ty-7; } if (keyCode==DOWN){ ty=ty+7; } if (keyCode==LEFT){ tx=tx-7; } if (keyCode==RIGHT){ tx=tx+7; } } void CrossHair() { strokeWeight(3); stroke(100); line(mouseX-10,mouseY,mouseX+10,mouseY); line(mouseX,mouseY-10,mouseX,mouseY+10); for (int i=0;i<6;i++){ pushMatrix(); translate(mouseX,mouseY); rotate(HALF_PI*i); beginShape(); vertex(10,-2); vertex(10,2); vertex(13,0); endShape(CLOSE); popMatrix(); } } // ----- dead page class DPage{ PVector loc; int rad; DPage(PVector l, int r) { loc=l.get(); rad=r; } void update(){ rad--; } void render(){ fill(100); noStroke(); ellipse(loc.x,loc.y,rad,rad); } boolean dead() { if (rad<=0) { return true; } else { return false; } } }