← Back to Articles
Introduction to Arcade
Jamie Z 2024-06-09Learning Goals
- Learn to install and use arcade to create pictures and animations
- Understand how to loop a gradient background
Arcade
Arcade is a Python library for creating 2D video games. It is built on top of the Pyglet library and provides a simple, easy-to-use programming interface for creating games with 2D graphics.
Coordinates
- We will be drawing in the upper right quadrant.
- 0, 0 will be the lower left of the screen, and all negative coordinates will be off-screen.
- Each ”point” will be a pixel – a window that is 800 pixels wide, will have the x- coordinate run from 0 to 800.
Setting up a Window
- In order to see what you have drawn it needs to be in a window and the code you are drawing needs to appear inside the render.
import arcade
arcade.open_window(600,600, "Drawing and Animation")
arcade.start_render()
# Draw stuff
arcade.finish_render()
arcade.run()
Gradients
Colour
- We can specify colours through arcade.csscolor and arcade.color
- We can also specify colours through a colour picker, using RGB value – red, green, blue value.
Code
import arcade
screen_width = 800
screen_height = 800
arcade.open_window(screen_width, screen_height,"Draw with Loops")
arcade.set_background_color((255, 255, 255))
arcade.start_render()
def draw_sky(bottom, b, screen_height, screen_width):
arcade.draw_lrtb_rectangle_filled(0 ,screen_width, screen_height, bottom,(0,0,b))
#b = blue value, h = height of circle, w = width of circle
blue_value = 10
bottom_value = 60
# for i in range(number) means repeat something for (number) times.
for i in range(15):
b = blue_value + i*20
bottom = bottom_value + i*10 #bigger the value, bigger the rectangle
draw_sky(b, bottom, screen_height, screen_width)
arcade.finish_render()
arcade.run()