forked from kitao/pyxel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_draw_api.py
executable file
·175 lines (125 loc) · 4.21 KB
/
03_draw_api.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import math
import pyxel
class App:
def __init__(self):
pyxel.init(200, 150, caption="Pyxel Draw API")
pyxel.image(0).load(0, 0, "assets/cat_16x16.png")
pyxel.image(1).load(0, 0, "assets/tileset_24x32.png")
pyxel.tilemap(0).set(
0,
0,
["022000002004001000060061062000040", "042003020021022003000001002003060"],
)
pyxel.tilemap(0).refimg = 1
self.pal_test_is_enabled = False
self.clip_test_is_enabled = False
pyxel.mouse(True)
pyxel.run(self.update, self.draw)
def update(self):
self.pal_test_is_enabled = (pyxel.frame_count // 30) % 10 >= 5
self.clip_test_is_enabled = pyxel.btn(pyxel.KEY_SPACE)
if pyxel.btnp(pyxel.KEY_Q):
pyxel.quit()
def draw(self):
self.test_pal1()
self.test_cls(6, 6)
self.test_clip()
self.test_pset(6, 20)
self.test_line(106, 6)
self.test_rect(6, 38)
self.test_rectb(106, 38)
self.test_circ(6, 61)
self.test_circb(106, 61)
self.test_blt(6, 88)
self.test_bltm(106, 88)
self.test_text(6, 124)
self.test_pal2(106, 124)
def test_pal1(self):
if self.pal_test_is_enabled:
pyxel.pal(5, 2)
pyxel.pal(12, 7)
pyxel.pal(7, 10)
def test_pal2(self, x, y):
pyxel.text(x, y, "pal(col1,col2)", 12)
pyxel.pal()
def test_cls(self, x, y):
pyxel.cls(5)
pyxel.text(x, y, "cls(col)", 7)
def test_clip(self):
pyxel.clip()
if not self.clip_test_is_enabled:
return
x = math.sin(pyxel.frame_count * 0.02) * 39 + 40
y = math.sin(pyxel.frame_count * 0.03) * 29 + 30
w = 120
h = 90
pyxel.text(x, y - 8, "clip(x,y,w,h)", 14)
pyxel.rectb(x - 1, y - 1, w + 2, h + 2, 14)
pyxel.clip(x, y, w, h)
def test_pset(self, x, y):
pyxel.text(x, y, "pset(x,y,col)", 7)
x += 4
y += 10
for i in range(16):
pyxel.pset(x + i * 2, y, i)
def test_line(self, x, y):
pyxel.text(x, y, "line(x1,y1,x2,y2,col)", 7)
x += 4
y += 9
col = 5
for i in range(3):
pyxel.line(x, y + i * 8, x + 48, y + i * 8, col)
col += 1
for i in range(4):
pyxel.line(x + i * 16, y, x + i * 16, y + 16, col)
col += 1
for i in range(4):
pyxel.line(x + i * 16, y, x + (3 - i) * 16, y + 16, col)
col += 1
def test_rect(self, x, y):
pyxel.text(x, y, "rect(x,y,w,h,col)", 7)
x += 4
y += 16
for i in range(8):
pyxel.rect(x + i * 8, y - i, i + 1, i + 1, i + 8)
def test_rectb(self, x, y):
pyxel.text(x, y, "rectb(x,y,w,h,col)", 7)
x += 4
y += 16
for i in range(8):
pyxel.rectb(x + i * 8, y - i, i + 1, i + 1, i + 8)
def test_circ(self, x, y):
pyxel.text(x, y, "circ(x,y,r,col)", 7)
x += 4
y += 15
for i in range(8):
pyxel.circ(x + i * 8, y, i, i + 8)
def test_circb(self, x, y):
pyxel.text(x, y, "circb(x,y,r,col)", 7)
x += 4
y += 15
for i in range(8):
pyxel.circb(x + i * 8, y, i, i + 8)
def test_blt(self, x, y):
pyxel.text(x, y, "blt(x,y,img,u,v,\n w,h,[colkey])", 7)
y += 15
offset = math.sin(pyxel.frame_count * 0.1) * 2
pyxel.blt(x, y, 0, 0, 0, 16, 16)
pyxel.blt(x + offset + 19, y, 0, 0, 0, 16, 16, 13)
pyxel.blt(x + 38, y, 0, 0, 0, -16, 16, 13)
pyxel.blt(x + 57, y, 0, 0, 0, 16, -16, 13)
pyxel.blt(x + 76, y, 0, 0, 0, -16, -16, 13)
def test_bltm(self, x, y):
pyxel.text(x, y, "bltm(x,y,tm,u,v,\n w,h,[colkey])", 7)
y += 15
pyxel.bltm(x, y, 0, 0, 0, 11, 2, 2)
def test_text(self, x, y):
pyxel.text(x, y, "text(x,y,s,col)", 7)
x += 4
y += 8
s = "Elapsed frame count is {}\n" "Current mouse position is ({},{})".format(
pyxel.frame_count, pyxel.mouse_x, pyxel.mouse_y
)
pyxel.text(x + 1, y, s, 1)
pyxel.text(x, y, s, 9)
App()