Simple Shapes

Let’s animate a circle instead of text.

Code

import arcade


class MyGame(arcade.Window):
    def __init__(self, width, height, title, bg_color):
        super().__init__(width, height, title)
        arcade.set_background_color(bg_color)
        self.width = width
        self.height = height
        self.position = 0
        self.velocity = 10
        self.radius = 30

    def on_draw(self):
        arcade.start_render()
        y = self.height / 2
        arcade.draw_circle_filled(self.position, y, self.radius, arcade.color.RED)

    def update(self, delta_time):
        self.position += self.velocity


def main():
    game1 = MyGame(600, 600, 'Drawing Example', arcade.color.WHEAT)
    game1.position = 1
    arcade.run()


if __name__ == '__main__':
    main()

Analysis

  1. We draw a filled circle
  2. We can get rid of storing self.title, as we don’t use it anywhere else
  3. Make an instance attribute for the speed of movement
  4. Change the starting position to 1

Exercises

  1. Adjust the speed and see the effect