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
e00ccc6c
Commit
e00ccc6c
authored
1 year ago
by
iggy
Committed by
q3k
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
demo_worms.py: cleanup and more OO
parent
23300ace
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_payload/demo_worms.py
+19
-21
19 additions, 21 deletions
python_payload/demo_worms.py
with
19 additions
and
21 deletions
python_payload/demo_worms.py
+
19
−
21
View file @
e00ccc6c
#python
#python
imports
import
random
import
time
import
math
#
badge23
#
flow3r imports
import
event
import
application
import
ui
# Subclass Application
class
AppWorms
(
application
.
Application
):
...
...
@@ -21,6 +22,13 @@ class AppWorms(application.Application):
self
.
frame_slack
=
None
self
.
last_report
=
None
self
.
add_event
(
event
.
Event
(
name
=
"
worms_control
"
,
action
=
self
.
handle_input
,
condition
=
lambda
data
:
data
.
get
(
"
type
"
,
""
)
==
"
captouch
"
and
data
.
get
(
"
value
"
)
==
1
and
data
[
"
change
"
],
)
)
self
.
worms
=
[]
for
i
in
range
(
0
):
worms
.
append
(
Worm
())
...
...
@@ -64,26 +72,12 @@ class AppWorms(application.Application):
self
.
last_render
=
now
app
=
AppWorms
(
"
worms
"
)
def
handle_input
(
self
,
data
):
worms
=
app
.
worms
worms
.
append
(
Worm
(
data
.
get
(
"
index
"
,
0
)
*
2
*
math
.
pi
/
10
+
math
.
pi
))
if
len
(
worms
)
>
10
:
worms
.
pop
(
0
)
def
handle_input
(
data
):
worms
=
app
.
worms
worms
.
append
(
Worm
(
data
.
get
(
"
index
"
,
0
)
*
2
*
math
.
pi
/
10
+
math
.
pi
))
if
len
(
worms
)
>
10
:
worms
.
pop
(
0
)
app
.
add_event
(
event
.
Event
(
name
=
"
worms_control
"
,
action
=
handle_input
,
condition
=
lambda
data
:
data
.
get
(
"
type
"
,
""
)
==
"
captouch
"
and
data
.
get
(
"
value
"
)
==
1
and
data
[
"
change
"
],
)
)
app
.
add_event
(
event
.
Event
(
name
=
"
worms_exit
"
,
action
=
app
.
exit
,
condition
=
lambda
e
:
e
[
"
type
"
]
==
"
button
"
and
e
.
get
(
"
from
"
)
==
2
and
e
[
"
change
"
]
))
class
Worm
():
def
__init__
(
self
,
direction
=
None
):
...
...
@@ -139,6 +133,10 @@ class Worm():
self
.
mutate
()
self
.
_lastdist
=
dist
app
=
AppWorms
(
"
worms
"
)
# To run standalone:
#app.run()
#app.engine.eventloop()
...
...
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