PlotDevice is a Mac OS X application that lets you write Python scripts to produce 2D graphics. It provides a built-in editor and allows you to view your script’s results as you write it. The graphics that you ‘draw with code’ can be saved as PDFs, images, or even Quicktime/GIF animations.

## First Steps

The first thing you’ll want to do once you’ve downloaded the application is run some example scripts. There’s a folder with tons of sample code that can be accessed from the app’s Examples menu. Select one of them and press ⌘R to see it run (if the script is an animation, you can bring it to a halt by pressing ⌘.). Then try changing some numbers in the script and run it again to see what happens:

Next you’ll want to have a look at the reference to see what scripting commands are available and the sorts of parameters they accept. We’ll learn how to interpret the reference’s ‘syntax definitions’ in the chapter on drawing primitives. But in the meantime, skimming over the list of commands should give you a general sense of what’s possible.

PlotDevice commands let you draw primitive shapes (polygons, circles), create your own shapes (Bézier paths), transform the ‘canvas’ (rotate, scale, etc.), and work with content generated elsewhere (images & text).

## Learning the Ropes

After you’ve played around with the app for a bit, you should take a look at the other chapters in this Tutorial. They contain essential tips on how the commands work and how to use them in scripts of your own. To really understand what’s going on in your PlotDevice scripts, we recommend reading through at least:

- Environment: using the PlotDevice application to run scripts and export graphics.
- Primitives: the fundamental drawing commands and how to call them.
- Graphics State: how primitives are colored and transformed.
- Color: the many ways to specify colors.
- Bézier Paths: powerful (but low level) drawing commands.
- Typography: fonts, text, and typesetting.

Readers who are new to programming may also find the chapters on datatypes and control structures helpful:

- Variables: instead of plugging numbers directly into a command, you can also store them in a variable and then use the variable throughout your script.
- Collections: ‘lists’ & ‘dictionaries’ allow you to organize large amounts of information in a manageable way.
- Repetition: ‘loops’ let your code concisely do things more than once.
- Commands: defining custom ‘functions’ can simplify common tasks.

Seasoned Pythonistas (and `emacs` partisans) will want to take a look at:

- Console: running PlotDevice scripts from the command line and using the graphics routines from external Python scripts.
- Cocoa: taking advantage of native frameworks using the PyObjC bridge.

## PlotDevice is Python

The programming language that underlies PlotDevice is Python (created by Guido van Rossum in the early ’90s). Python emphasizes code readability and programmer productivity; qualities that make it an excellent choice for those just learning to program. These same traits also result in an expressive ‘sketching’ language that makes it easy to experiment in your code without being weighed down by syntactic bookkeeping.

The official documentation is thorough and highly-readable. If you’re just starting out, the Python Tutorial is a well-paced introduction to the language as well as general programming concepts. We like to keep these chapters on the nightstand:

- Control Flow: for-loops, if-statements, and def-statements
- More on Lists: interesting things you can do with list objects
- String Methods: extremely helpful text-processing utilities
- Built-ins: functions for basic math, inspecting objects, and more

Writing your scripts in Python also means being able to take advantage of the thousands of third-party libraries that have been written by the community. Try searching for a topic of interest at the Python Package Index. We bet you’ll be pleasantly surprised by the amount of code you won’t have to write.