Skip to main content


Turtle Magic (Turtle to PNG)

 Watch the tutorial for better understanding:-



Steps to follow:-

Install Ghost Script in your Windows / Linux :- https://www.ghostscript.com/download/gsdnld.html

Note down the path where you are installing.

Create an environment variable of ghost script path.

How to set environment variable for Ghost Script? Watch the video.

Use background.png else it will not work.

 

background.png




Make sure you hide your turtle and remove turtle.done or loop.

And add this script below your turtle program. 

### This will create .eps file ####
import turtle
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)

# To get the transparent png in the center change this values i.e. 1.30 & 1.35, between 1.30, 1.31, 1.32 etc.
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()

 

Turtle to PNG working Scripts:-



import turtle
turtle.speed(0)
turtle.bgcolor("black")
#turtle.Screen().bgcolor("orange")

for i in range (15) :
    for colours in ("red", "magenta", "blue", "cyan", "green", "yellow", "white") :
        turtle.color(colours)
        turtle.pensize(3)
        turtle.left(4)
        turtle.forward(200)
        turtle.left(90)
        turtle.forward(200)
        turtle.left(90)
        turtle.forward(200)
        turtle.left(90)
        turtle.forward(200)
        turtle.left(90)
        turtle.hideturtle()

turtle.hideturtle()

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file

ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.3),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("DONE")
ts.exitonclick()



import turtle


sc=turtle.Screen()
sc.setup(600, 600)
spiral=turtle.Turtle()
spiral.speed(1000)
sc.bgcolor("black")

col = ("cyan", "blue", "yellow", "green")
c=0
for i in range(110):
    spiral.pensize(2)
    spiral.forward(i*5)
    spiral.right(144)
    spiral.color(col[c])
    if c==3:
       c=0
    else:
       c+=1
       
spiral.hideturtle()


### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.5),round(xoff-w/1.6)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("DONE")
ts.exitonclick()



import turtle
a=turtle.Turtle()
a.getscreen().bgcolor("black")
a.penup()
a.goto(-200, 100)
a.pendown()
a.color("yellow")
a.speed(25)
def star(turtle, size):
    if size<=10:
        return
    else:
        turtle.begin_fill()
        for i in range (5):
            turtle.pensize(2)
            turtle.forward(size)
            star(turtle, size/3)
            turtle.left(216)
            turtle.end_fill()
star(a, 360)

#turtle.done()

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.5),round(xoff-w/1.6)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("DONE")
ts.exitonclick()



import turtle
t = turtle.Turtle()
turtle.title("Love Shape Programming")
screen = turtle.Screen()
screen.bgcolor("black")
t.color("yellow", "red")
t.begin_fill()
t.pensize(3)

t.right(20)
t.fillcolor("#F5C657")
t.left(140)
t.forward(180)
t.circle(-90, 200)
t.setheading(60)
t.circle(-90, 200)
t.forward(180)
t.end_fill()
t.begin_fill()

t.right(15)
t.forward(90)
t.fillcolor("#F3EE00")
t.left(140)
t.left(140)
t.forward(180)
t.circle(-90, 200)
t.setheading(60)
t.circle(-90, 200)
t.forward(180)
t.end_fill()
t.begin_fill()

t.right(10)
t.forward(90)
t.fillcolor("#F7320F")
t.left(140)
t.left(140)
t.forward(180)
t.circle(-90, 200)
t.setheading(60)
t.circle(-90, 200)
t.forward(180)
t.end_fill()
t.begin_fill()

t.right(5)
t.forward(90)
t.fillcolor("#01D63E")
t.left(140)
t.left(140)
t.forward(180)
t.circle(-90, 200)
t.setheading(60)
t.circle(-90, 200)
t.forward(180)
t.end_fill()
t.begin_fill()

t.right(1)
t.forward(90)
t.fillcolor("#0284FC")
t.left(140)
t.left(140)
t.forward(180)
t.circle(-90, 200)
t.setheading(60)
t.circle(-90, 200)
t.forward(180)
t.end_fill()


t.hideturtle()

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.5),round(xoff-w/1.6)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("DONE")
ts.exitonclick()




import turtle
turtle.speed(0)
turtle.left(35)
turtle.bgcolor("black")
for i in range (22) :
    for colours in ("red", "magenta", "blue", "grey", "green",) :
        turtle.color(colours)
        turtle.pensize(2)
        turtle.forward(200)
        turtle.left(144)
        turtle.forward(201)
        #turtle.left(145)
        turtle.left(73)
        
### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.3),round(xoff-w/1.4)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("DONE")
ts.exitonclick()




import tkinter
import turtle

t=turtle.Pen()
turtle.bgcolor('dimgrey')
sides = 4
colors=['lemon chiffon', 'purple', 'blue', 'salmon', 'green', 'red']
y = 350

for x in range(y):
     t.pencolor(colors[x%sides])
     t.width(x*sides/200)
     t.forward(x*3/sides +x)
     t.left(y/sides+1)

t.forward(100)
ts = turtle.getscreen()
ts.getcanvas().postscript(file="NiceHexSpiral.eps")

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.5),round(xoff-w/1.6)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("DONE")
ts.exitonclick()




import turtle
colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']
t = turtle.Pen()
turtle.bgcolor('black')
t.speed(10)
for x in range(360):
    t.pencolor(colors[x%6])
    t.width(x/100 + 1)
    t.forward(x)
    t.left(59)
t.hideturtle()
### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()




import turtle 

ninja = turtle.Turtle()
turtle.Screen().bgcolor("black")

ninja.speed(10)

for i in range(180):
    ninja.pencolor("yellow")
    ninja.forward(100)
    ninja.right(30)
    ninja.pencolor("red")
    ninja.forward(20)
    ninja.left(60)
    ninja.pencolor("blue")
    ninja.forward(50)
    ninja.right(30)
    
    ninja.penup()
    ninja.setposition(0, 0)
    ninja.pendown()
    
    ninja.right(2)

ninja.hideturtle()    
#turtle.done()

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()




import turtle
from turtle import * 
from random import randint 
bgcolor('black') 
x = 1 
speed(0) 
while x < 400:
     r = randint(0,255) 
     g = randint(0,255)  
     b = randint(0,255) 
     colormode(255)  
     pencolor(r,g,b) 
     fd(0 + x) 
     rt(90.991) 
     x = x+1 

hideturtle() 
#exitonclick() 

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()




import turtle 
import math 
import colorsys 

phi = 180 * (3 - math.sqrt(5)) 

t = turtle.Pen() 
t.speed(0) 

def square(t, size): 
   for tmp in range(0,4): 
       t.forward(size) 
       t.right(90) 

num = 140 

for x in reversed(range(0, num)): 
   t.fillcolor(colorsys.hsv_to_rgb(x/num, 1.0, 1.0)) 
   t.begin_fill() 
   t.circle(5 + x, None, 11) 
   square(t, 5 + x) 
   t.end_fill() 
   t.right(phi) 
   t.right(.8) 

t.hideturtle()
#turtle.mainloop()

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()




from turtle import *
speed(10)
colors = ['orange', 'red', 'pink', 'yellow', 'blue', 'green']
for x in range(200):
     pencolor(colors[x % 6])
     width(x / 5 + 1)
     forward(x)
     left(45)

### This will create .eps file ####
import turtle
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()




from turtle import *

space = Screen()
tess = Turtle()
tess.color("lime")
#tess.shape("turtle")
tess.penup()
for a in range(40, -1, -1):
     tess.stamp()
     tess.left(a)
     tess.forward(20)

### This will create .eps file ####
import turtle
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()




import turtle
import math
import random
wn = turtle.Screen()
wn.bgcolor('black')
Albert = turtle.Turtle()
Albert.speed(0)
Albert.color('white')
rotate=int(360)
def drawCircles(t,size):
    for i in range(10):
        t.circle(size)
        size=size-4
def drawSpecial(t,size,repeat):
  for i in range (repeat):
    drawCircles(t,size)
    t.right(360/repeat)
drawSpecial(Albert,100,10)
Steve = turtle.Turtle()
Steve.speed(0)
Steve.color('yellow')
rotate=int(90)
def drawCircles(t,size):
    for i in range(4):
        t.circle(size)
        size=size-10
def drawSpecial(t,size,repeat):
    for i in range (repeat):
        drawCircles(t,size)
        t.right(360/repeat)
drawSpecial(Steve,100,10)
Barry = turtle.Turtle()
Barry.speed(0)
Barry.color('blue')
rotate=int(80)
def drawCircles(t,size):
    for i in range(4):
        t.circle(size)
        size=size-5
def drawSpecial(t,size,repeat):
    for i in range (repeat):
        drawCircles(t,size)
        t.right(360/repeat)
drawSpecial(Barry,100,10)
Terry = turtle.Turtle()
Terry.speed(0)
Terry.color('orange')
rotate=int(90)
def drawCircles(t,size):
    for i in range(4):
        t.circle(size)
        size=size-19
def drawSpecial(t,size,repeat):
    for i in range (repeat):
        drawCircles(t,size)
        t.right(360/repeat)
drawSpecial(Terry,100,10)
Will = turtle.Turtle()
Will.speed(0)
Will.color('pink')
rotate=int(90)
def drawCircles(t,size):
    for i in range(4):
        t.circle(size)
        size=size-20
def drawSpecial(t,size,repeat):
    for i in range (repeat):
        drawCircles(t,size)
        t.right(360/repeat)
drawSpecial(Will,100,10)

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()




import turtle 

painter = turtle.Turtle()
painter.speed(10)
turtle.Screen().bgcolor('black')

painter.pencolor("purple")
for i in range(50):
    painter.forward(50)
    painter.left(123)  

painter.pencolor("yellow")
for i in range(50):
    painter.forward(100)
    painter.left(123)  

painter.pencolor("lime")
for i in range(50):
    painter.forward(150)
    painter.left(123)  

painter.pencolor("blue")
for i in range(50):
    painter.forward(200)
    painter.left(123)  
    
painter.pencolor("red")
for i in range(50):
    painter.forward(250)
    painter.left(123)

painter.pencolor("orange")
for i in range(50):
    painter.forward(300)
    painter.left(123)

painter.pencolor("magenta")
for i in range(50):
    painter.forward(350)
    painter.left(123)

painter.pencolor("cyan")
for i in range(50):
    painter.forward(400)
    painter.left(123)

painter.pencolor("purple")
for i in range(50):
    painter.forward(450)
    painter.left(123)

painter.hideturtle()
#turtle.done()

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()




import turtle
trtl=turtle.Turtle()
trtl.speed(10)
for i in range(0,400,20):
  trtl.pencolor('lightgrey')
  trtl.penup()
  trtl.setpos(-200+i,-200)
  if i==0:
    trtl.left(90)
  trtl.pendown()
  trtl.forward(400)
  trtl.backward(400)
for i in range(0,400,20):
  trtl.pencolor('lightgrey')
  trtl.penup()
  trtl.setpos(-200,-200+i)
  if i==0:
    trtl.right(90)
  trtl.pendown()
  trtl.forward(400)
  trtl.backward(400) 
trtl.penup()
trtl.home()
trtl.pendown()
trtl.pencolor('yellow')
trtl.backward(200)
trtl.forward(400)
trtl.backward(200)
trtl.left(90)
trtl.forward(200)
trtl.backward(400)
trtl.penup()
trtl.setpos(5,5)
trtl.pendown()
trtl.write(0)
trtl.penup()
trtl.setpos(190,5)
trtl.pendown()
trtl.write("x")
trtl.penup()
trtl.setpos(5,190)
trtl.pendown()
trtl.write("y")
trtl.penup()
trtl.setpos(80,-180)
trtl.pendown()
trtl.write("@PythonProgrammers")
trtl.ht()

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()




import turtle
screen=turtle.Screen()
trtl=turtle.Turtle()
trtl.speed(10)
screen.setup(620,620)
screen.bgcolor('black')
clr=['red','green','blue','yellow','purple']
trtl.pensize(4)
trtl.shape('turtle')
trtl.penup()
trtl.pencolor('red')
m=0
for i in range(12):
      m=m+1
      trtl.penup()
      trtl.setheading(-30*i+60)
      trtl.forward(150)
      trtl.pendown()
      trtl.forward(25)
      trtl.penup()
      trtl.forward(20)
      trtl.write(str(m),align="center",font=("Arial", 12, "normal"))
      if m==12:
        m=0
      trtl.home()
trtl.home()
trtl.setpos(0,-250)
trtl.pendown()
trtl.pensize(10)
trtl.pencolor('blue')
trtl.circle(250)
trtl.penup()
trtl.setpos(150,-270)
trtl.pendown()
trtl.pencolor('olive')
trtl.write('@PythonProgrammers',font=("Arial", 10, "normal"))
trtl.ht() 

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.50),round(xoff-w/1.50)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()




import turtle
import math

kalam = turtle.Turtle()
kalam.speed(500)

window = turtle.Screen()
window.bgcolor("#000000")
kalam.color("yellow")

ankur = 20

kalam.fillcolor('yellow')
kalam.begin_fill()

kalam.left(90)
kalam.penup()
kalam.goto(-7 * ankur, 0)
kalam.pendown()

for a in range(-7 * ankur, -3 * ankur, 1):
    x = a / ankur
    rel = math.fabs(x)
    y = 1.5 * math.sqrt((-math.fabs(rel - 1)) * math.fabs(3 - rel) / ((rel - 1) * (3 - rel))) * (
                1 + math.fabs(rel - 3) / (rel - 3)) * math.sqrt(1 - (x / 7) ** 2) + (
                    4.5 + 0.75 * (math.fabs(x - 0.5) + math.fabs(x + 0.5)) - 2.75 * (
                        math.fabs(x - 0.75) + math.fabs(x + 0.75))) * (1 + math.fabs(1 - rel) / (1 - rel))
    kalam.goto(a, y * ankur)

