Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flow3r
flow3r firmware
Commits
c861e487
Commit
c861e487
authored
1 year ago
by
moon2
Browse files
Options
Downloads
Patches
Plain Diff
worms: 2x fps
parent
8ac0fa33
No related branches found
No related tags found
No related merge requests found
Pipeline
#7387
failed
1 year ago
Stage: check
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_payload/apps/demo_worms/__init__.py
+21
-33
21 additions, 33 deletions
python_payload/apps/demo_worms/__init__.py
with
21 additions
and
33 deletions
python_payload/apps/demo_worms/__init__.py
+
21
−
33
View file @
c861e487
...
...
@@ -21,55 +21,42 @@ class AppWorms(Application):
def
__init__
(
self
,
app_ctx
:
ApplicationContext
)
->
None
:
super
().
__init__
(
app_ctx
)
# HACK: we work against double buffering by keeping note of how many
# times on_draw got called.
#
# We know there's two buffers, so if we render the same state twice in a
# row we'll be effectively able to keep a persistent framebuffer, like
# with the old API.
#
# When bufn is in [0, 1] we render the background image.
# When bufn is in [2, ...) we render the worms.
# When bufn is > 3, we enable updating the worm state.
#
# TODO(q3k): allow apps to request single-buffered graphics for
# persistent framebuffers.
self
.
bufn
=
0
self
.
worms
=
[]
for
i
in
range
(
0
):
self
.
worms
.
append
(
Worm
())
self
.
just_shown
=
Tru
e
self
.
just_shown
=
Fals
e
def
on_enter
(
self
,
vm
:
Optional
[
ViewManager
])
->
None
:
# print("on foreground")
super
().
on_enter
(
vm
)
self
.
just_shown
=
True
def
draw
(
self
,
ctx
:
Context
)
->
None
:
if
self
.
bufn
<=
5
:
ctx
.
rgb
(
*
BLUE
).
rectangle
(
-
120
,
-
120
,
240
,
240
).
fill
()
self
.
just_shown
=
False
self
.
_bg
=
3
# animation requires multiple bg draws at the moment
self
.
worms
=
[]
# reset worms
ctx
.
text_align
=
ctx
.
CENTER
ctx
.
text_baseline
=
ctx
.
MIDDLE
ctx
.
move_to
(
0
,
0
).
rgb
(
*
WHITE
).
text
(
"
touch me :)
"
)
self
.
bufn
+=
1
def
draw_background
(
self
,
ctx
):
ctx
.
rgb
(
*
BLUE
).
rectangle
(
-
120
,
-
120
,
240
,
240
).
fill
()
return
ctx
.
text_align
=
ctx
.
CENTER
ctx
.
text_baseline
=
ctx
.
MIDDLE
ctx
.
move_to
(
0
,
0
).
rgb
(
*
WHITE
).
text
(
"
touch me :)
"
)
for
w
in
self
.
worms
:
w
.
draw
(
ctx
)
self
.
bufn
+=
1
def
draw
(
self
,
ctx
:
Context
)
->
None
:
if
self
.
_bg
>
0
:
self
.
draw_background
(
ctx
)
self
.
_bg
-=
1
else
:
for
w
in
self
.
worms
:
w
.
draw
(
ctx
)
self
.
just_shown
=
True
def
think
(
self
,
ins
:
InputState
,
delta_ms
:
int
)
->
None
:
super
().
think
(
ins
,
delta_ms
)
# Simulation is currently locked to FPS.
if
self
.
bufn
>
7
:
if
self
.
just_shown
:
for
w
in
self
.
worms
:
w
.
move
()
self
.
bufn
=
6
self
.
just_shown
=
False
for
index
,
petal
in
enumerate
(
self
.
input
.
captouch
.
petals
):
if
petal
.
whole
.
pressed
or
petal
.
whole
.
repeated
:
self
.
worms
.
append
(
Worm
(
-
tau
*
index
/
10
+
math
.
pi
))
...
...
@@ -126,6 +113,7 @@ class Worm:
self
.
size
+=
1
self
.
speed
=
self
.
size
/
5
self
.
speed
/=
2
# temporary hack bc framerate doubling
self
.
direction
+=
(
random
.
random
()
-
0.5
)
*
math
.
pi
/
4
...
...
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