Now, let's write our Python code in main.py
! We need to create our mini-map by drawing trees and a building, and then labeling the building.
Here are some helpful code examples:
1. How to draw a rectangle (for a building):
import turtle
my_pen = turtle.Turtle()
width = 60
height = 100
my_pen.color("brown")
my_pen.begin_fill()
for _ in range(2):
my_pen.forward(width)
my_pen.left(90)
my_pen.forward(height)
my_pen.left(90)
my_pen.end_fill()
2. How to draw a circle (for a tree top):
import turtle
my_pen = turtle.Turtle()
radius = 30
my_pen.color("green")
my_pen.begin_fill()
my_pen.circle(radius)
my_pen.end_fill()
3. How to use a loop to draw many things:
import turtle
my_artist = turtle.Turtle()
# Draw 4 dots in a row
for i in range(4):
x_pos = -150 + i * 100 # Change x position for each dot
y_pos = 0
my_artist.penup()
my_artist.goto(x_pos, y_pos)
my_artist.pendown()
my_artist.dot(20, "orange")
4. How to add a label to your drawing:
import turtle
my_pen = turtle.Turtle()
my_pen.penup()
my_pen.goto(50, 50) # Where to put the label
my_pen.color("blue")
my_pen.write("My Label", align="center", font=("Times New Roman", 16, "bold"))
5. Setting up your drawing pen (Turtle):
import turtle
my_pen = turtle.Turtle()
my_pen.hideturtle() # Make it invisible
my_pen.speed(0) # Make it super fast!
my_pen.penup() # Lift pen up
my_pen.pendown() # Put pen down