0% found this document useful (0 votes)
32 views

Cs Project

The document defines functions to draw various shapes using the turtle module in Python. It contains functions to draw circular, hexagonal, square, and triangular patterns, as well as individual shapes like circles, squares, triangles. The main program allows the user to choose a number corresponding to the desired shape function and calls it to render the drawing.

Uploaded by

poojaparmar2805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Cs Project

The document defines functions to draw various shapes using the turtle module in Python. It contains functions to draw circular, hexagonal, square, and triangular patterns, as well as individual shapes like circles, squares, triangles. The main program allows the user to choose a number corresponding to the desired shape function and calls it to render the drawing.

Uploaded by

poojaparmar2805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

import turtle

import colorsys

def initialize():

turtle.up()

turtle.goto(0,0)

turtle.down()

pen = turtle.Turtle()

turtle.speed(15)

turtle.bgcolor("black")

turtle.pensize(2)

turtle.hideturtle()

def circular_design():

turtle.up()

turtle.goto(0,0)

turtle.down()

colors = ["red", "orange", "yellow", "green", "blue", "purple"]

turtle.pensize(2)

for i in range(90):

turtle.color(colors[i % 6])

turtle.forward(200)

turtle.right(61)

turtle.forward(100)

turtle.right(120)

turtle.forward(100)

turtle.right(61)

turtle.forward(200)

turtle.right(181)

def hexagon():

turtle.up()

turtle.goto(0,0)
turtle.down()

turtle.pensize(8)

turtle.speed(5)

colors= "blue"

turtle.color(colors)

turtle.up()

turtle.goto(-86,150)

turtle.down()

num_sides = 6 #6 side

side_length = 200

angle = 360.0 / num_sides #60 degree angle

for i in range(num_sides):

turtle.forward(side_length)#to move turtle 100 pixel

turtle.right(angle)#to change angle by 60 degree

def square():

turtle.up()

turtle.goto(0,0)

turtle.down()

turtle.pensize(8)

turtle.speed(5)

colors= "red"

turtle.color(colors)

turtle.up()

turtle.goto(-86,150)

turtle.down()

num_sides = 4 #6 side

side_length = 200

angle = 360.0 / num_sides #60 degree angle

for i in range(num_sides):

turtle.forward(side_length)#to move turtle 100 pixel

turtle.right(angle)#to change angle by 60 degree

def circle():
turtle.up()

turtle.goto(0,0)

turtle.down()

turtle.pensize(4)

turtle.speed(5)

colors= "yellow"

turtle.color(colors)

turtle.circle(80)

turtle.up() # to pull the pen up from the screen

turtle.goto(0,80)# to move the turtle to an absolute position.

turtle.down()

def triangle():

turtle.up()

turtle.goto(0,0)

turtle.down()

turtle.pensize(4)

turtle.speed(5)

colors= "yellow"

turtle.color(colors)

turtle.up()

turtle.goto(0,90)

turtle.down()

turtle.right(60)

turtle.forward(300)

for i in range(2):

turtle.right(120)

turtle.forward(300)

def square_design():

turtle.up()

turtle.goto(0,0)

turtle.down()

colors = ["red", "orange", "yellow", "green", "blue", "purple"]


turtle.pensize(2)

turtle.speed(20)

x=45

for i in range(180):

turtle.color(colors[i % 6])

turtle.right(x)

turtle.forward(100)

x=x+2

for i in range(3):

turtle.right(90)

turtle.forward(100)

def triangle_design():

turtle.up()

turtle.goto(0,0)

turtle.down()

colors = ["red", "orange", "yellow", "green", "blue", "purple"]

turtle.pensize(2)

turtle.speed(100)

x=60

turtle.hideturtle()

for i in range(90):

turtle.color(colors[i % 6])

turtle.right(x)

turtle.forward(100)

x=x+4

for i in range(2):

turtle.right(120)

turtle.forward(100)

def hexagon_design():

turtle.up()

turtle.goto(0,0)

turtle.down()
colors = ["red", "orange", "yellow", "green", "blue", "purple"]

turtle.pensize(1)

turtle.speed(100)

x=60

turtle.hideturtle()

for i in range(90):

turtle.color(colors[i % 6])

turtle.right(x)

turtle.forward(100)

x=x+4

for i in range(5):

turtle.right(60)

turtle.forward(100)

def rainbow():

turtle.up()

turtle.goto(0,0)

turtle.down()

def draw_one_color_arc(x,y,r,band,color):

turtle.up()

turtle.goto(x+r,y)

turtle.down()

turtle.seth(90)

turtle.pensize(band)

turtle.pencolor(color)

turtle.circle(r,180)

turtle.speed(0)

turtle.bgcolor('black')

turtle.title(' Rainbow')

turtle.setup(700,700)

num_colors = 49
radius = 300

penwidth = 20*7/num_colors

hue = 0

for i in range(num_colors):

(r,g,b) = colorsys.hsv_to_rgb(hue,1,1)

draw_one_color_arc(0,-100,radius,penwidth,(r,g,b))

radius -= (penwidth-1) #overlapping a little removes the gaps

hue += 0.9/num_colors

#main program

print("welcome to our program")

print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")

print("this program helps you to draw different shapes")

print("enter 1 to draw circular design")

print("enter 2 to draw hexagon")

print("enter 3 to draw square")

print("enter 4 to draw circle")

print("enter 5 to draw triangle")

print("enter 6 to draw square design")

print("enter 7 to draw triangular design")

print("enter 8 to draw hexagonal design")

print("enter 9 to draw rainbow")

print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")

choice="y"

while choice=="y":

shape=int(input("choose any number from[1,2,3,4,5,6,7,8,9,10] to draw desired shape:"))

if shape == 1:

turtle.clear()

initialize()

circular_design()
elif shape == 2:

turtle.clear()

turtle.right(0)

initialize()

hexagon()

elif shape == 3:

turtle.clear()

initialize()

square()

elif shape == 4:

turtle.clear()

initialize()

circle()

elif shape == 5:

turtle.clear()

initialize()

triangle()

elif shape == 6:

turtle.clear()

initialize()

square_design()

elif shape == 7:

turtle.clear()

initialize()

triangle_design()

elif shape == 8:

turtle.clear()

initialize()

hexagon_design()

elif shape == 9:

turtle.clear()

initialize()

rainbow()

else :
print("please enter valid number")

choice = input("enter y to draw more:")

print("Thank you for visiting our program")

You might also like