Last active
March 18, 2018 20:18
-
-
Save oprypin/819b1bfc8e98d7412b80dfce4e8d99ef to your computer and use it in GitHub Desktop.
https://www.reddit.com/r/vexillologycirclejerk/comments/84dpgu/ultra_sweden_sweden_but_we_must_go_deeper/dvov878/ https://www.reddit.com/r/eyehurtingflags/comments/7w4ing/my_improved_swedish_flag/dtyiuqr/
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
#!/usr/bin/env python3 | |
# for i in {1..10}; do echo $i; python3 supersweden.py $i; done | |
import sys | |
import cairo | |
level = int(sys.argv[1]) | |
size = (1600, 1000) | |
dx = (5, 2, 9) | |
dy = (4, 2, 4) | |
blue = (0, 106, 168) | |
yellow = (254, 205, 0) | |
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, *size) | |
g = cairo.Context(surface) | |
g.rectangle(0, 0, *size) | |
g.set_source_rgb(*(c/255 for c in blue)) | |
g.fill() | |
g.set_source_rgb(*(c/255 for c in yellow)) | |
def draw(x, y, zx, zy, level): | |
if level == 0: | |
return | |
dx1, dx2, dx3 = [zx*d/sum(dx) for d in dx] | |
dy1, dy2, dy3 = [zy*d/sum(dy) for d in dy] | |
ddx = dx1+dx2 | |
ddy = dy1+dy2 | |
g.rectangle(x+dx1, y, dx2, zy) | |
g.rectangle(x, y+dy1, zx, dy2) | |
g.fill() | |
draw(x , y , dx1, dy1, level-1) | |
draw(x+ddx, y , dx3, dy1, level-1) | |
draw(x , y+ddy, dx1, dy3, level-1) | |
draw(x+ddx, y+ddy, dx3, dy3, level-1) | |
draw(0, 0, *size, level) | |
surface.write_to_png(f's{level}.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment