An incredibly basic turtle drawing tool I've built for making generative art with my BrachioGraph pen plotter.
Build a BrachioGraph and set it up with a Raspberry Pi according to the instructions.
The Python 3 script brachiosaurus.py
contained in this repository has no dependencies aside from the standard library. If you run it on a computer whose hostname is raspberrypi
, it'll dynamically attempt to import brachiograph
and draw the programmed pattern, otherwise it'll generate an SVG version (see above) instead and emit it on stdout
.
The Raspberry Pi hostname (and the BrachioGraph configuration – the default probably won't be accurate for your build) are configurable at the top of brachiosaurus.py
.
Copy brachiosaurus.py
to the directory on your Raspberry Pi in which you've installed the BrachioGraph software. With my setup, that's done like this:
scp ~/Dropbox/code/brachiosaurus/brachiosaurus.py pi@raspberrypi.local:/home/pi/BrachioGraph/
Place the code to generate the image you'd like to draw inside the main
function.
Similar to how you'd use the default BrachioGraph software – on your Raspberry Pi, after boot, run sudo pigpiod
to set up hardware servo timing. Then:
cd BrachioGraph
source bin/activate
python3 brachiosaurus.py
Alternatively, on your "development" machine where you haven't set up the BrachioGraph software, simply run
python3 brachiosaurus.py > ~/Desktop/preview.svg
and open preview.svg
in a web browser or other SVG viewer of your choice. This allows for fast and easy development of a complicated drawing without having to actually plot it until it's right, although I advise not previewing simpler ones – you never know which happy accidents you'd miss.
Not a bad idea at all! Create a file mydrawing.py
next to brachiosaurus.py
:
import brachiosaurus as bs # heartbreakingly, python won't accept 🦕 as an alias
c = bs.Canvas()
# turtle drawing commands go here
plotter = bs.AutoPlotter().from_canvas(c)
#plotter = bs.AutoPlotter().from_file("test-patterns/accuracy.json")
plotter.emit()
Then, as above, deploy this new file to your Raspberry Pi:
scp ~/Dropbox/code/brachiosaurus/mydrawing.py pi@raspberrypi.local:/home/pi/BrachioGraph/
And run it:
python3 mydrawing.py
.
Or run it without deployment:
python3 ~/Dropbox/code/brachiosaurus/mydrawing.py > ~/Desktop/preview.svg
Look no further than examples.py
– which has the same structure as the mydrawing.py
file outlined above and can be deployed and run in the same manner – where I've been collecting the code of some drawings I've made myself.
Alternatively, you can easily create your own examples using UJI, a generative art tool of my own design – it's able to export drawings in the JSON format supported by the AutoPlotter().from_file()
function.
The code is intentionally kept simple and extendible.
- Drawings are represented as lists of lines,
- lines are lists of points, and
- points are 2-ary lists of x and y coordinates.
If your plotter can be driven via Python and you're able to implement a function that translates this representation into whatever representation your plotter expects (see RealPlotter.emit
and FakePlotter.emit
), you should be golden. (Feel free to send a pull request!)
- Converting SVGs into the JSON format expected by this tool and the BrachioGraph software: https://github.com/Findus23/BrachioGraph-Utils
- Raster images can be vectorized using the built-in BrachioGraph tooling, see here: https://github.com/evildmp/BrachioGraph/blob/master/linedraw.py
- Advanced turtle drawing tool for AxiDraw plotters: https://github.com/fogleman/axi