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: ##class ball All the methods are stubs. Your task is to complete them.
## IMPORTANT NOTES: A ball is not drawn on the turtle screen when it is created.
## It will only be drawn when its draw() method is called.
## Any attribute of a ball can be changed while the ball is drawn on the screen. If
## an outside program calls any of the functions that change the attribute(s) of a ball,
## the attribute(s) should be changed whether the ball is currently drawn or not. If the
## ball was drawn when the method was called and the attribute change would affect
## the image of the ball, then the ball should be redrawn using the new attributes.
## This may involve "erasing" the original dot on the screen by making a dot over it,
## using the screen color. If the ball is not drawn when the method is called, then the
## attribute change should be made, but the change should not trigger the drawing of the ball.
## If the draw method is called when a ball is already drawn or if the undraw method is called
## when the ball is currently not drawn, the method call should have no effect. It should not
## change whether the ball is drawn or not, and it should also not print anything, raise an
## error message or crash.
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: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:00
Which of the following is not contained on the slide show toolbar? a. next button b. slide button c. close button d. pen tool
Answers: 1
question
Computers and Technology, 22.06.2019 23:30
To check spelling errors in a document, the word application uses the to determine appropriate spelling. internet built-in dictionary user-defined words other text in the document
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
What is one reason why indoor air pollution has become an increasing problem.
Answers: 1
question
Computers and Technology, 23.06.2019 18:50
What is transmission control protocol/internet protocol (tcp/ip)? software that prevents direct communication between a sending and receiving computer and is used to monitor packets for security reasons a standard that specifies the format of data as well as the rules to be followed during transmission a simple network protocol that allows the transfer of files between two computers on the internet a standard internet protocol that provides the technical foundation for the public internet as well as for large numbers of private networks
Answers: 2
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, 08.03.2021 22:00
question
Mathematics, 08.03.2021 22:00
question
Social Studies, 08.03.2021 22:00
question
Mathematics, 08.03.2021 22:00
question
Mathematics, 08.03.2021 22:00
question
Geography, 08.03.2021 22:00
question
English, 08.03.2021 22:00
question
Mathematics, 08.03.2021 22:00
Questions on the website: 13722363