Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COMP2215 - Bouncing Ball
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djp1g21
COMP2215 - Bouncing Ball
Commits
cb68ff1c
Commit
cb68ff1c
authored
2 years ago
by
djp1g21
Browse files
Options
Downloads
Patches
Plain Diff
Added skeleton code
parent
680b7e12
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
Stub.py
+102
-0
102 additions, 0 deletions
Stub.py
with
102 additions
and
0 deletions
Stub.py
0 → 100644
+
102
−
0
View file @
cb68ff1c
"""
Author: Daniel Piper (djp1g21)
"""
from
pimoroni
import
Button
from
picographics
import
PicoGraphics
,
DISPLAY_PICO_DISPLAY
,
PEN_P4
# TODO: get PicoGraphics display
# Display buttons
# TODO: get display buttons
# Pen definitions
# TODO: define some PicoGraphic pens
# Simulation variables
FORCE
:
float
=
20000.0
# Attractive force of the buttons. Could alternatively be negative.
AIR_RESISTANCE
:
float
=
0.95
# Scalar applied to the ball's velocity each step. 0.0 < x <= 1.0
BOUNCE_ABSORPTION
:
float
=
0.8
# Scalar applied to the ball's appropriate velocity component upon hitting a wall. 0.0 < x <= 1.0
# Maximum trail length
TRAIL_LIMIT
:
int
=
20
# Main class to store the ball's position, velocity, and behaviour
class
Ball
:
_pos_x
:
float
=
0
_pos_y
:
float
=
0
_vel_x
:
float
=
0.0
_vel_y
:
float
=
0.0
_radius
:
int
=
0
_trail
:
list
[
tuple
[
float
,
float
]]
=
[]
def
__init__
(
self
,
pos_x
:
float
,
pos_y
:
float
,
radius
:
int
,
vel_x
:
float
=
0.0
,
vel_y
:
float
=
0.0
):
self
.
_pos_x
=
pos_x
self
.
_pos_y
=
pos_y
self
.
_radius
=
radius
self
.
_vel_x
=
vel_x
self
.
_vel_y
=
vel_y
# Setters
def
set_pos_x
(
self
,
value
:
float
|
int
)
->
None
:
self
.
_pos_x
=
float
(
value
)
def
set_pos_y
(
self
,
value
:
float
|
int
)
->
None
:
self
.
_pos_y
=
float
(
value
)
def
set_vel_x
(
self
,
value
:
float
|
int
)
->
None
:
self
.
_vel_x
=
float
(
value
)
def
set_vel_y
(
self
,
value
:
float
|
int
)
->
None
:
self
.
_vel_y
=
float
(
value
)
def
set_radius
(
self
,
value
:
int
)
->
None
:
self
.
_vel_y
=
value
# Getters
def
get_pos_x
(
self
)
->
float
:
return
self
.
_pos_x
def
get_pos_y
(
self
)
->
float
:
return
self
.
_pos_y
def
get_vel_x
(
self
)
->
float
:
return
self
.
_vel_x
def
get_vel_y
(
self
)
->
float
:
return
self
.
_vel_y
def
get_radius
(
self
)
->
int
:
return
self
.
_radius
def
get_trail
(
self
)
->
list
[
tuple
[
int
,
int
]]:
return
self
.
_trail
# Velocity increasers
def
inc_vel_x
(
self
,
value
:
float
|
int
)
->
None
:
self
.
_vel_x
+=
value
def
inc_vel_y
(
self
,
value
:
float
|
int
)
->
None
:
self
.
_vel_y
+=
value
# Update the ball's position, velocity, and trail for one step
def
step
(
self
)
->
None
:
# TODO: Update trail
# TODO: Calculate new position - checking if it has gone out of bounds
# TODO: Update values
return
# TODO: Create ball at center of screen
while
True
:
# TODO: Update screen
# TODO: Catch button presses and update ball's velocity appropriately
ball
.
step
()
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