Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Visual aid for life planning
#!/usr/bin/python2
import cairo
from datetime import date, timedelta
import random
WIDTH, HEIGHT = 300, 860
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)
ctx.scale(WIDTH, WIDTH)
START_DATE = date(1993, 1, 1)
CHECKPOINT_1 = date(2015, 12, 14)
TODAY = date.today()
END_DATE = date(2071, 1, 1)
date = START_DATE
row = 0
column = 0
COLUMNS = 100
PADDING_TO_COLUMN_WIDTH = 0.25
COLUMN_WIDTH = 1.0 / (PADDING_TO_COLUMN_WIDTH * (COLUMNS - 1) + COLUMNS)
PADDING_WIDTH = COLUMN_WIDTH * PADDING_TO_COLUMN_WIDTH
ROW_HEIGHT = COLUMN_WIDTH
while date < END_DATE:
def draw_rect():
ctx.rectangle(column * (COLUMN_WIDTH + PADDING_WIDTH),
row * (ROW_HEIGHT + PADDING_WIDTH),
COLUMN_WIDTH,
ROW_HEIGHT)
if date < CHECKPOINT_1:
# past: yellow
ctx.set_line_width(0.001)
ctx.set_source_rgb(0, 0, 0)
draw_rect()
ctx.stroke()
ctx.set_source_rgb(0.8, 0.8, 0)
draw_rect()
ctx.fill()
elif date == CHECKPOINT_1:
# today: red
ctx.set_source_rgb(0.8, 0, 0)
draw_rect()
ctx.fill() elif date < TODAY:
# past: yellow
ctx.set_line_width(0.001)
ctx.set_source_rgb(0, 0, 0)
draw_rect()
ctx.stroke()
ctx.set_source_rgb(1, 1, 0)
draw_rect()
ctx.fill()
elif date == TODAY:
# today: red
ctx.set_source_rgb(1, 0, 0)
draw_rect()
ctx.fill()
else:
# future: white
ctx.set_line_width(0.001)
ctx.set_source_rgb(0, 0, 0)
draw_rect()
ctx.stroke()
ctx.set_source_rgb(1, 1, 1)
draw_rect()
ctx.fill()
column += 1
if column == COLUMNS:
row += 1
column = 0
date += timedelta(days=1)
surface.write_to_png("advent.png")

janbok commented Feb 10, 2017

Line 49: elif section should be moved to the next line, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment