Skip to content

Instantly share code, notes, and snippets.

@bgnori
Created February 10, 2014 13:03
Show Gist options
  • Save bgnori/8915544 to your computer and use it in GitHub Desktop.
Save bgnori/8915544 to your computer and use it in GitHub Desktop.
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()
@bgnori
Copy link
Author

bgnori commented Feb 10, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment