API Reference
- class linesim.LineSimulation(start: tuple = (30, 30), background='blank', custom_background=None)
Simulate a robot track with a robot and line sensors
- Parameters:
start (tuple, optional) – The start position of the robot, defaults to
(50, 450).background (str, optional) – The included background to use, defaults to
"blank"custom_background (str, optional) – The path to a custom background image.
- add_beacon(location, name)
Add beacon to course
- add_sensor(offset, sensor, angle=None)
Add a sensor to the robot
- Parameters:
offset (tuple) – The sensor offset from the robot’s center.
sensor (str) – The type of sensor
angle (int) – The angle of an ultrasonic sensor
- Returns:
The sensor object.
- quit()
Safe exit pygame
- render()
Render background and all objects
- update(check_bounds=True, fps=30)
Update simulation
Re-renders the simulation while checking events, the robot position, and maintaining a framerate.
- Parameters:
check_bounds (bool, optional) – Check if the robot leaves the window, defaults to
True.fps (int) – The max framerate of the simulation, defaults to
30.
- class linesim.Robot(start: tuple)
Player class
Simulates a robot, which can have sensors.
- Parameters:
start (tuple) – Start position of the robot.
- move(speed)
Move robot forward
- Parameters:
speed (int) – Number of pixels to move forward.
- rotate(degrees)
Update robot rotation
- Parameters:
degrees (int) – Degree change in rotation.
- property surface: Surface
Rotate robot image
- Returns:
The rotated robot image.
- Return type:
pygame.Surface
- class linesim.Line(sim, robot, offset: tuple)
Robot Line Sensor
- Parameters:
sim (LineSimulation) – The robot simulation.
robot (Robot) – The robot that the sensor is attached to.
offset (tuple) – The sensor’s offset from the robot center.
- read_line()
Read line under sensor
Return True if the average RGB value under sensor is under the threshold (black line). Also returned by
__bool__.
- property surface: Surface
Create sensor surface
- Returns:
Colored square representing the sensor.
- Return type:
pygame.Surface
- class linesim.Ultrasonic(sim, robot, offset: tuple, angle: int)
Robot Ultrasonic Sensor
- get_distance()
Get distance of wall from sensor
- Returns:
Distance from wall.
- Return type:
int
- property line
Ultrasonic visibility overlay
Only shown when a sensor value is retrieved. :return: Line to end of sensor path :rtype: pygame.Surface
- property surface: Surface
Create sensor surface
Draw a triangle inscribed in a circle that rotates with the robot and sensor angle. :return: Colored triangle representing the sensor. :rtype: pygame.Surface