Simple experiment: redrawing an arbitrary image using turtle graphics. Implemented in Fall 2016 in order to get students excited about Scheme recursive art. The idea was that I'd take a picture of the class and then let the turtle draw it (with my screen projected, so everyone could watch) over the course of the period.
Of course, it was never necessary to involve Scheme. In the interest of the general, non-Scheming population, I've added a version of the code that uses Python only. This is currently the standard version.
git clone https://github.com/ohjay/turtledraw.git
cd turtledraw
pip install -r requirements.txt
- Python (must be 3.4+ if the ability to save as PNG is desired)
- NumPy
- canvasvg
- CairoSVG (if Python 3)
Technically, everything can be run with Python 2.7 as well. However, images will be saved as SVGs instead of PNGs.
OSError: dlopen() failed to load a library: cairo / cairo-2
Try runningbrew install python3 cairo pango gdk-pixbuf libffi
.
Use this online tool. (Do use this one; the code is meant to run with the SVG spec associated with this tool specifically.)
Modify the parameters at the top of svgparse.py
as desired, then run
python3 svgparse.py <path_to_svg_file>
python3 svgparse.py --scheme <path_to_svg_file>
Why Scheme? The original purpose of this project was to promote the Scheme recursive art contest. Accordingly, I meant to show people the kinds of things they could do with their personal Project 4 [Scheme] interpreters.
Run the file using the Scheme interpreter from Berkeley's CS 61A (unfortunately, you'll have to implement this yourself; the project is reused every semester so I can't be posting the solution on GitHub). Note that my code does rely on having the 61A distribution of Scheme.
Alternatively, you can paste the generated code into Jen's online interpreter.
Many input images have been provided in the in
folder as examples. Note: with the exception of bird.jpg
, all in/*.jpg
photographs were taken by Tonya Nguyen. (Also, speaking of bird.jpg
, its redraw output looks a lot better if the cubic_unfinished
parameter is set to True
.)
cd turtledraw
python3 svgparse.py in/*.svg
cd turtledraw
python3 svgparse.py --scheme in/*.svg
python3 scheme/scheme.py out/*.scm
Note: the parameters can make a big difference in the style and quality of the output, as evidenced below.