coding UTF-8; // Specifies character encoding to prevent text corruption import Math; // Library for math functions import GUI; // Library for building GUI components import tool.Graph2D; // Library for rendering 2D graphs // Parameters of the sine wave double amplitude = 1.0; // Amplitude (A) double wavelength = 1.0; // Wavelength (λ) double period = 1.0; // Period (T) // Graph range, number of points, and time settings const int N = 1024; // Number of points (higher = smoother) const double X_MIN = 0.0; // Minimum value of X range const double X_MAX = 4.0; // Maximum value of X range const double Y_MIN = -1.0; // Minimum value of Y range const double Y_MAX = 1.0; // Maximum value of Y range const double DT = 0.05; // Time increment per loop (at speed = 1.0) const double DX = (X_MAX - X_MIN) / N; // Spacing between X values // Arrays for graph data double waveX[ N ]; // X values double waveY[ N ]; // Y values // Variables for GUI components int window; int periodSlider; int wavelengthSlider; int amplitudeSlider; int speedSlider; int infoLabel; int timeLabel; int resetButton; // Animation and state variables float speed = 1.0; int graph; bool continuesLoop = true; double t; // ================================================================================ // Main Routine - executed automatically on startup // ================================================================================ void main( ){ // Ask whether to input wave parameters manually inputParameters(); // Launch graph window createGraphWindow(); // Build settings (GUI) window createSettingWindow(); // The main loop. t = 0.0; while( continuesLoop ) { // Display current time string roundedTime = round(t, 1, HALF_UP); // Round time to 1 decimal place setGraph2DTitle(graph, "t = " + roundedTime); // Compute coordinates to be plotted on the graph. for( int i=0; i