Write a python program that will allow a user to draw by inputting commands. The program...

90.2K

Verified Solution

Question

Programming

Write a python program that will allow a user to draw byinputting commands. The program will load all of the commands first(until it reaches command \"exit\" or \"done\"), and then create thedrawing.

Must include the following:

change attributes:

  • color [red | green | blue]

  • width [value]

  • heading [value]

  • position [xval] [yval]

drawing:

  • draw_axes

  • draw_tri [x1] [y1] [x2] [y2] [x3] [y3

  • draw_rect [x] [y] [b] [h]

  • draw_poly [x] [y] [n] [s]

  • draw_path [path]

random

  • random [color | width | heading | position]

    • e.g. \"random color\" would set turtle to a random drawingcolor

Heres my starter code:

import turtle

#================ command loading=================

lines = [] #initialize empty list

# load up all commands into the list
def load_commands():
  
while(1):
  
line = input('>')
  
words = line.split()
if words[0] == 'exit':
break
  
lines.append(line)

#============== turtle drawing functions============

def draw_rect(alex, x, y, b, h):
alex.pu()
alex.goto(x,y)
alex.pd()
  
for i in range(2):
alex.fd(b)
alex.lt(90)
alex.fd(h)
alex.lt(90)
  
#==================== process commands (do thedrawing)======

def process_commands():
  
# ------ initialize turtle stuff ----------------
  
turtle.TurtleScreen._RUNNING=True
  
wn = turtle.Screen() # Set up the window and its attributes
wn.bgcolor(\"lightgreen\")
wn.title(\"Alex meets a function\")
  
alex = turtle.Turtle() # Create alex
  
#-----------------------------------------
  
# process each line and draw
for line in lines:
  
words = line.split()
  
if words[0] == \"draw_rect\":
x = int(words[1])
y = int(words[2])
b = int(words[3])
h = int(words[4])
draw_rect(alex,x,y,b,h)
  
  
wn.exitonclick()
  
#================== MAIN ======================
  
def main():
print(\"loading commands\")
load_commands()
print(\"drawing\")
process_commands()
  

main()

Answer & Explanation Solved by verified expert
3.8 Ratings (755 Votes)
PROGRAMOUTPUTSUMMARYProgram to load commands and draw based on the commands Step1 Load commandsload the command to list till exit ordoneStep2 Process    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students