753

1

Oh, meteors!

UPDATE 19/02 2015

I made a simple graphic showing how many meteors fell down to Earth from 1900 to 2000. To calculate the number I reordered the dataset to show the data chronologically, and made a loop to test if the year of every strike was the same as the prior, then added 1 to a variable; if not, reset the variable o 0.

Every strike draws a small rectangle (1px wide), so the large lines you can see are large series of those tiny rectangles. I'm sure this is not the smartest way to do that.

Here's the code.

// LIBRARIES
import processing.pdf.*;

// GLOBAL VARIABLES
String csv[];
String myData[][];
PFont f;
int cantAnual = 1;
int inicio = 1900;
int fin = 2000;

// SETUP
void setup() {
  size(450, 450);
  noLoop();
  f = createFont("Arial", 10);
  csv = loadStrings("MeteorStrikes-anual.csv");
  myData = new String[csv.length][6];
  for(int i=0; i<csv.length; i++) {
    myData2[i] = csv[i].split(",");
  }
}

// DRAW
void draw() {
  beginRecord(PDF, "meteorStrikes.pdf");
  noStroke();
  //fechas
  for (int i = inicio; i <= fin; i+=10) {
    fill(#202020);
    textFont(f2);
    text(i, 10, map(i, inicio, fin, 20, height-10));
    fill(225);
    rect(40, 4+map(i, inicio, fin, 10, height-20), width-50,2);
  }

  //Lee los datos del dataset y los asigna a variables
  //Gráfico 2: número anual de meteoritos
  for(int i=1; i<myData.length; i++){
    fill(#333333);
    noStroke();
    if(int(myData[i][1]) == int(myData[i-1][1])){
      cantAnual++;
    } else {
      noFill();
      cantAnual=1;
    }

  if (int(myData[i][1])> inicio && int(myData[i][1]) < fin) {
    float yPos = map(float(myData[i][1]), inicio, fin, 10, height-10);
    float xPos = 40+cantAnual/10;
    rect(xPos, yPos, 1, 2);
  }
    
  }

endRecord();
println("PDF Saved!");
}

--------------------------------------------------------------------

I'll try to use the dataset in more than one way...

First a small tweak to make the data appear in chronological order when moving the mouse from left to right

------

//stores the year of the impact in a variable called 'yr'
int yr = int(myData[i][1]);

//draws the ellipse only if the year is before the one defined by the mouse position
if(yr < map (mouseX,0,width,0,2014)){
      ellipse(graphLong, graphLat, markerSize, markerSize);
}

------

See it in action -> http://www.openprocessing.org/sketch/184270

Comments

Please sign in or sign up to comment.