FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
DandyBot/plitk.py at main · true-grue/DandyBot · GitHub
true-grue
/
DandyBot
Public
Notifications
You must be signed in to change notification settings
Fork
51
Star
13
Code
Issues
0
Pull requests
3
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
DandyBot
/
plitk.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (42 loc) · 1.75 KB
Breadcrumbs
DandyBot
/
plitk.py
Copy path
File metadata and controls
50 lines (42 loc) · 1.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
json
from
pathlib
import
Path
import
tkinter
as
tk
def
load_tileset
(
filename
):
tileset
=
json
.
loads
(
Path
(
filename
).
read_text
())
tileset
[
"data"
]
=
Path
(
tileset
[
"file"
]).
read_bytes
()
return
tileset
def
get_tile_ppm
(
tileset
,
index
):
x
=
tileset
[
"tile_width"
]
*
(
index
%
tileset
[
"columns"
])
y
=
tileset
[
"tile_height"
]
*
(
index
//
tileset
[
"columns"
])
w
=
tileset
[
"columns"
]
*
tileset
[
"tile_width"
]
data
=
bytes
()
for
i
in
range
(
w
*
y
+
x
,
w
*
(
y
+
tileset
[
"tile_height"
])
+
x
,
w
):
data
+=
tileset
[
"data"
][
i
*
3
:
i
*
3
+
tileset
[
"tile_width"
]
*
3
]
return
bytes
(
"P6
\n
%d %d
\n
255
\n
"
%
(
tileset
[
"tile_width"
],
tileset
[
"tile_height"
]),
"ascii"
)
+
data
class
PliTk
:
def
__init__
(
self
,
canvas
,
x
,
y
,
cols
,
rows
,
tileset
,
scale
):
self
.
canvas
=
canvas
self
.
x
,
self
.
y
=
x
,
y
self
.
tileset
=
tileset
self
.
scale
=
scale
self
.
images
=
[]
self
.
tiles
=
[]
for
i
in
range
(
tileset
[
"size"
]):
self
.
images
.
append
(
tk
.
PhotoImage
(
data
=
get_tile_ppm
(
tileset
,
i
)).
zoom
(
scale
))
self
.
resize
(
cols
,
rows
)
def
resize
(
self
,
cols
,
rows
):
self
.
cols
,
self
.
rows
=
cols
,
rows
while
self
.
tiles
:
self
.
canvas
.
delete
(
self
.
tiles
.
pop
())
for
j
in
range
(
rows
):
for
i
in
range
(
cols
):
self
.
tiles
.
append
(
self
.
canvas
.
create_image
(
self
.
x
+
i
*
self
.
tileset
[
"tile_width"
]
*
self
.
scale
,
self
.
y
+
j
*
self
.
tileset
[
"tile_height"
]
*
self
.
scale
,
image
=
self
.
images
[
0
],
anchor
=
"nw"
))
def
set_tile
(
self
,
x
,
y
,
index
):
self
.
canvas
.
itemconfigure
(
self
.
tiles
[
self
.
cols
*
y
+
x
],
image
=
self
.
images
[
index
]
)
Back
|
FazBrowse Home
|
New Git URL