#------------------------- 1- Wire frame lines with Python Turtle -------------------
#pip install turtle
from turtle import *
#pip install time
from time import sleep
bgcolor('black')
t=[Turtle(),Turtle()]
x=6
colors=['red','yellow','blue','lime','black']
for index,i in enumerate(t):
i.speed(0)
i.color("darkcyan")
i.shape("square")
i.shapesize(0.1)
i.width(0)
i.pu()
i.seth(90)
i.fd(350)
i.seth(-180)
i.pd()
t[0].pu()
delay(0)
speed(0)
ht()
sleep(8)
for i in colors:
color(i)
for i in range(360):
t[0].fd(x)
t[0].lt(1)
pu()
goto(t[0].pos())
pd()
t[1].fd(2*x)
t[1].lt(2)
goto(t[1].pos())
done()
#------------------------------ 2-Digtal Clock using turtle --------------------------
#pip install tkinter
from tkinter import *
from tkinter.ttk import *
#pip install time
from time import strftime
root=Tk()
root.title("Clock") #Name for the clock
def time():
string=strftime('%H:%M:%S %p') # Time Format (Hours : Minutes : Seconds)
label.config(text=string)
label.after(1000,time)
label=Label(root,font=("ds-digital",100),background="black",foreground="cyan")
# (Use the font of your system or any inbuilt fonts instead of "ds-digital") or
#(install 'ds-digital' in your system)
label.pack(anchor='center')
time()
mainloop()
#------------------------------ 3-SQUARE using Turtle ------------------------------
#pip install turtle
import turtle
from turtle import *
# Create a turtle screen and a turtle object
Tk = turtle.Screen()
bgcolor("blue") #screen color
speed(2) # for -ve value for high speed and +ve value for low speed - [speed(count)]
Tk.title("Square")
move = turtle.Turtle()
# Draw a square
for i in range(4):
move.forward(100) # Move the turtle forward by 100 units
color("blue")
move.left(90) # left(rotation_degree) or right(rotation_degree)
color('white')
bgcolor('white')
# Close the turtle graphics window when clicked
Tk.exitonclick()
#------------------------------ 4- CIRCLE using Turtle ------------------------------
# pip install turtle
import turtle
from turtle import *
bgcolor('cyan')
Tk = turtle.Screen()
Tk.title("Circle")
turn = turtle.Turtle()
# Draw a circle
turn.circle(100) # Draw a circle with a radius of 100 units
turn.width(0)
color("yellow")
bgcolor("yellow")
Tk.exitonclick()
# ------------------------- 5- Pentagon SPIRAL Using Turtle ----------------------
# pip install turtle
import turtle
from turtle import *
Tk = turtle.Screen()
Tk.title("Pentagon Spiral")
spir = turtle.Turtle()
bgcolor('yellow')
# Draw a spiral
for i in range(89): # You can adjust the number of iterations to change the spiral
spir.forward(10 + i * 5)
spir.right(73) # rotates at an angle of 45 degree, change the angle to
Tk.exitonclick()
#------------------------------ 6- SQUARE spiral Using Turtle -------------------------
# pip install turtle
import turtle
from turtle import *
Tk = turtle.Screen()
Tk.title("Pentagon Spiral")
spir = turtle.Turtle()
bgcolor("yellow")
# Draw a spiral
for i in range(80): # You can adjust the number of iterations to change the spiral
spir.forward(10 + i * 5)
spir.right(90) # rotates at an angle of 45 degree, change angle to
change shape
Tk.exitonclick()
#------------------------- 7-TREE using Turtle ---------------------------------------
import turtle # pip install turtle
from turtle import *
tree = turtle.Screen()
tree.title("Turtle Tree")
Tk = turtle.Turtle()
# Function to draw a tree
def draw_tree(branch_length, t):
if branch_length > 5:
t.forward(branch_length)
t.right(20)
draw_tree(branch_length - 15, t)
t.left(40)
draw_tree(branch_length - 15, t)
t.right(20)
t.backward(branch_length)
Tk.left(90) # Set initial angle
Tk.penup()
Tk.backward(140)
Tk.pendown()
Tk.color("green")
draw_tree(105, Tk)
tree.exitonclick()