Partial explainer of what that code does: https://twitter.com/justvanrossum/status/1192324084656476160
Posts made by justvanrossum
-
RE: A little arcTo() and geometry help?posted in General Discussion
-
RE: A little arcTo() and geometry help?posted in General Discussion
@MauriceMeilleur Have a look at https://github.com/typemytype/outlinerRoboFontExtension/blob/master/Outliner.roboFontExt/lib/outlinePen.py#L518 which solves more or less the same problem. Esp. the
handleLengthpart should be of interest to you. -
RE: Using a virtualenv in Drawbotposted in General Discussion
Oh, I've been trapped by a bot it seems
Still, my answer may be useful 
-
RE: Using a virtualenv in Drawbotposted in General Discussion
Oh, that's a clever idea, thanks for sharing.
... said in Using a virtualenv in Drawbot:
import sys
sys.path.insert(0, "/Users/maartenidema/t_venv/lib/python3.6/site-packages")You should be able to make that happen automatically. Please try the following:
- Create a folder called
/Library/Python/3.6/site-packagesif it doesn't already exists - place a file in there with a
.pthextension, saymy_venv.pth - write the line
/Users/maartenidema/t_venv/lib/python3.6/site-packagesinto that file - Restart DrawBot and see if you can now import from your venv.
Sorry, I didn't test this. Please let us know if it works.
- Create a folder called
-
Rotating arrows exerciseposted in Tutorials
This is by no means an original idea, but it's a fun thing to program.
Triggered by Mike Duggan: https://twitter.com/mickduggan/status/1090577885067386880

# triggered by Mike Duggan: # https://twitter.com/mickduggan/status/1090577885067386880 def arrow(center, size, rotation, barThickness, arrowhead): with savedState(): translate(*center) scale(size) rotate(rotation) points = [ (-0.5, barThickness/2), (0.5 - arrowhead, barThickness/2), (0.5 - arrowhead, 0.5), (0.5, 0), (0.5 - arrowhead, -0.5), (0.5 - arrowhead, -barThickness/2), (-0.5, -barThickness/2), ] polygon(*points) def arrowGrid(numArrows, arrowSize, barThickness, arrowhead, rotation): for i in range(numArrows): x = i * arrowSize for j in range(numArrows): y = j * arrowSize arrow((x, y), arrowSize, rotation, barThickness, arrowhead) def easeInOut(t): assert 0 <= t <= 1 return (1 - cos(t * pi)) / 2 canvasSize = 400 numArrows = 4 arrowSize = canvasSize / numArrows barThickness = 0.5 arrowhead = 0.5 rotation = 180 duration = 4 framesPerSecond = 15 numFrames = duration * framesPerSecond for frame in range(numFrames): t = 4 * frame / numFrames quadrant = floor(t) t = easeInOut(t % 1) angle = ((quadrant + t) * 90) % 380 flip = quadrant % 2 angle = -angle newPage(canvasSize, canvasSize) frameDuration(1/framesPerSecond) if flip: fill(1) rect(0, 0, canvasSize, canvasSize) fill(0) arrowGrid(numArrows + 1, arrowSize, barThickness, arrowhead, angle) else: fill(0) rect(0, 0, canvasSize, canvasSize) fill(1) translate(-arrowSize/2, -arrowSize/2) arrowGrid(numArrows + 2, arrowSize, 1 - barThickness, arrowhead, angle + 180) saveImage("Arrows.gif") -
RE: qCurveposted in General Discussion
@mauricemeilleur You're seeing the representation of your shape as cubic beziers. The quads get converted to cubic because the underlying NSBezierPath doesn't support quadratic curves.
-
RE: qCurveposted in General Discussion
@mauricemeilleur It's part of the "pen protocol" which lives in with FontTools, so any documentation should go there. It's documented in the code, have a look at the
basePen.pymodule:The main trick for the blobs is indeed the fact that the contour will have no on-curve points, and that is achieved by passing
Noneas the last argument topen.qCurveTo(). -
RE: Drawing glyphs from ufo file.posted in General Discussion
@rafalbuchner This should work:
def drawGlyph(g): bez = BezierPath() g.draw(bez) drawPath(bez) -
RE: How to run Drawbot on a server: Does it is possible?posted in General Discussion
@agyei Sounds like that should work.
-
RE: listFontGlyphNames() returning Alphabetical order?posted in General Discussion
@guidoferreyra It looks like DrawBot could be changed to do that, yes. Please file an issue on github. In the meantime, you could do it yourself via fontTools:
from fontTools.ttLib import TTFont font("AGaramondPro-Regular") f = TTFont(fontFilePath()) print(f.getGlyphOrder()) -
RE: Making new librariesposted in General Discussion
Alternatively you can park your module in
/Library/Python/3.6/site-packages/(If using Py 3.6.) If that folder doesn't exist, you can create it manually. DrawBot will find it. -
RE: Making new librariesposted in General Discussion
The
from . import mymodulenotation is only for relative imports within packages.The easiest way is indeed to put your module in the same folder as the main script. But just write
import mymoduleorfrom mymodule import nameinmymodule.Note that imports ae cached: if you change your module, the main script won't see those changes until you reload your module (or restart DrawBot).
-
A grid of animated spiralsposted in Code snippets

def spiral(cx, cy, diameter, angle): with savedState(): translate(cx, cy) scale(diameter / 1000) for i in range(100): rect(406, 0, 95, 95) rotate(angle) scale(0.99) gridSize = 100 margin = 50 canvasSize = 500 numFrames = 40 for frame in range(numFrames): t = frame / numFrames newPage(canvasSize, canvasSize) frameDuration(1/20) fill(0) rect(0, 0, canvasSize, canvasSize) fill(1) translate(margin, margin) for i in range(5): for j in range(5): a = 2 * pi * (t + (i + j) / 8) angle = 31 + 2 * sin(a) spiral(i*gridSize, j*gridSize, 95, angle) saveImage("~/Desktop/SpiralGrid.gif") -
RE: SSL Error (known SSL OSX issue?)posted in Bugs
The link you reference indeed explains the problem. I tried the first solution but it doesn't help. I don't have that command file in my machine to try that.
-
RE: Windows minimizing and re-expanding after completing scriptposted in Bugs
@mauricemeilleur Hm, I've never seen this happen.
-
RE: image Object should have imagePixelColor methodposted in Feature Requests
You can pass an ImageObject to
imagePixelColor():im = ImageObject() with im: fill(1, 0, 0) rect(100, 100, 200, 200) print(imagePixelColor(im, (150, 140))) -
RE: SSL Error (known SSL OSX issue?)posted in Bugs
@chuckloyola It fails for me in the same way, but also in Terminal. I have no idea why. It's more a general Python issue rather than one with DrawBot it seems.