FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PyWeek30/utils.py at master · PythonixCoders/PyWeek30 · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
PythonixCoders
/
PyWeek30
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PyWeek30
/
utils.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
65 lines (46 loc) · 1.32 KB
Breadcrumbs
PyWeek30
/
utils.py
Copy path
File metadata and controls
65 lines (46 loc) · 1.32 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import
re
import
pygame
class
Position
:
def
__init__
(
self
,
pos
,
y
=
None
):
if
isinstance
(
pos
, (
tuple
,
list
)):
self
.
_x
,
self
.
_y
=
pos
elif
isinstance
(
pos
, (
float
,
int
)):
self
.
_x
,
self
.
_y
=
pos
,
y
elif
isinstance
(
pos
,
pygame
.
Vector2
):
self
.
_x
,
self
.
_y
=
pos
@
property
def
x
(
self
):
return
self
.
_x
@
x
.
setter
def
x
(
self
,
value
):
self
.
_x
=
value
@
property
def
y
(
self
):
return
self
.
_x
@
y
.
setter
def
y
(
self
,
value
):
self
.
_x
=
value
@
property
def
xy
(
self
):
return
self
.
_x
,
self
.
_y
@
xy
.
setter
def
xy
(
self
,
value
):
self
.
_x
,
self
.
_y
=
value
@
property
def
int_xy
(
self
):
return
int
(
self
.
_x
),
int
(
self
.
_y
)
def
__getitem__
(
self
,
key
):
return
self
.
xy
[
item
]
def
__setitem__
(
self
,
key
,
value
):
d
=
list
(
self
.
xy
)
d
[
key
]
=
value
def
__str__
(
self
):
return
f"(
{
self
.
_x
}
,
{
self
.
_y
}
)"
def
natural_sort
(
l
):
convert
=
lambda
text
:
int
(
text
)
if
text
.
isdigit
()
else
text
.
lower
()
alphanum_key
=
lambda
key
: [
convert
(
c
)
for
c
in
re
.
split
(
'([0-9]+)'
,
key
)]
return
sorted
(
l
,
key
=
alphanum_key
)
def
image_load
(
path
):
return
pygame
.
image
.
load
(
str
(
path
))
def
object_to_rect
(
obj
):
return
pygame
.
Rect
(
obj
.
x
,
obj
.
y
,
obj
.
width
,
obj
.
height
)
Back
|
FazBrowse Home
|
New Git URL