I'm new to using Turtle graphics in Python 3, and I'm at a loss on what to do. One of my problems is that I have no idea where to begin with creating a function that will draw a marker inside of a grid cell based on a data set called 'path' containing 3 variables. The grid map itself is 7x7 and there's 5 markers in total (ranging from 0 to 4). Each marker draws its own social media logo and are completely different from each other.
grid_cell_size = 100 # px
num_squares = 7 # this for creating the 7x7 grid map
# for clarification: path = ['Start', location, marker_value]
path = [['Start', 'Centre', 4], ['North', 2, 3],
['East', 2, 2], ['South', 4, 1], ['West', 2, 0]]
My main goal is to be able to draw all 5 markers at once in their own location coordinates using the above data set. I'm not sure how should I approach with assigning these markers to their own marker_value. Would an if/elif/else statement work for this?
Trying to implement 5 markers at once is too overwhelming for me so I've tried using this very simple data set called 'path_var_3' that will only draw 1 marker.
path_var_3 = [['Start', 'Bottom left', 3]]
def follow_path(path_selection):
# Draws YouTube logo marker
if 3 in path_var_3[0]:
penup()
# !!!
goto(0, -32)
setheading(90)
# Variables
youtube_red = '#ff0000'
youtube_white = 'White'
radius = 10
diameter = radius * 2
# Prep to draw the superellipse
pencolor(youtube_red)
fillcolor(youtube_red)
# Drawing the superellipse
begin_fill()
pendown()
for superellipse in range(2):
circle(radius, 90)
forward(80)
circle(radius, 90)
forward(60 - diameter)
# Finish up
end_fill()
penup()
# Move turtle position towards the centre of the superellipse
# !!!
goto(-59)
backward(16)
setheading(90)
fillcolor(youtube_white)
# Drawing the white 'play icon' triangle
begin_fill()
pendown()
for play_triangle in range(2):
right(120)
forward(28)
right(120)
forward(28)
# Finish up
endfill()
penup()
else: return print('ERROR')
follow_path(path_var_3)
So far I was able to draw the marker in the program, but immediately I've encountered my first problem: I've realised that I've hardcoded the coordinates of where the superellipse and the triangle will begin to draw at, as indicated with the '!!!' comments. So when I run the program the marker is drawn outside of the grid cell. How do I get the marker to be drawn INSIDE a cell, regardless of where the cell is located within the 7x7 grid map?
If anyone has any ideas or is able to help I will greatly appreciate it.
TL;DR:
- How do I draw a marker, consisting of various shapes, inside the 100x100 cell within the 7x7 grid map?
- How do I draw a marker in any cell based on the location variable from a data set?
- How should I approach with assigning markers to integers ranging 0-4? If/elif/else statements?