Cedric
Re: Text Help Required
Reply #3 - Mar 22nd , 2009, 2:09pm
looking at the text examples should have answered all your questions... anyway, here it is... PImage mapImage; Table locationTable; Table connTable; int rowCount; int transCount; int x1, x2, y1, y2; int mapWidth = 600; int mapHeight = 563; boolean reFresh = false; PFont myFont; String[] Locs = new String[mapWidth * mapHeight]; void setup() { size(mapWidth, 563); rectMode(CORNER); myFont = createFont("Arial", 14); textFont(myFont); mapImage = loadImage("europe_plastic.png"); //Make a data table from a file that contains //the coordinates of each country. locationTable = new Table("locations20072009.tsv"); connTable = new Table("conns20072009.tsv"); // The row count will be used a lot, so store it globally. rowCount = locationTable.getRowCount(); transCount = connTable.getRowCount(); print("tranfers ="+transCount); for (int L = 0; L < (mapWidth * mapHeight); L++) { Locs[L] =" "; // clear out array } } void draw() { if ( reFresh == false){ drawMap(); reFresh = true; } if (Locs[(mouseY * mapWidth)+ mouseX].equals(" ") == false){ //print("Location ="+ Locs[(mouseY * mapWidth)+ mouseX] + "\n"); noStroke(); fill(255); rect(0,0,230,30); fill(0); text("Location: "+ Locs[(mouseY * mapWidth)+ mouseX] + "\n", 10,20); } } void drawMap() { background(255); image(mapImage, 0, 0); //line(168, 335, 153, 312); //Drawing attributes for the ellipses. smooth(); fill(192, 0, 0); //noStroke(); // Loop through the rows of the locations file and draw the points. for (int row = 0; row < rowCount; row++) { int x = locationTable.getInt(row, 1); // column 1 int y = locationTable.getInt(row, 2); // column 2 // instead of a single point, make this a square 5 pix high x 5 pix wide Locs[(mapWidth*y)+x] = locationTable.getString(row, 0); // column 0 Locs[(mapWidth*y)+x-1] = locationTable.getString(row, 0); Locs[(mapWidth*y)+x+1] = locationTable.getString(row, 0); Locs[(mapWidth*(y-1))+x] = locationTable.getString(row, 0); //Locs[(mapWidth*(y+1))+x] = locationTable.getString(row, 0); // add loop writing Locs[(mapWidth*y)+x] = locationTable.getString(row, 0) to each cell in array ellipse(x, y, 5, 5); } // Loop through the rows of the conns file and draw the points. for (int row = 0; row < transCount; row++) { x1 = connTable.getInt(row, 1); // column 1 y1 = connTable.getInt(row, 2); // column 2 x2 = connTable.getInt(row, 3); // column 1 y2 = connTable.getInt(row, 4); // column 2 //line(x1, y1, x2, y2); noFill(); stroke(0,0,0,64); strokeWeight(2); //alpha(20); bezier(x1, y1, x1, y1-30, x2, y2-30, x2, y2); } }