Skip to content

Instantly share code, notes, and snippets.

@jul
Last active Mar 20, 2016
Embed
What would you like to do?
We don't need an OOP class called point or rectangle
from PIL import Image, ImageDraw
from cmath import pi as PI, e as E
I = complex("j")
to_x_y = lambda cpl : (cpl.real, cpl.imag)
im = Image.new("RGB", (512, 512), "white")
draw = ImageDraw.Draw(im)
rotation = E**(I*PI/3)
homothetia = min( im.size[0], im.size[1])
# to bored to be smart, random guessing
trans = homothetia/2
homothetia /= 2.5
# lazyness off
polygone = ( complex(0,0), complex(0,1), complex(1,1), complex(1,0), complex(0,0) )
bigger = map(lambda x: x * homothetia + trans , polygone )
bigger_rotated = map(lambda x: x * rotation, bigger )
draw.line(map(to_x_y, bigger),"blue")
draw.line(map(to_x_y, bigger_rotated),"green")
im.save("this.png", "PNG")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment