How do I place different colored ellipses on a map while using latitude and longitude?

edited December 2015 in Questions about Code

This is a for a school assignment so I'm really new to Processing, but I'm wanting to use 4 different colored ellipses to convey information being taken from an xml sheet and plotting them on a map using latitude and longitude. I have the coding working but only for one color, is there a way to change this so I can control multiple colors at once?

 PShape baseMap;
 String csv[];
  String myData[][];

  //Setup BaseMap and csv info

  void setup() {
    size(3000, 1700);
    noLoop();
    baseMap = loadShape("WorldMap.svg");
    csv = loadStrings("WeatherCoordinates.csv");
    myData = new String[csv.length][5];
    for(int i=0; i<csv.length; i++) {

      myData[i] = csv[i].split(",");


 }
 }


 //draw
 void draw() {
   shape(baseMap, 0, 0, width, height);
   noStroke();


   for(int i=0; i<myData.length; i++){
     fill(25, 30, 255, 70);
     noStroke();
     float graphLong = map(float(myData[i][3]), -180, 180, 0, width);
     float graphLat = map(float(myData[i][2]), 90, -90, 0, height);
     float markerSize = 5*(float(myData[i][0]));
    println(graphLong + " / " + graphLat);  
    ellipse(graphLong, graphLat, markerSize, markerSize);


   if(i<25){
     fill(0);
     text(myData[i][1], graphLong + markerSize + 30, graphLat);
     noFill();
     stroke(0);
     line(1.2*graphLong+markerSize, graphLat, graphLong+markerSize, graphLat);
      }
     }
   }
 }

Answers

  • Just test against the variable and set the fill colour within each condition:

    if(myData[i][#] == ???) {
        fill(255,166,0);
    }
    else {
        fill(0);
    }
    

    I don't know your data so you'll have to fill in the blanks in the above code for it to work...

  • the easiest way to get a spread of colours is to use HSB mode

    colorMode(HSB, nColours, 100, 100);
    

    then you can use

    fill(i, 50, 50);
    

    for a different colour for every item.

    i find it's easiest to change back to RGB for things like setting background colours or graph lines.

  • What piece of data to i enter to replace the "???" in the line

     if(myData[i][#] == ???) {
    fill(255,166,0);
     }
     else {
         fill(0);
     }    
    
Sign In or Register to comment.