Simulation
The simulation array stores steps taken during the execution of algorithms for visualization purposes. Each step is represented as an array containing information about the step type and relevant data.
Note
The code assumes the presence of a TYPE
object that defines constants for different types of simulation steps. These constants are used to identify and label each step in the simulation.
Variables
1. WIDTH
Description: Width of the canvas for visualization.
Type: Number
2. HEIGHT
Description: Height of the canvas for visualization.
Type: Number
3. points
Description: Array to store the points for convex hull generation.
Type: Array
4. n
Description: Number of points to generate randomly.
Type: Number
Methods
1. setup()
Description: Setup function to initialize the canvas and user interface.
Parameters: None.
Returns: None.
2. toggleAlgorithm(id)
Description: Toggles the selected algorithm and updates the UI.
Parameters: id: ID of the algorithm button.
Returns: None.
3. toggleBrute()
Description: Toggles the brute force algorithm.
Parameters: None.
Returns: None.
4. toggleKPS()
Description: Toggles the Kirk Seidal algorithm.
Parameters: None.
Returns: None.
5. toggleJarvis()
Description: Toggles the Jarvis algorithm.
Parameters: None.
Returns: None.
6. mousePressed()
Description: Event handler for mouse press to add points to the canvas.
Parameters: None.
Returns: None.
7. drawPoints(P)
Description: Draws points on the canvas.
Parameters: P: Array of points.
Returns: None.
8. runBruteStep()
Description: Executes a single step of the brute force convex hull algorithm visualization.
Parameters: None.
Returns: None.
9. runJarvisStep()
Description: Executes a single step of the Jarvis algorithm visualization.
Parameters: None.
Returns: None.
10. runKPSStep()
Description: Executes a single step of the Kirk Seidal algorithm visualization.
Parameters: None.
Returns: None.
11. runSimulationStep()
Description: Executes a single step of the convex hull algorithm visualization based on the selected algorithm.
Parameters: None.
Returns: None.
12. generateConvexHull()
Description: Generates the convex hull based on the selected algorithm.
Parameters: None.
Returns: None.
13. generateBrute()
Description: Generates the convex hull using the brute force algorithm.
Parameters: None.
Returns: None.
14. generateKPS()
Description: Generates the convex hull using the Kirk Seidal algorithm.
Parameters: None.
Returns: None.
15. generateJarvis()
Description: Generates the convex hull using the Jarvis algorithm (gift wrapping).
Parameters: None.
Returns: None.
16. clearCanvas()
Description: Clears the canvas and resets the points array.
Parameters: None.
Returns: None.
17. generatePoints()
Description: Randomly initializes points on the canvas.
Parameters: None.
Returns: None.
18. sendMessage(message)
Description: Displays a message on the screen.
Parameters: message: The message to be displayed.
Returns: None.
19. sleep(ms)
Description: Pauses execution for the specified duration.
Parameters: ms: The duration to pause in milliseconds.
Returns: A promise that resolves after the specified duration.
20. mirror(P)
Description: Mirrors the points horizontally.
Parameters: P: Array of points to be mirrored.
Returns: An array of mirrored points.