subject

My assignment is to create a class called “ball” that is represented by a dot on the turtle window. The class implements rudimentary methods to allow the ball to be animated, moving around the screen in two dimensions. The user will be able to tell the ball to move to a particular spot, move by a specific amount, change size or change color. For this assignment, we will NOT try to make the motion completely smooth. This assignment can be done with the turtle commands we already have. How would I do this? Here is the code I was already given: from turtle import *
from time import sleep
colormode(255)
speed(0)
hideturtle()
class ball:
'''defines a class for a ball which is represented ( if drawn) as a dot on the
turtle screen. If an attribute is changed, the dot is redrawn if it was already
drawn. If the ball was not visible (drawn) before the attribute was changed, it is
not redrawn until its draw method is called.'''
def __init__(self, location=(0,0),size=30,fill=(0,0,0) ,bgcolor=(255,255,255)):
self. location = location
self. size = size
self. fill = fill
self. bgcolor = bgcolor
self. drawn = False #instance is invisible, but does exist
def draw(self):
'''draws a dot on the screen, representing the instance's size, color, and location'''
return
def undraw(self):
'''removes the dot from the screen, (but the instance still exists)'''
return
def moveTo(self, newLocation=(0,0)):
'''changes location to newLocation, and redraws dot if needed'''
return
def moveToward(self, targetLocation=(0,0),distance=10.0) :
'''changes location to a new location 'distance' pixels closer to the targetLocation, and redraws dot if needed'''
alreadyDrawn = self. drawn
if alreadyDrawn:
self. undraw()
penup()
dx=self. location[0]-targetLocation[0]
dy=self. location[1]-targetLocation[1]
wholeDistance = sqrt(dx^2+dy^2)
proportion = distance/wholeDistance
moveVector = (dx*proportion, dy*proportion)
self. move(moveVector)
if alreadyDrawn:
self. draw()
return
def move(self, vector = (0,0)):
'''changes location to location + vector, and redraws dot if needed'''
return
def resize(self, increment=1):
'''changes size to size + increment, and redraws dot if needed'''
return
def set_size(self, newSize=30):
'''changes size to newSize, and redraws dot if needed'''
return
def get_size(self):
'''returns current size'''
return self. size
def get_position(self):
'''returns current position as tuple (x, y)'''
return (0,0)
def set_color(self, newColor=(0,0,0)):
'''changes fill color to newColor and redraws dot if needed'''
return
def get_color(self):
'''return current fill color as a tuple (r, g,b)'''
return (0,0,0)
def store_ball(self, fileName='dummy. txt'):
'''write the attributes of the ball to a file'''
return
def read_ball(self, fileName='dummy. txt'):
'''read the attributes of the ball from a file'''
return
if __name__ == '__main__':
#help(ball)
a = ball()
a. draw()
for i in range(10,100,5):
a. moveTo((i, i))
sleep(.01)
a. moveTo((0,0))
sleep(1)
for i in range(0,20):
a. move((-5,-5))
sleep(.01)
sleep(1)
current = a. get_size()
for i in range(0,10):
a. set_size(current+3*i)
sleep(.01)
sleep(1)
for i in range(0,10):
a. resize(-3)
sleep(.01)

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:30
What do character formats do for your document's message? a.set the tone b.provide organization c.provide clarity d.set how texts align with documents
Answers: 2
question
Computers and Technology, 22.06.2019 17:30
Working on this program in python 3.7: a year in the modern gregorian calendar consists of 365 days. in reality, the earth takes longer to rotate around the sun. to account for the difference in time, every 4 years, a leap year takes place. a leap year is when a year has 366 days: an extra day, february 29th. the requirements for a given year to be a leap year are: 1) the year must be divisible by 42) if the year is a century year (1700, 1800, the year must be evenly divisible by 400some example leap years are 1600, 1712, and 2016.write a program that takes in a year and determines whether that year is a leap year.ex: if the input is 1712, the output is: 1712 is a leap year. ex: if the input is 1913, the output is: 1913 is not a leap year. your program must define and call the function isleapyear(useryear). the function should return true if the input year is a leap year and false otherwise.
Answers: 1
question
Computers and Technology, 22.06.2019 18:40
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
question
Computers and Technology, 22.06.2019 23:30
For her science class, elaine is creating a presentation on weather in the united states. she wants to make the presentation beautiful and interesting by drawing simple cloud or wave shapes. which is the best way for elaine to draw these shapes?
Answers: 1
You know the right answer?
My assignment is to create a class called “ball” that is represented by a dot on the turtle window....
Questions
question
Mathematics, 07.02.2021 06:30
question
Mathematics, 07.02.2021 06:30
question
Chemistry, 07.02.2021 06:30
question
Mathematics, 07.02.2021 06:30
Questions on the website: 13722361