for a in range(-3 * ankur, -1 * ankur - 1, 1):
    x = a / ankur
    rel = math.fabs(x)
    y = (2.71052 + 1.5 - 0.5 * rel - 1.35526 * math.sqrt(4 - (rel - 1) ** 2)) * math.sqrt(
        math.fabs(rel - 1) / (rel - 1))
    kalam.goto(a, y * ankur)

kalam.goto(-1 * ankur, 3 * ankur)
kalam.goto(int(-0.5 * ankur), int(2.2 * ankur))
kalam.goto(int(0.5 * ankur), int(2.2 * ankur))
kalam.goto(1 * ankur, 3 * ankur)

#print("Batman Logo with Python Turtle")

for a in range(1 * ankur + 1, 3 * ankur + 1, 1):
    x = a / ankur
    rel = math.fabs(x)
    y = (2.71052 + 1.5 - 0.5 * rel - 1.35526 * math.sqrt(4 - (rel - 1) ** 2)) * math.sqrt(
        math.fabs(rel - 1) / (rel - 1))
    kalam.goto(a, y * ankur)

for a in range(3 * ankur + 1, 7 * ankur + 1, 1):
    x = a / ankur
    rel = math.fabs(x)
    y = 1.5 * math.sqrt((-math.fabs(rel - 1)) * math.fabs(3 - rel) / ((rel - 1) * (3 - rel))) * (
                1 + math.fabs(rel - 3) / (rel - 3)) * math.sqrt(1 - (x / 7) ** 2) + (
                    4.5 + 0.75 * (math.fabs(x - 0.5) + math.fabs(x + 0.5)) - 2.75 * (
                        math.fabs(x - 0.75) + math.fabs(x + 0.75))) * (1 + math.fabs(1 - rel) / (1 - rel))
    kalam.goto(a, y * ankur)

for a in range(7 * ankur, 4 * ankur, -1):
    x = a / ankur
    rel = math.fabs(x)
    y = (-3) * math.sqrt(1 - (x / 7) ** 2) * math.sqrt(math.fabs(rel - 4) / (rel - 4))
    kalam.goto(a, y * ankur)

for a in range(4 * ankur, -4 * ankur, -1):
    x = a / ankur
    rel = math.fabs(x)
    y = math.fabs(x / 2) - 0.0913722 * x ** 2 - 3 + math.sqrt(1 - (math.fabs(rel - 2) - 1) ** 2)
    kalam.goto(a, y * ankur)

for a in range(-4 * ankur - 1, -7 * ankur - 1, -1):
    x = a / ankur
    rel = math.fabs(x)
    y = (-3) * math.sqrt(1 - (x / 7) ** 2) * math.sqrt(math.fabs(rel - 4) / (rel - 4))
    kalam.goto(a, y * ankur)


kalam.penup()
#kalam.goto(300, 300)
kalam.hideturtle()
kalam.end_fill()
#turtle.done()

### This will create .eps file ####
from tkinter import *
from turtle import *
from PIL import Image
import os
import time

# keeping eps file name as image
eps_file = "temp.eps"

# generating eps file
ts = turtle.getscreen()
turtle.hideturtle()
ts.getcanvas().postscript(file=eps_file)

# get current python file name as string without ".py"
fname = os.path.basename(__file__)
filename = fname.replace('.py','.png')

# Converting eps file to jpg | with filename 
#im.save(str(filename)+".jpg", "JPEG")

# Convert eps to transparent png using ghost script
os.popen("gswin64c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="+filename+" -dEPSCrop temp.eps")

# Merge transparent png on top of given background png
time.sleep(2)

# Get transparent image file height / width
img = Image.open(filename)
h, w = img.size
print(h,w)

# Get background image file height / width
background = Image.open('background.png')
hh, ww = background.size
print(hh,ww)      

#resize the transparent png image
yoff = round((h)/1.5)
xoff = round((w)/1.5)
size = yoff,xoff
print(size)
img = img.resize(size ,Image.ANTIALIAS)
background.paste(img, (round(yoff-h/1.30),round(xoff-w/1.35)), img)

#Save file as New Image file
background.save("_"+filename,"PNG")
print("Done")
ts.exitonclick()



Comments



🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍

Popular Posts

Python underline string, Python underline text, Underline python print

Python pip - Installing modules from IDLE (Pyton GUI) for python 3.7

Top 40 Python - String Processing in Python | Working with String in Python

Python Program - When was I born? / Date of Birth / MY BIRTHDAY (using Python3+)

Top 11 Essential Python Tips and Tricks





Subscribe to our Channel


Follow us on Facebook Page

Join our python facebook groups



Join us on Telegram