Do you want to draw some cool pictures with a few lines of Python code? SketchPy is here to help..Sketchpy is a Python module for animating drawings of images. The sketchpy module is created on top of the turtle module in Python.

MRMYSTERY003 MRMYSTERY003 Last update: Apr 07, 2024

Welcome to sketchpy

Description

This is the Intermediate level python project to do some awesome drawing animation using the turtle module, hope it grows in the future. It is a Python module for animating drawings of images. The sketchpy module is created on top of the turtle module in Python. To install sketchpy on your computer, you can go to your command prompt (command line) and run the following command.

Usage

  • Just install the package pip install sketchpy
  • Followed by pip install --upgrade sketchpy to update the package to the latest version.
  • Import it to you project import sketchpy and use as you want😊

Built with

  • Turtle
  • Open-cv
  • Pillow
  • numpy
  • Svgpathtools

Getting started

Lastes version of sketchpy: 0.1.8

  • you can install the latest version with either
    pip install sketchpy==0.1.8

or

    pip install sketchpy --U

Updates!!

  • This version 0.1.8 uses multiprocessing for processing the single svg file in 4 different threads to reduce the time for loading the svg file
  • Sample
  • And I have included a new function named get_svg() from utils to convert your Image to svg, this function opens your default web browser to get you to the best svg converting website
  • You can use the function as followes
        from sketchpy import canvas
        canvas.get_svg()
    

Prerequisites

  • Python
  • Basic text editor
  • creativity😂

Install

    pip install sketchpy

it should probably work, If not then try the following code

    pip install turtle open-cv wheel sketchpy

Library Example

Open your code editor and write the example Python code snippets given below. Run your code and see the magic by yourself.

Drawing Robert Downey Jr. Using Python

    from sketchpy import library as lib
    obj = lib.rdj()
    obj.draw()

OUTPUT

Drawing Tom Holland Using Python

    from sketchpy import library
    myObject = library.tom_holland()
    myObject.draw()

OUTPUT

More examples

    from sketchpy import library as lib
    
    obj = lib.bts()
    obj.draw()
    from sketchpy import library as lib

    obj = lib.vijay()
    obj.draw()

Drawing Iron Man ASCII Animation Using Python

    from sketchpy import library
    myObject = library.ironman_ascii()
    myObject.draw()

OUTPUT

Trace from Image

The recent version of the package includes a class named trace_from_image(), which allowes you to get the same output as using a svg file without the need to convert it to a svg file. hecnce it reduces the run time and it is much effecient.

  • To know more about this new class visit the blog post here.
  • A sample output of the class trace_from_image().
  • you can take a view about how the class working in here

Sample Code:

    from sketchpy impor canvas
    obj = canvas.trace_from_image("Image Path")
    obj.draw()

Parameters :

- Path: Path of the image
- Scale:
      -scaling factor for the sketched image,
      - less than 1 => smaller than original image
      - equal to 1 => original size
      - greater than 1 => greater than original image

- intensity -> intensity of details, keep the value between 0 and 255, optimal value lies between(200 - 255)
- save -> take a screenshot when the program stops sketching, false by default

Sketch from Image

used to trace the image line by line.

Example Code :

    from sketchpy impor canvas
    obj = canvas.sketch_from_image("Image Path")
    obj.draw(threshold = 127)

Parameters

- path -> path of the image
- save -> used to same the results

you can watch the example video from here

NOTE: you can change the value of threshold to draw more detailed image, it's range is 0 - 255,use values between 90-190

to know more about it visit here

Drawing From SVG file

You can sketch image uinsg the class color_sketch_from_svg, which takes the inpu in svg formate and then sketches it. Example Code:

    from sketchpy impor canvas
    obj = canvas.color_sketch_from_svg("Image Path")
    obj.draw()

Example output

NOTE: sketch_from_svg class is remove from the package, since it can only draw with single color, color_sketch_from_svg class will be available.

Parameters

- color_sketch_from_svg
    - path -> path of the svg file
    - scale -> zoom value
    - x_offset -> amount of movemnt in x direction
    - y_offset -> amount of movemnt in y direction
    - save -> (True by defaule)= take a screenshot and save it
- load_svg
    - file_name -> name of the npy array, you can use this array data to sketch images directly
- draw
    - retain -> retain the window after sketching (true by defaule)
    - file -> file path of the npy file for direct sketching
    - data -> raw data,  should be a list in [[[x1,y1], [x2,y2], ....], [255,255,255]], first nested list is the points and the second list the color
    - x_offset -> amount of movement in x direction while sketching
    - y_offset -> amount of movement in y direction while sketching
    - scale -> zoom value while sketching
    - speed -> speed of sketching

Sketching form .npy file

Insted of waiting for the svg file to load, you can saved .npy file and use that for future use, use the following code to draw your image from saved data file

    from sketchpy import canvas
    obj = canvas.color_sketch_from_svg(None)
    obj.draw(file = 'data.npy')

Troubleshooting

  • If you find any problem, you can pull request, or contact me on either insta or discord
  • You can also find video on my youtube channel
  • You can know more about sketchpy and get tutorial in this blog page

Acknowledgements

Thanks to all who helped inspire this project.❤

See also

Consider supporting me

  • we spend hours to implement these algorithms and making you to access these with just 3 lines
  • consider supporting our work.
  • even a single rupee conunts.
  • upi id sriramanand23@okicici
  • scan and encourage us to develop more features or use the short url to get the svg file

gpay qr code

License

This project is licensed under the MIT License.

Subscribe to our newsletter