diff --git a/Stub.py b/Stub.py new file mode 100644 index 0000000000000000000000000000000000000000..6d096ccdd7bf7f29ccd6f963cd048f712efdc645 --- /dev/null +++ b/Stub.py @@ -0,0 +1,102 @@ +""" + +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()