Overview
The Sorting Algorithms Visualiser can be customized by modifying constants in the source code. After making changes, you’ll need to recompile the program.Window Configuration
These constants inSortingAlgos.h:12-14 control the window dimensions:
WINDOW_X (Width)
- Default: 1080 pixels
- Description: Width of the application window
- Recommendations:
- Minimum: 800 pixels (to fit all buttons)
- Maximum: Limited by your screen resolution
- Keep as a multiple of common button widths (70, 140, 160)
WINDOW_Y (Height)
- Default: 720 pixels
- Description: Height of the application window
- Recommendations:
- Minimum: 400 pixels (to accommodate buttons + visualization)
- Maximum: Limited by your screen resolution
- Consider the
heightFactor(0.5) when increasing
SIDEOFFSET (Margins)
- Default: 50 pixels
- Description: Margin from the left and right edges of the window
- Effect: Creates padding around the visualization rectangles
- Recommendations:
- Smaller values: More space for rectangles
- Larger values: Better visual separation from edges
Array Configuration
Control the default array size inSortingAlgos.cpp:8:
LIST_SIZE (Default Array Size)
- Default: 250 elements
- Description: Initial number of elements in the array
- Runtime Adjustable: Yes, using +/- buttons in the interface
- Recommendations:
- Small arrays (10-50): Good for slow algorithms like Bogo Sort
- Medium arrays (100-300): Balanced visualization
- Large arrays (500+): May cause performance issues with large delays
Users can adjust
LIST_SIZE at runtime using the +/- buttons, but this value sets the initial default.Performance Configuration
These settings control algorithm execution speed:SORT_DELAY (Operation Delay)
- Default: 1 nanosecond
- Description: Delay between each comparison/swap operation
- Runtime Configurable: Yes, via command-line argument
- Effect: Controls visualization speed
- Location:
SortingAlgos.h:18
Why SORT_DELAY is not constexpr
Why SORT_DELAY is not constexpr
Unlike other constants,
SORT_DELAY is declared as int instead of constexpr int because it can be modified at runtime through command-line arguments. This allows users to adjust visualization speed without recompiling.MAX_BOGOSORT_ITERATIONS (Bogo Sort Limit)
- Default: 1,000,000 iterations
- Description: Maximum number of shuffle attempts for Bogo Sort
- Why It Exists: Prevents infinite loops on large arrays
- Location:
SortingAlgos.h:15 - Recommendations:
- Increase for larger arrays or if Bogo Sort times out
- Decrease to fail faster on impossible cases
Visualization Configuration
Height Factor
FromSortingAlgos.cpp:170:
- Current Value:
0.5(uses half the screen height) - Description: Determines how tall the rectangles can grow
- Calculation:
(WINDOW_Y / max_value) × 0.5 - Effect:
0.5= rectangles use up to 50% of window height1.0= rectangles could fill entire window height0.25= rectangles limited to 25% of height
Customizing Height Factor
Customizing Height Factor
To change the visualization height:
- Open
SortingAlgos.cpp - Find line 170 in the
drawRectangles()function - Change
0.5to your desired factor (e.g.,0.7for 70% height) - Recompile the project
Button Customization
Button Positions and Sizes
All buttons are defined inSortingAlgos.cpp:48-129. Each button follows this structure:
Example: Moving a Button
To move the Shuffle button from(10, 10) to (20, 20):
Example: Changing Button Colors
To change the Bubble Sort button from cyan to orange:Highlight Colors
The three highlight colors used during sorting are defined inSortingAlgos.cpp:178-183:
Customizing Highlight Colors
Example: Change to Yellow/Magenta/Cyan
Example: Change to Yellow/Magenta/Cyan
Recompilation Process
After making any changes to the source code:- Save all modified files
- Clean the build (removes old compiled objects)
- Rebuild the project using your build system
Common Build Commands
The exact build commands depend on your project setup. Refer to the project’s build documentation for specific instructions.
Advanced Customizations
Adding a New Sorting Algorithm Button
Adding a New Sorting Algorithm Button
Changing the Font
Changing the Font
The font is loaded from To change the font:
assets/Roboto-Regular.ttf at line 36:- Place your
.ttffont file in theassets/directory - Update the path in the code
- Recompile
Adjusting List Size Display
Adjusting List Size Display
The list size display (center-top) is configured at lines 37-46 and 154-157:
- Character size: Line 41 -
listNum.setCharacterSize(40); - Position: Line 156 -
listNum.setPosition(sf::Vector2f(WINDOW_X / 2, 30)); - Format: Line 39 - Three digits with leading zeros