Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Trees
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
1MAE002 - ALGORITHM AND COMPUTING
Advanced
Trees
Commits
3c9a2a54
Unverified
Commit
3c9a2a54
authored
Jul 1, 2024
by
STEVAN Antoine
Browse files
Options
Downloads
Patches
Plain Diff
add `src.ui.qtree` module
parent
a574dbf0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ui/qtree.py
+101
-0
101 additions, 0 deletions
src/ui/qtree.py
with
101 additions
and
0 deletions
src/ui/qtree.py
0 → 100644
+
101
−
0
View file @
3c9a2a54
from
dataclasses
import
dataclass
import
pygame
import
sys
COLORS
=
{
"
background
"
:
(
0
,
0
,
0
),
}
@dataclass
class
Canva
:
width
:
int
height
:
int
caption
:
str
frame_rate
:
int
screen
:
pygame
.
surface
.
Surface
=
None
clock
:
pygame
.
time
.
Clock
=
None
def
setup
(
self
):
pygame
.
init
()
self
.
screen
=
pygame
.
display
.
set_mode
((
self
.
width
,
self
.
height
))
pygame
.
display
.
set_caption
(
self
.
caption
)
self
.
clock
=
pygame
.
time
.
Clock
()
self
.
mouse
=
None
self
.
points
=
[]
def
__handle_events
(
self
):
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
QUIT
or
(
event
.
type
==
pygame
.
KEYDOWN
and
event
.
key
==
pygame
.
K_ESCAPE
):
pygame
.
quit
()
sys
.
exit
()
elif
event
.
type
==
pygame
.
MOUSEMOTION
:
self
.
mouse
=
event
.
pos
def
__render_qtree
(
self
,
qtree
):
x
=
qtree
.
boundary
.
x
y
=
qtree
.
boundary
.
y
w
=
qtree
.
boundary
.
w
h
=
qtree
.
boundary
.
h
pygame
.
draw
.
rect
(
self
.
screen
,
(
255
,
255
,
255
),
(
x
-
w
/
2
,
y
-
h
/
2
,
w
,
h
),
width
=
1
,
)
if
qtree
.
divided
:
self
.
__render_qtree
(
qtree
.
ne
)
self
.
__render_qtree
(
qtree
.
nw
)
self
.
__render_qtree
(
qtree
.
se
)
self
.
__render_qtree
(
qtree
.
sw
)
def
__render
(
self
,
f
):
self
.
screen
.
fill
(
COLORS
[
"
background
"
])
res
=
f
(
self
.
points
,
self
.
mouse
)
if
isinstance
(
res
,
list
)
and
isinstance
(
res
[
0
],
bool
):
for
p
,
c
in
zip
(
self
.
points
,
res
):
pygame
.
draw
.
circle
(
self
.
screen
,
(
255
,
255
,
255
)
if
c
else
(
100
,
100
,
100
),
(
p
.
x
,
p
.
y
),
p
.
r
,
)
else
:
qtree
,
range
=
res
self
.
__render_qtree
(
qtree
)
for
p
in
self
.
points
:
pygame
.
draw
.
circle
(
self
.
screen
,
(
255
,
255
,
255
),
(
p
.
x
,
p
.
y
),
p
.
r
)
pygame
.
draw
.
rect
(
self
.
screen
,
(
0
,
255
,
0
),
(
range
.
x
-
range
.
w
/
2
,
range
.
y
-
range
.
h
/
2
,
range
.
w
,
range
.
h
),
width
=
1
,
)
for
p
in
qtree
.
query
(
range
):
pygame
.
draw
.
circle
(
self
.
screen
,
(
0
,
255
,
0
),
(
p
.
x
,
p
.
y
),
p
.
r
)
pygame
.
display
.
flip
()
def
step
(
self
,
u
,
f
):
self
.
__handle_events
()
self
.
points
=
u
(
self
.
points
)
self
.
__render
(
f
)
self
.
clock
.
tick
(
self
.
frame_rate
)
def
loop
(
self
,
u
,
f
):
while
True
:
self
.
step
(
u
,
f
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment