Menu

[Solved]Python Turtle Graphics Set Turtle Square Shape Move Top Left Corner Screen Towards Bottom Q37128976

Python Turtle Graphics : set the turtle to asquare shape, and move it from the top left corner of thescreen towards the bottom right corner,getting bigger as it moves along.

the square turtle’s start size is 0.5 and it grows 0.01 at eachiteration. The turtle travel distance in each iteration must be setto the (total path length / 100).

The current code I have below works; except it doesn’talways go to the bottom right corner of the screen eachtime it is ran because the height and width is chosen randomly andchanges. Please help me fix this issue.

CURRENT CODE:

import turtle

import random

numbers = (100, 200, 300, 400, 500, 600, 700, 800, 900)

width = random.choice(numbers)
height = random.choice(numbers)

turtle.setup(width,height)
# get reference to turtle window
window = turtle.Screen()
# set window title bar
window.title(‘A Turtle moving from top left corner to bottom rightcorner’)
aTurtle = turtle.Turtle()

def movingaturtle(aTurtle, window):

aTurtle.ht()
aTurtle.penup()
height=window.window_height()
width=window.window_width()
aTurtle.speed(1)
aTurtle.left(310)#turning turtle towards bottom right corner
aTurtle.shape(‘square’)
aTurtle.setposition((-width//2),(height//2))

  
c=100
size=.5
aTurtle.turtlesize(size)
while c>1:
aTurtle.showturtle()
aTurtle.turtlesize(size)
c=c+1
size=size+.01
aTurtle.forward(height//100)
  

Expert Answer


Answer to Python Turtle Graphics : set the turtle to a square shape, and move it from the top left corner of the screen towards th… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *