DrawBot Documentation

repository·master·Indexed 19 days ago

https://github.com/typemytype/drawbot

DrawBot is a macOS application and Python module for generating 2D graphics via scripting. It supports paths, text, and colors, with export capabilities for PDF, SVG, PNG, and video. The library provides a Canvas abstraction for managing drawing surfaces, geometric transformations, and a comprehensive color system including CMYK for print-ready exports. It can be used as a standalone Python module (requiring Python 3.11+) or compiled as a full application with a UI.

Tokens
11K
Snippets
51
Records
85
Agent score
65%

What's inside DrawBot

  1. Overview of DrawBot

    master

    DrawBot is a macOS application used to generate two-dimensional graphics via Python scripts. It provides built-in graphics primitives including:

    • Rectangles
    • Ovals
    • (Bezier) paths
    • Polygons
    • Text objects
    • Transparency support

    Results can be exported in various formats such as high-resolution scalable PDF, SVG, movie, PNG, JPEG, and TIFF.

  2. Understand the DrawBot App interface

    master

    The DrawBot application consists of three primary views for writing, debugging, and visualizing code:

    1. Code Editor: The primary interface for writing and editing your Python scripts.
    2. Output View: Displays print statements and tracebacks (error reports) when scripts fail.
    3. Preview: Provides a live preview of the current page and all generated pages (useful for multi-page documents).
  3. Create and manipulate Bezier paths in drawBot

    master

    drawBot provides a suite of functions to create, manipulate, and render Bezier paths. You can create a new path object using drawBot.newPath() and then define its shape using various drawing commands like moveTo, lineTo, curveTo, and arc. Once a path is defined, it can be rendered to the canvas using drawBot.drawPath() or used to define a clipping area via drawBot.clipPath().

    # Conceptual workflow for drawing a path
    path = drawBot.newPath()
    path.moveTo(100, 100)
    path.lineTo(200, 200)
    drawBot.drawPath(path)
  4. Understand the Canvas abstraction in DrawBot

    master

    The Canvas represents the drawing surface in DrawBot, acting as the document size or art board. It is defined by a specific height and width.

    Note that the canvas dimensions are independent of the application window size; changing the window size does not change the canvas dimensions, and vice versa.

  5. Using DrawBot as a Python module

    master
    DrawBot is written in Python. While the standard binary download is a fully self-contained application that does not require a pre-existing Python installation, you can also use the source code to build your own environment or integrate it into your workflows.
  6. Navigate the Preview area in DrawBot

    master

    The Preview area displays your generated graphics. You can interact with the canvas using the following controls:

    • Zooming: Use Cmd+ to increase the zoom level and Cmd- to decrease it.
    • Multi-page Visualization: For documents with multiple pages, right-click on a page to toggle between:
      • Single page vs. Double pages
      • Continuous vs. Individual page views.
  7. Compile DrawBot.app (with UI) from source

    master

    To build the full DrawBot application package for macOS using py2app, you must first install several dependencies.

    Required packages:

    • vanilla
    • defcon
    • defconAppKit
    • fonttools
    • pygments
    • jedi
    • booleanOperations
    • mutatorMath
    • woffTools
    • compositor
    • feaTools2
    • ufo2svg
    • PyObjC
    • PIL (only required for running tests)

    Compilation steps:

    cd path/To/drawBot
    python setupApp.py py2app
  8. Use DrawBot for Python programming instruction

    master
    DrawBot is designed as a teaching tool that combines Python with a compact application where code, results, and feedback are visible simultaneously. It is suitable for introducing basic programming concepts like math, strings, variables, lists, loops, functions, and conditions through visual feedback.