We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › plotting data to x and y coordinates for an array
Page Index Toggle Pages: 1
plotting data to x and y coordinates for an array (Read 787 times)
plotting data to x and y coordinates for an array
Feb 26th, 2010, 2:46pm
 
I want to plot data for the x and y coordinates of an array of images (country flags) so that the x value equals the gnp of the country and the y value equals the surface area of that country any help would be greatly appreciated I already have all my data.  Here is my code so far.

Table locationTable;
int rowCount;
PFont font;
PImage[] img = new PImage[300];
void setup() {
 size(1250, 750);
 font = loadFont("Times-Roman-14.vlw");
 textFont(font);
 // Make a data table from a file that contains
 // the coordinates of each state.
 locationTable = new Table("myurladdress");
 // The row count will be used a lot, store it locally.
 rowCount = locationTable.getRowCount();
   for (int row = 0; row < rowCount; row++) {
     String code  = locationTable.getString(row, 0);  // column 1
    img[row] = loadImage(code+".gif");
      PImage img = loadImage(code+".gif");
       image(img, 0, 0);
       img.resize(0, 50);
       //img.resize(surface, gnp);
       image(img, 0, 0);

   }
}

void draw() {
 background(255);


 // Drawing attributes for the ellipses  
 smooth();
 fill(192, 0, 0);
 noStroke();

 // Loop through the rows of the locations file and draw the points
 int x = 500;
 int y = 0;
 //int x = surface;
 //int y = gnp;
 for (int row = 0; row < rowCount; row++) {
   String code  = locationTable.getString(row, 0);  // column 1
   image(img[row],x,y);
   //Float x = locationTable.getFloat(row, 1);  // column 1
   //Float y = locationTable.getFloat(row, 2);  // column 2
   int gnp = locationTable.getInt(row, 2);
   int surface = locationTable.getInt(row, 3);
   text(code+":"+gnp+":"+surface, x, y);
   y+=80;
   if (y>height) {
     x = gnp;
     y = surface;
     //y=20;
     //x+=150;
//gnp = PImage img(code+"gif");
   }
 }
}
Re: plotting data to x and y coordinates for an array
Reply #1 - Feb 26th, 2010, 6:04pm
 
first problem that pops out at me is that you're using "img" as a name of an array of images, and also as the name of an individual image loaded later on.  I'd use a more descriptive name for your array, like imgArray.
Re: plotting data to x and y coordinates for an array
Reply #2 - Feb 28th, 2010, 1:44pm
 
thank you so much I'm sure thats not everything that's gotta be fixed but it's a good place to start much appreciated

can someone please tell me how to to map data for the x an y of an image

I want the flags of the countries to have the x value as the GNP and the y values as the surface area
Page Index Toggle Pages: 1