forked from ernestas-poskus/interactive-programming-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_tiled_images.py
More file actions
40 lines (29 loc) · 1.02 KB
/
Copy pathclass_tiled_images.py
File metadata and controls
40 lines (29 loc) · 1.02 KB
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
31
32
33
34
35
36
37
38
39
40
# demo for drawing using tiled images
import simplegui
# define globals for cards
RANKS = ('A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K')
SUITS = ('C', 'S', 'H', 'D')
# card sprite - 950x392
CARD_CENTER = (36.5, 49)
CARD_SIZE = (73, 98)
card_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/cards.jfitz.png")
# define card class
class Card:
def __init__(self, suit, rank):
self.rank = rank
self.suit = suit
def draw(self, canvas, loc):
i = RANKS.index(self.rank)
j = SUITS.index(self.suit)
card_pos = [CARD_CENTER[0] + i * CARD_SIZE[0],
CARD_CENTER[1] + j * CARD_SIZE[1]]
canvas.draw_image(card_image, card_pos, CARD_SIZE, loc, CARD_SIZE)
# define draw handler
def draw(canvas):
one_card.draw(canvas, (155, 90))
# define frame and register draw handler
frame = simplegui.create_frame("Card draw", 300, 200)
frame.set_draw_handler(draw)
# createa card
one_card = Card('S', '6')
frame.start()