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:40
Design a pos circuit that displays the letters a through j on a seven-segment indicator. the circuit has four inputs w, x, y, and z which represent the last 4 bits of the uppercase ascii code for the letter to be displayed. thus, if wxyz = 0001 then "a" will be displayed. (any answer with 22 or fewer gates and inverters, not counting any for the inputs, is acceptable)
Answers: 2
question
Computers and Technology, 22.06.2019 15:00
The three logical operators used to write compound conditions are "and," "or," and "not." a: true b: false
Answers: 2
question
Computers and Technology, 23.06.2019 19:30
2. fluorine and chlorine molecules are blamed fora trapping the sun's energyob forming acid rainoc producing smogod destroying ozone molecules
Answers: 2
question
Computers and Technology, 24.06.2019 02:30
Assume a class window with accessor method getwidth that accepts no parameters and returns an integer. assume further an array of 3 window elements named winarr, has been declared and initialized. write a sequence of statements that prints out the width of the widest window in the array.
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, 19.04.2021 15:40
question
Computers and Technology, 19.04.2021 15:40
Questions on the website: 13722362