Python code,
How do I add text in the red cube section, and how can I draw
the hexagon on the left side in to the blue circled area
hexagon code as below
number = 1234567 # put number here as an
integer
name = 'david' # put name as a character
string
# BREAKOUT
# Import standard Python modules needed to complete this
assignment.
from turtle import *
from math import *
from random import *
from sys import exit as abort
from os.path import isfile
cell_side = 50 # pixels (default is 50)
# Derive constant values used in the main program that sets
up
# the drawing canvas. Do NOT change any of these
values.
cell_width = cell_side + (2 * (cell_side * cos(radians(60))))
# some trigonometry!
cell_height = 2 * (cell_side * sin(radians(60))) #
x_margin = cell_width * 2.5 # the size of the margin left and right
of the map
y_margin = cell_height // 1.5 # the size of the margin below and
above the map
window_height = 8 * cell_height + y_margin * 2 # the drawing
canvas' height
window_width = 8 * cell_width + x_margin * 2 # the drawing canvas'
width
coord_font = ('Arial', cell_side // 3, 'normal') # text font for
coords
label_font = ('Arial', cell_side // 2, 'normal') # text font for
labels
# Validity check on dimensions - do not change this code
assert (40 <= cell_side <= 60), \
'Cell sides must be between 40 and 60
pixels in length'
#-----Initialisation
Steps-------------------------------------------#
#Do NOT change any of the code in this section.
if not isinstance(student_number, int):
print('\nUnable to run: No student number
supplied',
'(must be an integer)\n')
abort()
if not isinstance(student_name, str):
print('\nUnable to run: No student name
supplied',
'(must be a character
string)\n')
abort()
### Define the function for generating data sets, using
the
### data generation function if available,
if isfile('motion_data.py'):
print('\nData module found ...')
from motion_data import steps
def movements(new_seed = randint(0, 999)):
print('Using seed', new_seed,
'...\n')
seed(new_seed) # set the seed
return steps() # return the random data
set
else:
print('\nNo data module available!\n')
def movements(dummy_parameter = None):
return [] # return an empty data
set
#
#--------------------------------------------------------------------#
#-----Functions for Drawing the
Map----------------------------------#
# Set up the canvas and draw the background for the overall
image
def create_map(bg_colour = 'light grey',
line_colour
= 'slate grey',
draw_map =
True,
add_text =
True): # NO! DON'T CHANGE THIS CODE!
# Set up the drawing canvas with enough space for the
map and
# spaces on either side
setup(window_width, window_height)
bgcolor(bg_colour)
# Draw as quickly as possible
tracer(False)
# Get ready to draw the map
penup()
color(line_colour)
width(2)
# Determine the left-bottom coords of the
map
left_edge = -(8.5 * cell_width) // 2
bottom_edge = -(7 * cell_height) // 2
# Optionally draw the map
if draw_map:
# Mark the home coordinate
home()
dot(cell_side // 4)
# Draw the cells row by row
for rows in range(8):
# Draw upper half of
row
goto(left_edge,
bottom_edge + (rows * cell_height))
pendown()
setheading(0) # face
east
for angle in ([60, -60,
-60, 60] * 6)[:-1]:
left(angle)
forward(cell_side)
penup()
# Draw lower half of
row
goto(left_edge,
bottom_edge + (rows * cell_height))
pendown()
setheading(0) # face
east
for angle in ([-60, 60,
60, -60] * 6)[:-1]:
left(angle)
forward(cell_side)
penup()
# Draw each of the labels on the x
axis
penup()
y_offset = cell_height // 1.2 #
pixels
for x_label in range(11):
goto(left_edge -
(cell_width // 4) + ((x_label + 1) * (cell_width // 1.32)),
bottom_edge - y_offset)
write(chr(x_label +
ord('A')), align = 'center', font = coord_font)
# Draw each of the labels on the y
axis
penup()
x_offset, y_offset = cell_side // 5,
cell_height // 10 # pixels
for y_label in range(15):
goto(left_edge +
(cell_width * 8.7), bottom_edge + (y_label * (cell_height // 2)) -
y_offset)
write(str(y_label + 1),
align = 'left', font = coord_font)
# Optionally mark the blank spaces ... DO NOT CHANGE
ANY OF THIS CODE!
#if add_text:
# Write to the left of the map
#goto(-(4.4 * cell_width),
-(cell_height // 2))
# write('Draw the\nfour levels of\nyour
object or\nentity here', align = 'right', font = label_font)
# Write to the right of the map
#goto(4.8 * cell_width,
-cell_height)
# write('Your final\nmessage\n(if any)
will\nappear\nhere', align = 'left', font = label_font)
# Reset everything ready for the student's
solution
pencolor('black')
width(1)
penup()
home()
tracer(True)
# End the program and release the drawing canvas to the
operating
# system.
def release_map(hide_cursor = True):
tracer(True) # ensure any drawing still in progress
is displayed
if hide_cursor:
hideturtle()
done()
#
#--------------------------------------------------------------------#
#-----Function to Write a
Message------------------------------------#
#
# The function in this section writes a message to the
screen.
#
def write_breakout_message(step_num):
penup()
color('firebrick')
goto(cell_width * 4.8, -cell_height * 0.25)
write('Breakout\nat Step ' + str(step_num) +
'!',
align = 'left', font =
label_font)
#
#--------------------------------------------------------------------#
#-----Code to Create Drawing
Canvas----------------------------------#
#
. Do NOT change any of this code except
# as indicated by the comments marked '*****'.
#
# Set up the drawing canvas
create_map()
# Control the drawing speed
# ***** Change the following argument
# ***** the drawing speed
speed('fastest')
# Decide whether or not to show the drawing being done
step-by-step
# ***** Set the following argument to False if dont want to
wait
tracer(True)
# Give the drawing canvas a title
# ***** Replace this title with a description of the
# ***** object or entity shown in your solution
title("the shape")
#
#--------------------------------------------------------------------#
#
# Complete the code by replacing the dummy function below
with
# your own "follow_path" function. ALL of
solution code
# must appear in, or be called from, function "follow_path".
Do
# NOT put any of the code in any other parts of the
program and do
# NOT change any of the provided code except as allowed in
parts
def follow_path(cell_width, cell_height):
if follow_path:
color("black","light blue") #(outline,
fill)
for i in range (1):
penup()
goto(-600,200)
pendown()
begin_fill()
setheading(0)
for angle in ([60, -60,
-60, 60]*1 )[:-1]:
left(angle)
forward(cell_side)
penup()
#bottom half of
row
goto(-600, 200)
pendown()
setheading(0)# face
east
for angle in ([-60, 60,
60, -60]*1 )[:-1]:
left(angle)
forward(cell_side)
penup()
end_fill()
#-----Main Program to Call
follow_path(movements(), True) # <-- no argument for "movements"
when assessed
release_map()
#
#--------------------------------------------------------------------#
DD A B C D E LL F G H | J K
Python code, How do I add text in the red cube section, and how can I draw the hexagon on the left side in to the blue c
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Python code, How do I add text in the red cube section, and how can I draw the hexagon on the left side in to the blue c
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!