Skip to content

Instantly share code, notes, and snippets.

@beala
Forked from DrSkippy/AgeProgressMeter.pde
Created December 10, 2012 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beala/4249235 to your computer and use it in GitHub Desktop.
Save beala/4249235 to your computer and use it in GitHub Desktop.
Graphic showing how many months old you are compared to median and long lifespans
// Small changes to DrSkippy's code. Turns graph horizontal. Makes margins smaller.
// Original (https://gist.github.com/4057438) Blog (http://blog.drskippy.com/2012/11/11/age-visualization/)
import java.util.*;
import java.text.*;
int boxSize = 5; // pixel size of month representation
int boxSpacing = 4; // vertical and horizontal spacing
int decadeSpacing = 2*boxSpacing; // extra space between decades
int markerOverhang = 18;
int margin = 10;
int w;
// Ages
int age = 0;
int maxYears = 95;
int medianAge = 78;
String yourBirthday = "1988-10-03";
// Colors
int backShade = 65;
int fillShade = 240;
int strokeShade = 240;
int medianAgeShade = #70A070;
public static final int getMonthDiff(Date d1, Date d2) {
int m1 = d1.getYear() * 12 + d1.getMonth();
int m2 = d2.getYear() * 12 + d2.getMonth();
return m2 - m1;
}
public void setup() {
int h = int(2 * margin + (boxSize + boxSpacing) * 12 - boxSpacing + 1 );
w = int(2 * margin + maxYears * (boxSize + boxSpacing) + ((maxYears/10. - 1) * decadeSpacing) + 1);
Date bday = new Date();
try {
bday = new SimpleDateFormat("yyyy-MM-dd").parse(yourBirthday);
}
catch (ParseException e) {
println("Whups!");
}
Date today = new Date();
age = getMonthDiff(bday, today);
size(w, h);
//size(h, w);
}
public void draw() {
background(backShade);
int jump = 0;
for (int i = 0; i < maxYears; i++) {
if (i%10 == 0 && i != 0) {
jump += decadeSpacing;
}
int x = jump + margin + i * (boxSize + boxSpacing);
if (i == medianAge) {
stroke(medianAgeShade);
line(x - boxSpacing/2, margin - markerOverhang, x - boxSpacing/2, margin + 12 * (boxSize + boxSpacing) - boxSpacing + markerOverhang);
//line(margin - markerOverhang, w - x - boxSpacing/2, margin + 12 * (boxSize + boxSpacing) - boxSpacing + markerOverhang, w - x - boxSpacing/2);
}
for (int j = 0; j < 12; j ++ ) {
int y = margin + j * (boxSize + boxSpacing);
if (i*12 + (11-j) < age) {
stroke(fillShade);
fill(fillShade);
} else {
stroke(fillShade);
fill(backShade);
}
rect(x, y, boxSize, boxSize);
}
}
save("yourCurrentCalendar.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment