In: Computer Science
Write a Python graphics program that draws the following shapes:
• window size: 250 x 250 pixels with window title with your name
• big circle, 50 pixels radius with center at (125, 125)
• two green circles, 10 pixels radius; first one centered at (113, 113) and second centered at (137, 113)
• one red line, from (100, 150) to (150, 150)
Then answer this, what do you see? (make this a comment in your code)
import turtle
window = turtle.Screen()
# sets the window size to 250 x 250 pixels
window.setup(250, 250)
# sets the world coordninate according to window size
window.setworldcoordinates(0, 0, 250, 250)
# sets the window title
window.title('Your Name Here')
# creates a new turtle to draw
t = turtle.Turtle()
# up the pen to avoid drawing the paths
t.penup()
# since we need center at 125,125
# we have to go x,y-2r to get center at xy,where r is radius
# so go to the point (125,75)
t.goto((125, 75))
# down the pen to draw
t.pendown()
# draws circle at current point(125,75)
# with radius 50
t.circle(50)
# up the pen to avoid drawing the paths
t.penup()
# sets the fill color to green
t.fillcolor('green')
# since we need center at 113,113
# we have to go x,y-2r to get center at xy,where r is radius
# so go to the point (113,103)
t.goto((113, 103))
# down the pen to draw
t.pendown()
# to fill the color inside circles
t.begin_fill()
# draw a circle at current point (113,103)
# with radius 10
t.circle(10)
# up the pen to avoid drawing the paths
t.penup()
# since we need center at 137,113
# we have to go x,y-2r to get center at xy,where r is radius
# so go to the point (137,103)
t.goto((137, 103))
# down the pen to draw
t.pendown()
# draw a circle at current point (137,103)
# with radius 10
t.circle(10)
# end the fill to fill both circles
t.end_fill()
# up the pen to avoid drawing the paths
t.penup()
# go to the point (100,150)
t.goto((100, 150))
# set pen color to red
t.pencolor('red')
# pen down to draw
t.pendown()
# goto the point (150,150) with drawing the path
# here the line
t.goto((150, 150))
# to hide the turtle
t.hideturtle()
# to prevent from automatically closing the window
input()
Code Screenshot:
Output:
PS-: If you have any problems doubts please comment below.Thank You