Computers and Technology
Computers and Technology, 07.12.2021 23:40, poppy1173

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)

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 00:00, dubouuu
Donna and her team of five have invented a new gadget for the science exhibition in their college. which intellectual property right will protect their invention?
Answers: 1
image
Computers and Technology, 23.06.2019 11:00, swelch2010
Describe three characteristics of at-risk drivers. a. b. c. describe three characteristics of safe drivers. a. b. c. describe three driver errors that could cause a collision. a. b. c. how will this information affect you as a driver now and in the future? (2-3 sentences)
Answers: 2
image
Computers and Technology, 24.06.2019 12:30, hilario4785
Why does the pc send out a broadcast arp prior to sending the first ping request
Answers: 1
image
Computers and Technology, 24.06.2019 13:30, andybiersack154
Consider jasper’s balance sheet. which shows how to calculate jasper’s net worth?
Answers: 1
Do you know the correct answer?
My assignment is to create a class called “ball” that is represented by a dot on the turtle window....

Questions in other subjects:

Konu
Mathematics, 02.04.2021 19:00
Konu
Mathematics, 02.04.2021 19:00