Last active
January 25, 2016 05:39
-
-
Save raphaelschaad/a8a9f33107c70d7880f3 to your computer and use it in GitHub Desktop.
Processing sketch visualizing a large set of meteorite strikes as a map for learning purposes. To run, extract data.zip because GitHub Gist doesn't allow folders but Processing expects external resources in ./data. https://www.skillshare.com/classes/design/Data-Visualization-Designing-Maps-with-Processing-and-Illustrator/1063775924
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// processing_meteormap.pde | |
// | |
// Processing sketch visualizing a large set of meteorite strikes as a map for learning purposes. | |
// To run, extract xdata.zip because GitHub Gist doesn't allow folders but Processing expects external resources in ./data. | |
// https://www.skillshare.com/classes/design/Data-Visualization-Designing-Maps-with-Processing-and-Illustrator/1063775924 | |
// | |
// Created by Raphael Schaad on 2016-01-23. | |
// This is free and unencumbered software released into the public domain. | |
// | |
import processing.pdf.*; | |
final int kCanvasWidth = 800; | |
PShape worldMap; | |
PFont font; | |
String[][] meteorStrikes; | |
void settings() { | |
// Given our equirectangular map projection, the height has to be half the width | |
size(kCanvasWidth, ceil(kCanvasWidth/2)); | |
} | |
void setup () { | |
worldMap = loadShape("worldmap.svg"); | |
font = createFont("Avenir-Medium", 8); | |
// Columns: place,year,mass_g,longitude,latitude,fell_found | |
// Example: Hoba,1920,60000000,17.91667,-19.58333,Found | |
final int kColumnCount = 6; | |
String[] csvRows = loadStrings("meteorstrikes.csv"); | |
meteorStrikes = new String[csvRows.length][kColumnCount]; | |
for (int i = 0; i < csvRows.length; i++) { | |
meteorStrikes[i] = csvRows[i].split(","); | |
} | |
noLoop(); | |
} | |
void draw () { | |
beginRecord(PDF, "meteorstrikesmap.pdf"); | |
shape(worldMap, 0, 0, width, height); | |
// Record text not as outlines but as characters | |
textMode(MODEL); | |
textFont(font); | |
// meteorStrikes.length: 34066 | |
final int kPlotedStrikesCount = 1000; | |
for (int i = 1; i < kPlotedStrikesCount; i++) { | |
fill(255, 0, 0, 50); | |
noStroke(); | |
float worldMapLongitude = map(float(meteorStrikes[i][3]), -180, 180, 0, width); | |
float worldMapLatitude = map(float(meteorStrikes[i][4]), 90, -90, 0, height); | |
final float kEllipseDiameterScale = 0.015; | |
float ellipseDiameter = kEllipseDiameterScale * sqrt(float(meteorStrikes[i][2])) / PI; | |
ellipse(worldMapLongitude, worldMapLatitude, ellipseDiameter, ellipseDiameter); | |
final int kLabeledStrikesCount = 10; | |
if (i <= kLabeledStrikesCount) { | |
fill(0); | |
final float kPaddingX = 4; | |
final float kPaddingY = 2; | |
text(meteorStrikes[i][0], worldMapLongitude + ellipseDiameter + kPaddingX, worldMapLatitude + kPaddingY); | |
noFill(); | |
strokeWeight(0.3); | |
stroke(0); | |
line(worldMapLongitude + ellipseDiameter / 2, worldMapLatitude, worldMapLongitude + ellipseDiameter, worldMapLatitude); | |
} | |
} | |
endRecord(); | |
println("PDF Saved!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment