loops - Processing link() returning multiple links -
i have pretty basic scatter plot shows largest impact craters on earth. y-axis diameter, x age.
i trying create interaction when click data point on graph link displaying craters wiki page opens.
i have working, when click data point page opens every entry in loop. dozen+ of same page.
is there way make return 1 entry. tried noloop(); works, returns relevant entry, stops program, making can longer click on other data points.
i included relevant code below.
int rownumber; //set rownumber integer int datawh = 10; //data width/height int row = 0; table craterwiki = loadtable("craterwiki.tsv"); //loads , parses tsv data rows , columns string craterlink = craterwiki.getstring(row, 5); pfont font; pfont fonttitle; void setup() { size(1120, 920); rownumber = craterwiki.getrowcount(); //number of rows font = loadfont("couriernewpsmt-14.vlw"); fonttitle = loadfont("couriernewpsmt-18.vlw"); } void draw() { background(#111727); textfont (font, 14); textsize(14); //deafult font size stroke(180); fill(180, 200); int vertx = 45; // location of y-axis title on x int verty = 460; // location of y-axis title on y int headx = 560; // location of header on x int heady = 50; // location of header on y int infox = 560; // location of crater info on x int infoy = 400; // location of crater info on y // x-axis setup (crater age) textalign(center); line(100, 830, 1024, 830); // x-axis line (int = 0; < 16; i++) { // loops x-axis data in 16 increments text (i*150, * 60 + 100, 850); // 16 increments of 150, spacing between each increment, , location of chain } textfont (fonttitle, 18); text("crater age (million years)", 560, 885); // y-axis setup (crater diameter) textalign(center); textfont (font, 14); line(100, 80, 100, 830); // y-axis line (int = 0; < 16; i++) { // loops y-axis data in 16 increments text (i*20, 80, 830-i*49); //16 increments of 20, spacing between each increment, , location of chain } pushmatrix(); //reset matrix stack translate(vertx,verty); //location of y-axis title rotate(-half_pi); //make text vertical textfont (fonttitle, 18); text("crater diameter (km)", 0, 0); popmatrix(); pushmatrix(); //reset matrix stack translate(headx,heady); //location of header title textfont (fonttitle, 18); text(" largest impact craters on earth", 0, 0); popmatrix(); textfont (font, 14); // data point draw loop (int row = 0; row < rownumber; row++) { // define/load table again table craterwiki = loadtable("craterwiki.tsv"); // crater names displayed above data point , in center gstring cratername = craterwiki.getstring(row, 0); // crater location displayed in center string craterlocation = craterwiki.getstring(row, 1); // crater size displayed in center string cratercountry = craterwiki.getstring(row, 2); string craterlink = craterwiki.getstring(row, 5); // crater size displayed in center float cratersize = craterwiki.getfloat(row, 3); float y = map(cratersize, 0, 300, 825, 100); // crater age displayed in center float craterage = craterwiki.getfloat(row, 4); float x = map(craterage, 0, 2250, 100, 1024); // data point ellipse based off of actual diameter of crater (cratersize) nostroke(); fill(#ffba00, 180); ellipse(x, y, datawh*cratersize/45, datawh*cratersize/45); // mouse interaction textalign(center); fill(180, 200); // when mouse on cratersize ellipse display text below if(dist(x, y, mousex, mousey) < (datawh*cratersize/45)) { pushmatrix(); translate(infox,infoy); text( "crater name: " + cratername, 0, 0); text( "location: " + craterlocation, 0 , 60); text( "country: " + cratercountry, 0 , 80); text( "age: " + craterage +" million years", 0 , 40); text( "diameter: " + cratersize + "km", 0 , 20); popmatrix(); //second ellipse created when mouse on cratersize ellipse int datawh = 12; text(cratername, x, y - datawh*cratersize/90 - 5); fill(#ffd564, 180); ellipse(x, y, datawh*cratersize/45, datawh*cratersize/45); } } } // if mouse pressed display crater wiki page void mousepressed() { link(craterlink); }
if more information required please let me know.
you're checking (aka polling) whether mouse pressed 60 times per second. instead of polling, should use event function fires once every time mouse clicked:
void mousepressed() { link(craterlink); }
more info on event functions can found in reference here.
Comments
Post a Comment