Friday, 10 April 2020

Python Program-10

(10) Draw graphics using Turtle.
1) Shape 1: Square
2) Shape 2: Star
3) Shape 3: Hexagon
4) A square inside another square box
5) Drawing of pattern-1
6) Drawing of pattern-2


Program Code-1:Square using Turtle:

#Lab-10-Draw graphics using Turtle.
#Shape 1: Square
import turtle
skk = turtle.Turtle()

for i in range(4):
    skk.forward(50)
    skk.right(90)


turtle.done()

Output-1:Square using Turtle


Program Code-2:Star using Turtle

#Lab-10-Draw graphics using Turtle.
#Shape 2: Star
import turtle

star = turtle.Turtle()

for i in range(50):
    star.forward(50)
    star.right(144)
   
turtle.done()

Output-2:Star using Turtle


Program Code-3:Hexagon using Turtle

#Lab-10-Draw graphics using Turtle.
#Shape 3: Hexagon
import turtle

polygon = turtle.Turtle()
num_sides = 6
side_length = 70
angle = 360.0 / num_sides

for i in range(num_sides):
    polygon.forward(side_length)
    polygon.right(angle)

turtle.done()

Output-3:Hexagon using Turtle



Program Code-4:Draw a square inside another square box using Turtle

#Lab-10-Draw graphics using Turtle.
#Draw a square inside another square box.
# import turtle library
import turtle           
my_wn = turtle.Screen()
my_wn.bgcolor("light blue")
my_wn.title("Turtle")
my_pen = turtle.Turtle()
my_pen.color("black")
def my_sqrfunc(size):
   for i in range(4):
      my_pen.fd(size)
      my_pen.left(90)
      size = size - 5
my_sqrfunc(146)
my_sqrfunc(126)
my_sqrfunc(106)
my_sqrfunc(86)
my_sqrfunc(66)
my_sqrfunc(46)
my_sqrfunc(26)

Output-4:Draw a square inside another square box using Turtle




Program Code-5:Drawing of pattern-1 using Turtle

#Lab-10-Draw graphics using Turtle.
#Drawing of pattern-1
# import turtle library
import turtle           
my_wn = turtle.Screen()
turtle.speed(2)
for i in range(30):
   turtle.circle(5*i)
   turtle.circle(-5*i)
   turtle.left(i)
turtle.exitonclick()

Output-5:Drawing of pattern-1 using Turtle



Program Code-6:Drawing of pattern-2 using Turtle

#Lab-10-Draw graphics using Turtle.
#Drawing of pattern-2
# import turtle library
import turtle           
colors = [ "red","purple","blue","green","orange","yellow"]
my_pen = turtle.Pen()
turtle.bgcolor("black")
for x in range(360):
   my_pen.pencolor(colors[x % 6])
   my_pen.width(x/100 + 1)
   my_pen.forward(x)
   my_pen.left(59)

Output-6:Drawing of pattern-2 using Turtle


No comments:

Post a Comment