data = loadTable('codes.csv', 'csv', 'header');
myFont = loadFont('medium.ttf');
createCanvas(windowWidth, windowHeight);
background(249, 244, 239);
colors = [color(230, 91, 32), color(7, 75, 247), color(228, 118, 48), color(247, 166, 67),
color(51, 147, 171), color(85, 91, 92), color(34, 36, 36)]
labels = ['Stayed Married', 'Divorced', 'Dating To Married', 'Stayed Dating', 'Broke Up', 'Widowed']
for (i = 0; i < 3; i++) {
for (i = 3; i < 5; i++) {
background(247, 243, 235);
type = row.getNum('type')
if (st == 'True' && type == 0) {
else if (st == 'False' && type >= 10) {
relationship_end(py, type/10)
else if (st == 'True' && type > 0) {
else if (st == 'True' && type == -1) {
else if (st == 'False' && type > 0 && type < 10) {
relationship_end(dy, type)
else if (st == 'False' && type < 0 && type > -10) {
else if (st == 'False' && type <= -10) {
passed_away(py, -1*type/10)
text('How Did 2660 Relationships', width/2, 80)
text('Change Over Time?', width/2, 115)
text('Press space to investigate a single relationship.', width/2, height-50)
timestamps = ['Feb 2009', 'March 2010', 'April 2011', 'March 2013', 'December 2014']
for (i = 1; i < 5; i++) {
text(timestamps[i], px[i] + 10, py - 70);
text('Married', 105, py);
for (i = 0; i < labels.length; i++) {
line(leg_x, leg_y, leg_x + line_length, leg_y)
text(labels[i], leg_x + line_length + 10, leg_y + 5);
line(linex, liney, linex+30, liney)
line(linex+30, liney-ydiff, linex+30, liney+ydiff)
line(linex+30, liney+ydiff, linex+40, liney+ydiff)
line(linex+30, liney-ydiff, linex+40, liney-ydiff)
fill(247, 243, 235, 150);
rect(0, 0, windowWidth, windowHeight)
row_index = int(random(0, rows.length))
type = row.getNum('type')
if (st == 'True' && type == 0) {
else if (st == 'False' && type >= 10) {
returnValue = relationship_end(py, type/10)
else if (st == 'True' && type > 0) {
else if (st == 'True' && type == -1) {
else if (st == 'False' && type > 0 && type < 10) {
returnValue = relationship_end(dy, type)
else if (st == 'False' && type < 0 && type > -10) {
returnValue = passed_away(dy, -1*type)
else if (st == 'False' && type <= -10) {
returnValue = passed_away(py, -1*type/10)
drawFinalText(st, type, returnValue);
function drawFinalText(st, type, returnValue) {
if (returnValue > 0 && returnValue < 1080) {
if (abs(type) > 10) t = abs(type)/10
if (st == 'True' && type == 0) {
text('This couple stayed married throughout.', width-50, py - offset);
else if (st == 'False' && type >= 10) {
text('This couple was married but then divorced.', x_loc, height - 50);
else if (st == 'True' && type > 0) {
text('This couple got married!', width-50, py - offset);
else if (st == 'True' && type == -1) {
text('This couple was dating throughout.', width-50, dy + offset);
else if (st == 'False' && type > 0 && type < 10) {
text('This couple was dating but then broke up.', x_loc, height - 50);
else if (st == 'False' && type < 0 && type > -10) {
text('One partner from this couple passed away.', x_loc, height - 50);
else if (st == 'False' && type <= -10) {
text('One partner from this couple passed away.', x_loc, height - 50)
function throughout(y_start) {
amplitude = randomGaussian(0, 25)
curveVertex(0, y + amplitude)
curveVertex(0, y + amplitude)
for (i = 0; i < 4; i += 1) {
if (i == 0) curveVertex(px[0], y + amplitude)
else curveVertex(px[i], y)
curveVertex((px[i] + px[i+1])/2, y + amplitude*(1.3-i*0.2))
curveVertex(px[4] + 180, y + amplitude)
curveVertex(windowWidth, y + amplitude)
curveVertex(windowWidth, y + amplitude)
function dating_to_married(time) {
amplitude = randomGaussian(0, 30)
curveVertex(0, y + amplitude)
curveVertex(0, y + amplitude)
for (i = 0; i < time; i += 1) {
if (i == 0) curveVertex(px[0], y + amplitude)
else curveVertex(px[i], y)
curveVertex((px[i] + px[i+1])/2, y + amplitude)
for (i = time; i < 4; i += 1) {
curveVertex((px[i] + px[i+1])/2, y + amplitude)
curveVertex(windowWidth, y + randomGaussian(0, 5))
curveVertex(windowWidth, y + randomGaussian(0, 5))
function relationship_end(y, time) {
amplitude = randomGaussian(0, 25)
curveVertex(0, y + amplitude)
curveVertex(0, y + amplitude)
for (i = 0; i < time; i += 1) {
if (i == 0) curveVertex(px[0], y + amplitude)
else curveVertex(px[i], y)
curveVertex((px[i] + px[i+1])/2, y + amplitude)
x_dest = px[time] + random(100, 270)
curveVertex(x_dest, height)
curveVertex(x_dest-100, height)
function passed_away(y, time) {
amplitude = randomGaussian(0, 25)
for (i = 0; i < time; i += 1) {
curveVertex((px[i] + px[i+1])/2, y + amplitude)
x_dest = px[time] + random(70, 100)
curveVertex(x_dest, height)
curveVertex(x_dest-100, height)