This project is a data visualisation tool built with Python and the turtle graphics library. It parses a list of abstract movement commands and translates them into a visual simulation of a magpie's flight path on a hexagonal grid.
This project was developed for the IFB104: Building IT Systems unit at Queensland University of Technology (QUT). The assignment was to create a simulation that could process a "log" of data and display its contents visually.
The program simulates a magpie's movement starting from a central cell (E5) on a hexagonal grid. It reads a list of movement instructions generated by the assignment_1_data_source.py module.
The simulation proceeds step-by-step, drawing the magpie's new position and orientation at each cell, until one of three stopping conditions is met. A thematic message is then displayed at the top of the canvas explaining why the simulation ended.
The data set is a list of lists.
-
Initial State: The first item defines the magpie's starting energy (the maximum number of steps) and its initial direction (e.g., 'North', 'South west')
-
Move Actions: All subsequent items define one of three actions for each step:
-
Move forward -
Move & turn left(moves forward, then turns 60 degrees left) -
Move & turn right(moves forward, then turns 60 degrees right)
-
The simulation halts immediately when one of the following occurs:
-
Energy Exhaustion: The magpie completes its maximum number of steps. The program displays: "The bird became exhausted after X steps!"
-
Off-Grid: The magpie's next move would take it outside the monitored grid perimeter. The program displays: "The bird flew away after X steps!"
-
Special Cell: The magpie lands on one of the three predefined "special" cells (A3, D8, or H6). The program displays: "Found a special cell after X steps!"
The solution is contained within assignment_1.py and is structured around several key functions:
-
visualise_data(random_moves): This is the main simulation engine. It initializes the turtle, reads the initial state, and then loops through the energy range. In each loop, it checks for off-grid, special cell, and exhaustion conditions before drawing the next step. -
Magpie(x, y, direction)/Magpie_moves(x, y, direction): These are reusable, parameter-driven functions that draw the magpie symbol.-
Magpieusessetheading()for the absolute initial orientation. -
Magpie_movesuses relative turns (left()) for all subsequent steps. This was a key requirement to ensure the code was reusable and not hard-coded.
-
-
heading_interger(input_string): A helper function that acts as a simple parser, translating human-readable string commands (e.g., 'North west', 'Move & turn left') into integer-based angle changes for theturtle. -
Hexagon(color): A utility function to draw the pale green hexagonal cell background for the magpie at each step. -
Print_text(x, y, label): A utility function for writing labels and the final status message to the canvas.
-
Ensure you have Python 3 installed.
-
Place all three Python files in the same directory:
assignment_1.py(The solution)assignment_1_config.py(Provided canvas setup)assignment_1_data_source.py(Provided data generator) -
Run the main solution file from your terminal:
python assignment_1.py -
A new
turtlegraphics window will open, and the simulation will run. Each run will produce a new, random data set and a different path.
To test specific, repeatable scenarios, you can provide a "seed" value to the data_set() function call at the bottom of assignment_1.py.
For example:
visualise_data(data_set(7292))
A list of useful seeds and their expected outcomes (e.g., "runs out of energy," "finds special cell") is documented in the comments of assignment_1_data_source.py.
Here is the output from seed value 7292:


