def draw_archery_target(): """ 3. Write a function, draw_archery_target(), that draws a coloured target consisting of concentric circles of yellow (innermost), red and blue. The sizes of the circles should be in correct proportion i.e. the red circle should have a radius twice that of the yellow circle, and the blue circle should have a radius three times that of the yellow circle. Hint: objects drawn later will appear on top of objects drawn earlier. """ win = GraphWin("Target") win.setCoords(0, 0, 1, 1) centre = Point(0.5, 0.5) yellow_circle = Circle(centre, 0.1) yellow_circle.setFill("yellow") red_circle = Circle(centre, yellow_circle.getRadius() * 2) red_circle.setFill("red") blue_circle = Circle(centre, yellow_circle.getRadius() * 3) blue_circle.setFill("blue") blue_circle.draw(win) red_circle.draw(win) yellow_circle.draw(win) await_user_input(win)
class Wheel(): def __init__(self, center, wheel_radius, tire_radius): self.tire_circle = Circle(center, tire_radius) self.wheel_circle = Circle(center, wheel_radius) def draw(self, win): self.tire_circle.draw(win) self.wheel_circle.draw(win) def move(self, dx, dy): self.tire_circle.move(dx, dy) self.wheel_circle.move(dx, dy) def set_color(self, wheel_color, tire_color): self.tire_circle.setFill(tire_color) self.wheel_circle.setFill(wheel_color) def undraw(self): self.tire_circle .undraw() self.wheel_circle .undraw() def get_size(self): return self.tire_circle.getRadius() def get_center(self): return self.tire_circle.getCenter() def animate(self, win, dx, dy, n): if n > 0: self.move(dx, dy) win.after(100, self.animate, win, dx, dy, n - 1)
def update(win: GraphWin, sun: Circle): if sun.getP1().x - sun.getRadius() > win.width: sun.move(-win.width - 2 * sun.getRadius() - 20, 0) sun.move(1, 0)
class Player: def __init__(self, pos, r, vel=1.0, c=color_rgb(255, 255, 255)): self.pos = pos #position self.radius = r #radius self.vel = vel #velocity self.colour = c self.object = Circle(self.pos, r) self.object.setFill(c) self.object.setOutline('black') self.bullets = [] #bullet list self.score = 0 print(self.object.getRadius()) def modifyScore(self, value): self.score += value #print("Score:"+str(self.score)) def getScore(self): return self.score def update(self, dt, win): x = 0.0 y = 0.0 if k.kUp(): #If key up is pressed y -= self.vel * dt if k.kDown(): #If key down is pressed y += self.vel * dt if k.kLeft(): #If key left is pressed x -= self.vel * dt if k.kRight(): #If key right is pressed x += self.vel * dt #Check if mouse has been clicked mouse = k.kMouseLeft(win) if mouse != None: #print(mouse) self.bullets.append( Bullet(self.pos, win, 10, Point(mouse.getX(), mouse.getY()), 1000, self.colour)) #Update bullets and check if out of bounds for bullet in self.bullets: bullet.update(dt, win) if bullet.getAliveFlag() != True: bullet.undraw() self.bullets.remove(bullet) self.object.move(x, y) self.pos = self.object.getCenter() def getBullets(self): return self.bullets def getObject(self): return self.object def getRadius(self): return self.object.getRadius() def getPos(self): return self.pos def draw(self, win): self.object.draw(win) #undraw object def undraw(self): self.object.undraw()