Partial explainer of what that code does: https://twitter.com/justvanrossum/status/1192324084656476160
Posts made by justvanrossum
-
RE: A little arcTo() and geometry help?
-
RE: A little arcTo() and geometry help?
@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
handleLength
part should be of interest to you. -
RE: Using a virtualenv in Drawbot
Oh, I've been trapped by a bot it seems Still, my answer may be useful
-
RE: Using a virtualenv in Drawbot
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-packages
if it doesn't already exists - place a file in there with a
.pth
extension, saymy_venv.pth
- write the line
/Users/maartenidema/t_venv/lib/python3.6/site-packages
into 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 exercise
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: qCurve
@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: qCurve
@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.py
module: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
None
as the last argument topen.qCurveTo()
. -
RE: Drawing glyphs from ufo file.
@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?
@agyei Sounds like that should work.
-
RE: listFontGlyphNames() returning Alphabetical order?
@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 libraries
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 libraries
The
from . import mymodule
notation 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 mymodule
orfrom 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 spirals
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?)
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 script
@mauricemeilleur Hm, I've never seen this happen.
-
RE: image Object should have imagePixelColor method
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?)
@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.