drawbot
drawbot copied to clipboard
add methods to fit and center the bezierpath to a given bounds
I've used these many times and I thought it could be useful to be added to the BezierPath object. I hope it's not too arbitrary!
Also if you think this can be added, I think alignTop, alignBottom, etc to a given bound is also useful.
test case:
from drawBot import *
from datetime import datetime
size(800, 800)
b = BezierPath()
b.oval(234, 324, 345, 342)
fill(None)
stroke(0)
b2 = BezierPath()
b2.rect(200, 200, 400, 400)
b.fit(b2.bounds())
drawPath(b2)
drawPath(b)
import os, subprocess
fn = os.path.split(os.path.realpath(__file__))[1] + datetime.now().strftime("%Y|%m|%d-%H%M%S")
saveImage(f"{fn}.pdf")
subprocess.call(['open', "%s.pdf" %fn])
After a bit of thinking, maybe align to a path is better than bounds. Then there can be a method as alignToPath(other_path, "center") which does the job?
After a bit of thinking, maybe align to a path is better than bounds.
Hm, I don't think so. I want to think a bit more about this PR. The base idea is good, and I've used similar things (but not exactly the same :) ) a lot before, so I agree something like this is useful.
Are you interested in continuing/finishing this PR? If not, we should probably close.