Last active
September 29, 2019 01:01
-
-
Save mkfink/9940ed027861b8252f6e485ee4fd8eb5 to your computer and use it in GitHub Desktop.
create thermometer fundraiser graphic
This file contains 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
import svgwrite | |
def make_therm(fn, total, goal): | |
xcen = 300 | |
ory = 75 | |
ylen = 600 | |
xwid = 100 | |
rad = 100 | |
stroke = 10 | |
overlap = 25 | |
maxtherm = ylen + ory - xwid/2 | |
tikwid = 50 | |
tikh = 10 | |
tikx = xcen - xwid/2 - tikwid - 2* stroke | |
goal_scaled = goal / (ylen + overlap) | |
progress_scaled = total / goal_scaled | |
matchh = ylen / 5 | |
# create the static thermomstat | |
dwg = svgwrite.Drawing(filename=fn, size=(xcen * 2, ylen + 3 * rad)) | |
dwg.add(dwg.rect((xcen - xwid / 2 - stroke, ory), (xwid + 2 * stroke, ylen + overlap), fill='black')) | |
dwg.add(dwg.circle(r=rad + stroke, center=(xcen, ory + ylen + rad), fill='black')) | |
dwg.add(dwg.circle(r=xwid/2 + stroke, center=(xcen, ory), fill='black')) | |
dwg.add(dwg.rect((xcen - xwid / 2, ory), (xwid, ylen + overlap), fill='white')) | |
dwg.add(dwg.circle(r=xwid/2, center=(xcen, ory), fill='white')) | |
dwg.add(dwg.circle(r=rad, center=(xcen, ory + ylen + rad), fill='red')) | |
# fill in progress, and if we hit the top, fill in the top circle | |
# also add a pink rectangle for the bonus match or add extra 10k if match is met | |
if total < 9000: | |
dwg.add(dwg.rect((xcen - xwid/2, ory + ylen + overlap - progress_scaled), (100, progress_scaled), fill='red')) | |
elif total >= 9000 and total < 19000: | |
dwg.add(dwg.rect((xcen - xwid/2, ory + ylen + overlap - progress_scaled), (100, progress_scaled), fill='red')) | |
dwg.add(dwg.rect((xcen - xwid/2, ory + ylen + overlap - progress_scaled - matchh), (100, matchh), fill='pink')) | |
dwg.add(dwg.text('BONUS', | |
insert=(xcen + xwid/3, ory + ylen + overlap - progress_scaled - matchh + 15), | |
font_family='Arial', | |
font_size='24px', | |
font_weight='bold', | |
text_anchor='start', | |
writing_mode='tb')) | |
dwg.add(dwg.text('MATCH!', | |
insert=(xcen + xwid/8, ory + ylen + overlap - progress_scaled - matchh + 15), | |
font_family='Arial', | |
font_size='24px', | |
font_weight='bold', | |
text_anchor='start', | |
writing_mode='tb')) | |
elif total >= 19000 and total < 40000: | |
dwg.add(dwg.rect((xcen - xwid/2, ory + ylen + overlap - progress_scaled), (100, progress_scaled), fill='red')) | |
dwg.add(dwg.rect((xcen - xwid/2, ory + ylen + overlap - progress_scaled - matchh), (100, matchh), fill='red')) | |
elif total >= 40000: | |
dwg.add(dwg.rect((xcen - xwid/2, ory + ylen + overlap - maxtherm), (100, maxtherm), fill='red')) | |
dwg.add(dwg.circle(r=xwid/2, center=(xcen, ory), fill='red')) | |
# add tick marks | |
for n, y in enumerate(list(range(ory, ory + ylen - tikh, int((ylen + overlap - tikh)/10)))): | |
dwg.add(dwg.rect((tikx+60, y + 7.5), (tikwid,tikh), fill='black', rx=5, ry=5)) | |
num = 50000 - (5000 * n) | |
text = f'${num:,}' | |
dwg.add(dwg.text(text, | |
insert=(xcen-xwid/2 - 2 * stroke, y + 20), | |
font_family='Arial', | |
font_size='24px', | |
font_weight='bold', | |
text_anchor='end' | |
)) | |
dwg.save() | |
if __name__ == "__main__": | |
make_therm('thermometer.svg', 10000, 50000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment