Giter Site home page Giter Site logo

mrmystery003 / sketchpy Goto Github PK

View Code? Open in Web Editor NEW
70.0 1.0 37.0 690 KB

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.

Home Page: https://codehub03.blogspot.com/

License: MIT License

Python 100.00%
sketchpy python drawing turtel graphics animation rdj how-to-draw-with-python sketchpy-python animation-library

sketchpy's Introduction

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.

sketchpy's People

Contributors

mr-warriyo avatar mrmystery003 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sketchpy's Issues

How can I align my image in center of the canvas?

I am using sketchpy. I tried to draw some image which I converted into SVG format. After running the code, the turtle starts drawing from such a location which does not result in aligning the image at the center of the canvas. Is there any method to do this?

KeyError: 'USERPROFILE'

My code:

from sketchpy import library as lib

Error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[<ipython-input-3-504f6cc831a4>](https://localhost:8080/#) in <cell line: 1>()
----> 1 from sketchpy import library as lib

1 frames
[/usr/local/lib/python3.10/dist-packages/sketchpy/library.py](https://localhost:8080/#) in <module>
    226 
    227 path = os.path.join(
--> 228     os.environ["USERPROFILE"], "AppData", "Local", "Programs", "Python", "data.txt")
    229 def log(mode, data = ''):
    230     try:

[/usr/lib/python3.10/os.py](https://localhost:8080/#) in __getitem__(self, key)
    678         except KeyError:
    679             # raise KeyError with the original key value
--> 680             raise KeyError(key) from None
    681         return self.decodevalue(value)
    682 

KeyError: 'USERPROFILE'

error with svg files

this is my code:

from sketchpy import canvas

if __name__ == '__main__':
    pen = canvas.sketch_from_svg("2022_04_06.svg")
    pen.draw()

this is the output in console:

python.exe main.py
loading data
100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 25/25 [00:09<00:00,  2.60it/s]
svg data loaded
42 40

but I see this small window and it no draw anithing:

image

this is the file that I have used:

2022_04_06

I have generated it with this site: https://svgconvert.com/#/

Not Working

"Import "sketchpy" could not be resolvedPylance[reportMissingImports]" This i error is poping up while i try to run it

Drawing from raw image

Thanks for the fun package! The current sample code provided for the drawing from raw image is as below - should the last line be obj.draw(threshold=270) instead?

    from sketchpy import canvas
    obj = canvas.sketch_from_image('IMAGE PATH')
    obj = draw(threshold = 127)

Methods for saving the sketch as svg ,png or jpg

No offense, The project is very nice,creative and fun but I'm thinking about exporting the art to the local storage. A method for saving the art to a desired format and path.It'd be fun to have a save_as function.
Thanks

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.