Giter Club home page Giter Club logo

blackstripes-python-extensions's Introduction

Blackstripes python extensions

Your drawbot will like it!

This is a python module written in c. It turns an png image into a svg line drawing. The output is very suitable for vsg capable drawbots. We use it every day on blackstripes.nl.

This also comes with a command-line interface for using it, installed at the same time as the python module. Check blackstripes --help for detailed usage.

How to use

This module exposes 3 drawing styles.

1. Sketchy

from blackstripes import sketchy

sketchy.draw("ali.png",                 # input
         	 "ali_sketchy.svg",         # output
            1,                          # nibsize (line size in output svg)
            100,                        # max line length
            "#000000",                  # line color
            0.32,                       # scaling factor
            1,                          # line size (internal line size for calculations)
            540, 1021, 0.7              # signature transform tx, ty, scale
        )

Using the CLI:

blackstripes sketchy ali.png --output ali_sketchy.svg

example

How does it work
  1. Calculate the brightness of the input image.
  2. Place the pen at pixel 0,0.
  3. Get a random line length between 10 and the max segment length.
  4. Evaluate 360 lines by making a 360 degree sweep with the selected line length.
  5. Get the line covering the largest average darkness in the input image.
  6. Draw this line white in the input image.
  7. Draw this line black in the ouput image.
  8. Calculate the brightness of the output image.
  9. Repeat from step 2 until the brightness of the output image is equal to the inpute image.

2. Crossed

from blackstripes import crossed

crossed.draw("ali.png",             # input
        	 "ali_crossed.svg",     # output
            2.0,                    # nibsize (line size in output svg)
            "#2200aa",              # line color
            0.32,                   # scaling factor
            200, 146, 110, 56,      # levels
            2,                      # type
            540,1021,0.7            # signature transform
        )

Using the CLI:

blackstripes crossed ali.png --output ali_sketchy.svg

example

3. Spiral

from blackstripes import spiral

spiral.draw("ali.png",                  # input
       	    "ali_spiral.svg",           # output
            2.0 ,                       # nibsize (line size in output svg)
            "#aa0000",                  # line color
            0.32,                       # scaling factor
            180, 108, 180, 108,         # levels
            2,                          # linespacing
            540,1021,0.7                # signature transform
        )

Using the CLI:

blackstripes spiral ali.png --output ali_sketchy.svg

example

How to build

(This module is tested with python 2.7 and python 3.4 on mac-osx and linux, but it will probably work on most platforms.)

  1. Clone this repo
  2. navigate to the src folder
  3. python setup.py build
  4. python setup.py install
  5. navigate to the test folder
  6. python sketchy-test.py
  7. python crossed-test.py
  8. python spiral-test.py

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.