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 06:00
What are the most likely causes of conflict at the meeting? check all that apply.
Answers: 1
question
Computers and Technology, 22.06.2019 18:30
All of the following are characteristics that must be contained in any knowledge representation scheme except
Answers: 3
question
Computers and Technology, 23.06.2019 17:30
When making changes to optimize part of a processor, it is often the case that speeding up one type of instruction comes at the cost of slowing down something else. for example, if we put in a complicated fast floating-point unit, that takes space, and something might have to be moved farther away from the middle to accommodate it, adding an extra cycle in delay to reach that unit. the basic amdahl's law equation does not take into account this trade-off. a. if the new fast floating-point unit speeds up floating-point operations by, on average, 2ă—, and floating-point operations take 20% of the original program's execution time, what is the overall speedup (ignoring the penalty to any other instructions)? b. now assume that speeding up the floating-point unit slowed down data cache accesses, resulting in a 1.5ă— slowdown (or 2/3 speedup). data cache accesses consume 10% of the execution time. what is the overall speedup now? c. after implementing the new floating-point operations, what percentage of execution time is spent on floating-point operations? what percentage is spent on data cache accesses?
Answers: 2
question
Computers and Technology, 23.06.2019 20:30
What are some settings you can control when formatting columns?
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, 08.07.2021 17:00
question
English, 08.07.2021 17:00
question
Mathematics, 08.07.2021 17:00
question
Mathematics, 08.07.2021 17:00
question
Mathematics, 08.07.2021 17:00