-
Notifications
You must be signed in to change notification settings - Fork 1
/
xx_pset_and_pget.py
46 lines (32 loc) · 1 KB
/
xx_pset_and_pget.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
"""
pset sets a pixel color. pget gets a pixel color.
Kris Pritchard / @krp
"""
import pyxel
class App:
def __init__(self):
# Initialize the screen.
pyxel.init(256, 256)
# Clear the screen
pyxel.cls(0)
# Enable the mouse
pyxel.mouse(True)
# Run the app.
pyxel.run(self.update, self.draw)
def update(self):
pass
def draw(self):
mouse_x = pyxel.mouse_x
mouse_y = pyxel.mouse_y
# Loop through the pixels, setting them different colors.
pyxel.cls(0)
# NOTE: This seems to be really slow. Probably best not to use pset()
for i in range(256):
for j in range(256):
pyxel.pset(i, j, i % 16)
# Draw a black rectangle
pyxel.rect(60, 74, 150, 30, 0)
# Draw text of mouse position
pyxel.text(80, 80, f'Mouse Position: ({mouse_x}, {mouse_y})', 7)
pyxel.text(80, 90, f'Pixel Color: {pyxel.pget(mouse_x, mouse_y)}', 7)
App()