In: Computer Science
Objective:
Create a program that displays a design or picture for someone in your quarantine household/group: a pet, a parent, a sibling, a friend. Make them a picture using the tools in TurtleGraphics and run your program to share it with them!
Use a pen object, as well as any of the shape class objects to help you create your design. You must use and draw at least 5 shape objects.
You must use a minimum of 4 different colors in your design.
You must pick up the pen at least once in your code.
You mut put down the pen at least once in your code.
The picture is of a starry night.
Python code:
from turtle import *
speed(0)
def star():
turns=5
begin_fill()
while turns>0:
forward(25)
left(145)
turns=turns-1
end_fill()
# Grass
bgcolor("green")
# Sky
penup()
goto(-400, -100)
pendown()
color("black")
begin_fill()
for i in range(2):
forward(800)
left(90)
forward(500)
left(90)
end_fill()
# Moon
penup()
goto(-320, 225)
pendown()
color("white")
begin_fill()
circle(35)
end_fill()
# Cloud
penup()
goto(200, 200)
pendown()
color("white")
begin_fill()
circle(25)
end_fill()
penup()
goto(220, 240)
pendown()
begin_fill()
circle(25)
end_fill()
penup()
goto(230, 215)
pendown()
begin_fill()
circle(25)
end_fill()
penup()
goto(180, 225)
pendown()
begin_fill()
circle(25)
end_fill()
# House
penup()
goto(-100, -100)
pendown()
pensize(3)
color("red", "orange") # (stroke, fill)
begin_fill()
for i in range(4):
forward(170)
left(90)
end_fill()
# Chimney
penup()
goto(20, 130)
pendown()
color("red", "cyan")
begin_fill()
for i in range(2):
forward(40)
left(90)
forward(100)
left(90)
end_fill()
# Roof
penup()
goto(-127, 70)
pendown()
begin_fill()
for i in range(3):
forward(225)
left(120)
end_fill()
# Window 1
penup()
goto(0, 0)
pendown()
color("black", "white")
begin_fill()
for i in range(4):
forward(50)
left(90)
end_fill()
# Window 1 Cross - Horizontal Line
penup()
goto(0, 25)
pendown()
color("black")
forward(50)
# Window 1 Cross - Vertical Line
penup()
goto(25, 0)
pendown()
left(90)
forward(50)
# Window 2
penup()
goto(-80, 0)
pendown()
right(90)
color("black", "white")
begin_fill()
for i in range(4):
forward(50)
left(90)
end_fill()
# Window 2 Cross - Horizontal Line
penup()
goto(-80, 25)
pendown()
color("black")
forward(50)
# Window 2 Cross - Vertical Line
penup()
goto(-55, 0)
pendown()
left(90)
forward(50)
# Door
penup()
goto(-40, -97)
pendown()
right(90)
color("blue")
begin_fill()
for i in range(2):
forward(50)
left(90)
forward(80)
left(90)
end_fill()
# Door Handle
penup()
goto(-30, -60)
pendown()
color("black")
begin_fill()
circle(5)
end_fill()
# Stars
x = -350
y= 200
for i in range(0, 5):
penup()
goto(x, y)
pendown()
color("yellow")
star()
x = x+50
a = 200
b = 200
for i in range(0, 5):
penup()
goto(a, b)
pendown()
color("yellow")
star()
a = a+50
# Heading
penup()
goto(-50,270)
pendown()
color('white')
write('A starry night', font=('Courier', 20,'bold'))
hideturtle()
exitonclick()
Output:
How to run the code:
1) Copy paste the code in a file and save it as "test.py"
2) Run the code using command prompt and type the command "python test.py"
or
If using IDLE, press F5
3) The output will be displayed.
Customization:
The colors can be customized according to the user. The different options of colors are:
orange, red, blue, yellow, green, purple, navy blue, cyan, gold, lightgreen, turquoise, darkgreen, chocolate, brown, black, white