forked from ernestas-poskus/interactive-programming-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsprites-animations.py
More file actions
32 lines (23 loc) · 1004 Bytes
/
sprites-animations.py
File metadata and controls
32 lines (23 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# demo of animation using asteroid sprite sheet
import simplegui
# load 64 frame sprite sheer for asteroid - image source is opengameart, artist is warspawn
ROCK_CENTER = [64, 64]
ROCK_SIZE = [128, 128]
ROCK_DIM = 64
rock_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/asteroid1.opengameart.warspawn.png")
# global time for animation
time = 0
# draw handler
def draw(canvas):
global time
current_rock_index = (time % ROCK_DIM) // 1
current_rock_center = [ROCK_CENTER[0] + current_rock_index * ROCK_SIZE[0], ROCK_CENTER[1]]
canvas.draw_image(rock_image, current_rock_center, ROCK_SIZE, ROCK_CENTER, ROCK_SIZE)
time += 0.2
# create frame and size frame based on 128x128 pixel sprite
frame = simplegui.create_frame("Asteroid sprite", ROCK_SIZE[0], ROCK_SIZE[1])
# set draw handler and canvas background using custom HTML color
frame.set_draw_handler(draw)
frame.set_canvas_background("Blue")
# start animation
frame.start()