Code Monkey home page Code Monkey logo

turtledraw's Introduction

turtledraw

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.

bird

Setup

git clone https://github.com/ohjay/turtledraw.git
cd turtledraw
pip install -r requirements.txt

Requirements

Technically, everything can be run with Python 2.7 as well. However, images will be saved as SVGs instead of PNGs.

Troubleshooting

  • OSError: dlopen() failed to load a library: cairo / cairo-2
    Try running brew install python3 cairo pango gdk-pixbuf libffi.

Usage

1. To vectorize an image as an SVG file

Use this online tool. (Do use this one; the code is meant to run with the SVG spec associated with this tool specifically.)

2. To draw an SVG file using turtle graphics (no Scheme involved)

Modify the parameters at the top of svgparse.py as desired, then run

python3 svgparse.py <path_to_svg_file>

2b. To convert an SVG file to Scheme turtle code

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.

3b. To run the Scheme turtle code

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.

Examples

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.)

no Scheme
cd turtledraw
python3 svgparse.py in/*.svg
Scheme
cd turtledraw
python3 svgparse.py --scheme in/*.svg
python3 scheme/scheme.py out/*.scm

examples 5, 19, 27, 32, 37 examples 4, 6, 7, 16, 12, 23

Note: the parameters can make a big difference in the style and quality of the output, as evidenced below. example 41

turtledraw's People

Contributors

ohjay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.