Skip to content

Instantly share code, notes, and snippets.

@brendandawes
Last active December 12, 2015 04:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendandawes/4713241 to your computer and use it in GitHub Desktop.
Save brendandawes/4713241 to your computer and use it in GitHub Desktop.
Number of kills by James Bond in EON Production movies. Data provided by the Guardian Data Store.
import processing.pdf.*;
/*
James Bond Kills by Brendan Dawes
http://brendandawes.com/projects/jamesbondkills/
CSV import method by che-wei wang.
Requires CSV export from data provided by Guardian Data Store.
https://docs.google.com/spreadsheet/ccc?key=0AonYZs4MzlZbdEgyUE9aQktJR0ZEWFlURGlYODNISHc#gid=1
Press mouse to save a PDF.
*/
String lines[];
String [][] csv;
int csvWidth=0;
PFont font;
PGraphics g, m;
boolean record = false;
final int LARGE_CIRCLE_VERTICAL_SPACING = 106;
final int SMALL_CIRCLE_SPACING = 53;
final int LARGE_CIRCLE_WIDTH = 104;
final int SMALL_CIRCLE_WIDTH = 50;
int START_Y;
final color LARGE_CIRCLE_FILL = color(183,7,7);
final color SMALL_CIRCLE_FILL = color(38,126,121);
final color LABEL_COLOR = color(255);
void setup() {
size(3000, 1200);
rectMode(LEFT);
ellipseMode(LEFT);
START_Y = height;
font = loadFont("TradeGothic-Bold-48.vlw");
textFont(font);
parseBondKills();
}
void draw() {
if (record) {
beginRecord(PDF, "jamesbond-####.pdf");
}
rectMode(LEFT);
ellipseMode(LEFT);
background(0);
smooth();
noStroke();
textSize(12);
textAlign(LEFT);
int x = 50;
int y = START_Y;
for (int i=1; i < csv.length; i++) {
int xInc = SMALL_CIRCLE_SPACING;
int bondKillScore = int(csv[i][4]);
if (bondHasKilled(bondKillScore) && isOfficialMovie(csv[i][1])) {
int offset = 25;
for (int c=0; c < ceil(bondKillScore/10); c++) {
y -= LARGE_CIRCLE_VERTICAL_SPACING;
drawNode(x,y,LARGE_CIRCLE_FILL,LARGE_CIRCLE_WIDTH);
xInc = 84;
}
y -= SMALL_CIRCLE_SPACING;
if (ceil(bondKillScore/10) > 0) {
x+=SMALL_CIRCLE_WIDTH/2;
}
for (int j=0; j < bondKillScore%10; j++) {
drawNode(x,y,SMALL_CIRCLE_FILL,SMALL_CIRCLE_WIDTH);
y -= SMALL_CIRCLE_SPACING;
}
drawLabel(x+offset,y+25,csv[i][0].toUpperCase());
x += xInc;
y = START_Y;
}
}
if (record) {
endRecord();
record = false;
}
}
void drawNode(int x, int y, color fillColor, int circleSize) {
fill(fillColor);
ellipse(x,y,circleSize,circleSize);
}
void drawLabel(int x, int y, String label) {
pushMatrix();
translate(x, y);
rotate(radians(-90));
fill(LABEL_COLOR );
text(label, 0, 0);
popMatrix();
}
boolean isOfficialMovie(String test){
return(test.equals("Official"));
}
boolean bondHasKilled(int n) {
if (n > 0) {
return true;
} else {
return false;
}
}
void parseBondKills() {
lines = loadStrings("bondkills.csv");
//calculate max width of csv file
for (int i=0; i < lines.length; i++) {
String [] chars=split(lines[i], ',');
if (chars.length>csvWidth) {
csvWidth=chars.length;
}
}
//create csv array based on # of rows and columns in csv file
csv = new String [lines.length][csvWidth];
//parse values into 2d array
for (int i=0; i < lines.length; i++) {
String [] temp = new String [lines.length];
temp= split(lines[i], ',');
for (int j=0; j < temp.length; j++) {
csv[i][j]=temp[j];
}
}
}
void mousePressed() {
record = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment