Created
February 10, 2014 13:03
-
-
Save bgnori/8915544 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 | |
def blend(p, q, t): | |
""" | |
>>> blend((1.0, 1.0), (1.0, 2.0), 0) | |
(1.0, 1.0) | |
>>> blend((1.0, 1.0), (1.0, 2.0), 1) | |
(1.0, 2.0) | |
>>> blend((1.0, 1.0), (1.0, 2.0), 0.4) | |
(1.0, 1.39999...) | |
""" | |
return (p[0] * (1-t) + q[0] * t), (p[1] * ( 1- t) + q[1] * t) | |
im = Image.new("RGB", (512, 512), "white") | |
draw = ImageDraw.Draw(im) | |
p = (100, 100) | |
q = (400, 200) | |
r = (200, 400) | |
for t in range(0, 1000): | |
draw.point(blend(blend(p, q, t/1000.0), blend(q, r, t/1000.0), t/1000.0), | |
fill=128) | |
with open("bezier.png", "w") as f: | |
im.save(f, "PNG") | |
#import doctest | |
#doctest.testmod() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result
http://gyazo.com/3180ea55d085271dea136925165f341c.png