Draw any Image using Python Turtle Module

 Instructions:

1. The below code will draw an Iron man image as the iron man image is passed to the program.

2. You have to install the library pywhatkit into your python directory by using the command 

>>>pip install pywhatkit

 Resources:


Code:

from pywhatkit import image_to_ascii_art as a 
img_path = 'ironman.jpg'
text = 'ironman.txt'         
a(img_path, text)
import turtle as t 
s_x = -320                  
s_y = 250
p = t.Pen()
t.bgcolor('black')
p.up()
p.width(2)
f_m = 0
d_m = 4
# function to select the color
def set_col(c):
    chars = {"*": 'white', "S" : 'green', "#" : 'green', "&" : 'white', "@":'black', "$" : 'white', "%" : 'white', "!":'blue', ":" :'darkgreen', ".":'grey'}
    col = chars[c]
    p.pencolor(col)
def d(m, s_char):
     p.up()
     if s_char != '\n':
         set_col(s_char)
     p.goto(s_x- m, s_y )
     p.down()
     p.forward(1)
text = open(text, 'r')
te = text.readlines()
for i in te:
    for j in i:
        d(f_m, j)
        f_m -= 4
    s_y -= 9
    s_x = -320
    f_m = 0
    d_m = 4
t.done()
print('completed')

Comments

Popular posts from this blog

Python Game - Turtle Race

Convert Image To Sketch Using Python