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.
- 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😊
- Turtle
- Open-cv
- Pillow
- numpy
- Svgpathtools
- you can install the latest version with either
pip install sketchpy==0.1.8
or
pip install sketchpy --U
- 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()
fromutils
to convert your Image to svg, this function opens your default web browser to get you to thebest svg converting website
- You can use the function as followes
from sketchpy import canvas canvas.get_svg()
- Python
- Basic text editor
- creativity😂
pip install sketchpy
it should probably work, If not then try the following code
pip install turtle open-cv wheel sketchpy
Open your code editor and write the example Python code snippets given below. Run your code and see the magic by yourself.
from sketchpy import library as lib
obj = lib.rdj()
obj.draw()
from sketchpy import library
myObject = library.tom_holland()
myObject.draw()
from sketchpy import library as lib
obj = lib.bts()
obj.draw()
from sketchpy import library as lib
obj = lib.vijay()
obj.draw()
from sketchpy import library
myObject = library.ironman_ascii()
myObject.draw()
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()
- 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
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)
- 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
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.
- 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
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')
- 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
Thanks to all who helped inspire this project.❤
- 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
This project is licensed under the MIT License.