G.I.F.s
The resources on this page were originally created by Dr. Aaron Bradley of Summit Middle School. I've done some reformatting to add clarity but that is about it. Enjoy!
|
GIFs
If you've been wanting to make your graphics-based games look nicer, here's one way. The Graphic Interchange Format (or GIF) is a way to compress digital images. The sgfx module provides a function to import image files saved as GIFs.
To follow this tutorial, download the GIF files (below), and save them in your programming directory (i.e. your MyPrograms folder).
If you've been wanting to make your graphics-based games look nicer, here's one way. The Graphic Interchange Format (or GIF) is a way to compress digital images. The sgfx module provides a function to import image files saved as GIFs.
To follow this tutorial, download the GIF files (below), and save them in your programming directory (i.e. your MyPrograms folder).
|
|
The following code should look mostly familiar from an early graphics lesson. It loads the two images and adds keyboard-based controls to the second one. The first image was made to have size 500x500 so that it serves as a fancy background. Both images are loaded to appear with their centers at (250, 250), but the second one moves.
from sgfx import *
w = Window()
w.gif(250, 250, 'background.gif')
bfly = w.gif(250, 250, 'butterfly.gif')
def left():
w.move(bfly, -10, 0)
def right():
w.move(bfly, 10, 0)
def up():
w.move(bfly, 0, 10)
def down():
w.move(bfly, 0, -10)
w.on('4', left)
w.on('6', right)
w.on('8', up)
w.on('2', down)
w.run()
With a better image editor than MS Paint, one can make the background color of the foreground object (the butterfly in this case) transparent so that the surrounding white box disappears. But this tutorial at least gets you started on making prettier programs.