Created
May 16, 2014 08:12
-
-
Save tsuyukimakoto/f39aa6d222270fc5b9d4 to your computer and use it in GitHub Desktop.
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
from PIL import Image, ImageDraw | |
X = 0 | |
Y = 1 | |
def position_by_ratio(p1, p2, ratio): | |
# divide returns float with Python3 | |
return p1[X] + ((p2[X] - p1[X]) * (ratio/100)), p1[Y] + ((p2[Y] - p1[Y]) * (ratio/100)) | |
def bezier_position_by_ratio(p1, p2, p3, p4, ratio): | |
p5 = position_by_ratio(p1, p2, ratio) | |
p6 = position_by_ratio(p2, p3, ratio) | |
p7 = position_by_ratio(p3, p4, ratio) | |
p8 = position_by_ratio(p5, p6, ratio) | |
p9 = position_by_ratio(p6, p7, ratio) | |
return position_by_ratio(p8, p9, ratio) | |
if __name__ == '__main__': | |
im = Image.new('RGBA', (600, 600), (255,255,255,0)) | |
draw = ImageDraw.Draw(im) | |
x1 = (0,600 - 0) | |
x2 = (100, 600 - 550) | |
x3 = (400, 600 - 400) | |
x4 = (600, 600 - 50) | |
_pos = x1 | |
for i in range(1, 101): | |
pos = bezier_position_by_ratio(x1, x2, x3, x4, i) | |
draw.line((_pos, pos)) | |
_pos = pos | |
im.save('bezier.png', "PNG") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment