coding UTF-8; // Specify the character encoding (to prevent garbled text) import Math; // Import library for using mathematical functions import GUI; // Import library for building GUI windows import tool.Graph2D; // Import library for 2D graph plotting // Variables for storing wave parameters double amplitudeA = 1.0; // Amplitude (A) of Wave A double amplitudeB = 1.0; // Amplitude (A) of Wave B double wavelengthA = 0.35; // Wavelength () of Wave A double wavelengthB = 0.4; // Wavelength () of Wave B double periodA = 1.0; // Period (T) of Wave A double periodB = 0.5; // Period (T) of Wave B // Configuration variables for graph range, number of points, time steps, etc. const int N = 1024; // Number of points on the graph (higher for smoother curves) const double X_MIN = 0.0; // Minimum value of the X-axis const double X_MAX = 4.0; // Maximum value of the X-axis const double Y_MIN = -2.0; // Minimum value of the Y-axis const double Y_MAX = 2.0; // Maximum value of the Y-axis const double DT = 0.05; // Time increment per loop (when speed = 1.0) const double DX = (X_MAX - X_MIN) / N; // X-axis spacing between points // Arrays to store coordinate data for passing wave data to the graph double waveX[ 3 ][ N ]; // X-coordinates (3 series: Wave A, Wave B, Composite Wave ~ number of points) double waveY[ 3 ][ N ]; // Y-coordinates (3 series: Wave A, Wave B, Composite Wave ~ number of points) // Variables for the GUI (parameter setting window) int window; // Stores the ID of the window int periodSliderA; // ID of the period slider for Wave A int periodSliderB; // ID of the period slider for Wave B int wavelengthSliderA; // ID of the wavelength slider for Wave A int wavelengthSliderB; // ID of the wavelength slider for Wave B int amplitudeSliderA; // ID of the amplitude slider for Wave A int amplitudeSliderB; // ID of the amplitude slider for Wave B int speedSlider; // ID of the animation speed slider int infoLabelA; // ID of the label displaying Wave A's parameters int infoLabelB; // ID of the label displaying Wave B's parameters int timeLabel; // ID of the label displaying the current time int resetButton; // ID of the button to reset time // Other control-related variables float speed = 0.5; // Animation speed int graph; // Stores the ID of the graph software instance bool continuesLoop = true; // Controls whether the animation loop runs or stops double t; // Time variable // ====================================================================== // Main routine - this function runs automatically on startup // ====================================================================== void main( ){ // Ask the user whether to input initial wave parameters; input if needed inputParameters(); // Launch the graph window createGraphWindow(); // Build the GUI (parameter setting window) createSettingWindow(); t = 0.0; // Initialize time to zero // Main animation loop while( continuesLoop ) { // Display the current time in the graph title string roundedTime = round(t, 1, HALF_UP); // Round time to 1 decimal place setGraph2DTitle(graph, "t = " + roundedTime); // Set title as "t = [time]" // Calculate the coordinates of points for graph plotting for( int i=0; i