//Define the constructor of this class. public Sineframe() { //Set the size of the frame (window) holding the graphic area. Size = new Size(form_width, form_height); MaximumSize = maxframesize; MinimumSize = minframesize; //Set the title of this user interface. Text = "Particle moving in a Sine Wave Pattern"; //Give feedback to the programmer. System.Console.WriteLine("Form_width = {0}, Form_height = {1}.", form_width, form_height); //Set the initial background color of this form. BackColor = Color.Beige; //Instantiate the collection of supporting algorithms curve_algorithms = new Sinecurve(); //Set initial values for computing the position of the dot which will travel in a Sine curve pattern. //The point (x,y) is the center of the dot in mathematical coordinates. t = 0.0; x = t; y = amplitude * System.Math.Sin(coefficient * t); //x_scaled_double and y_scaled_double are the coordinates of the upper left corner of the dot. //The point (x_scaled_double,y_scaled_double) is the upper left corner of the dot in C# coordinate system. x_scaled_double = scale_factor * x + offset - dot_radius; y_scaled_double = (double)form_height / 2.0 - scale_factor * y - dot_radius; System.Console.WriteLine("x_scaled_double = " + x_scaled_double + " y_scaled_double = " + y_scaled_double);///ok here. //x_scaled_int and y_scaled_int are the integer coordinates of the upper left corner of the dot. x_scaled_int = (int)System.Math.Round(x_scaled_double); y_scaled_int = (int)System.Math.Round(y_scaled_double); //Prepare a string holding the sine function: y = amplitude * sin (coefficient * t). equation_font = new System.Drawing.Font("Arial", (float)equation_height, FontStyle.Regular); equation = "y = " + String.Format("{0:0.00}", amplitude) + "*sin(" + String.Format("{0:0.00}", coefficient) + "*x)"; System.Console.WriteLine("The function is " + equation); //Prepare the refresh clock graphic_area_refresh_clock.Enabled = false; graphic_area_refresh_clock.Elapsed += new ElapsedEventHandler(Update_the_graphic_area); //Prepare the dot clock dot_motion_clock.Enabled = false; dot_motion_clock.Elapsed += new ElapsedEventHandler(Update_the_position_of_the_dot); motion_clock_active = false; //Prepare both clocks for start up. Initialize_graphic_clock(refresh_rate); Initialize_dot_clock(dot_update_rate); //Set up the start/pause button start_button.Text = "Start"; start_button.Size = new Size(60, 20); start_button.BackColor = Color.LimeGreen; start_button.Location = new Point((int)System.Math.Round(offset + 15.0), form_height - 60); start_button.Click += new EventHandler(All_systems_go); this_is_first_click_on_start_button = true; Controls.Add(start_button); //Set up the exit button exit_button.Text = "Quit"; exit_button.Size = new Size(60, 20); exit_button.BackColor = Color.Orange; exit_button.Location = new Point(form_width - 80, form_height - 60); exit_button.Click += new EventHandler(Shutdown); Controls.Add(exit_button); //Use extra memory to make a smooth animation. DoubleBuffered = true; }//End of constructor of Sineframe class.
//Define the constructor of this class. public Sineframe() { //Set the initial size of this form. Size = new Size(form_width, form_height); MaximumSize = maxframesize; MinimumSize = minframesize; //Set the title of this user interface. Text = "y = sin(4t) By Michael Rozsypal"; //Give feedback to the programmer. System.Console.WriteLine("form_width = {0}, form_height = {1}.", form_width, form_height); //Set the initial background color of this form. BackColor = Color.Pink; /*//Obtain the amplitude from the console. * System.Console.Write("Enter a float value for the amplitude of the sine function - the range 0.0 to 5.0 is recommended: "); * amplitude = double.Parse(System.Console.ReadLine()); * * //Obtain the period from the console. * System.Console.WriteLine("Enter a float value for the period of the sine function - 6.283185307 (2π) is a nice test case: "); * System.Console.Write("Entering 0.0 or a number close to zero may cause a divide by zero error: "); * period = double.Parse(System.Console.ReadLine()); * * //Compute the coefficient of t in the function: y = amplitude * sin(coefficient * t). * coefficient = 2.0*System.Math.PI/period; */ start_button.Text = "Go"; start_button.Size = new Size(80, 22); start_button.Location = location_of_start_button; start_button.BackColor = Color.LimeGreen; exit_button.Text = "Exit"; exit_button.Size = new Size(80, 22); exit_button.Location = location_of_exit_button; exit_button.BackColor = Color.LimeGreen; Controls.Add(start_button); start_button.Click += new EventHandler(Manage_dot_clock); Controls.Add(exit_button); exit_button.Click += new EventHandler(Stoprun); //Instantiate the collection of supporting algorithms curve_algorithms = new Sinecurve(); //Set initial values for the sine curve in a standard mathematical cartesian coordinate system t = 0.0; x = t; y = amplitude * System.Math.Sin(coefficient * t); //Prepare the refresh clock graphic_area_refresh_clock.Enabled = false; graphic_area_refresh_clock.Elapsed += new ElapsedEventHandler(Update_the_graphic_area); //Prepare the dot clock dot_refresh_clock.Enabled = false; dot_refresh_clock.Elapsed += new ElapsedEventHandler(Update_the_position_of_the_dot); //Start both clocks running Start_graphic_clock(refresh_rate); //Start_dot_clock(dot_update_rate); //Use extra memory to make a smooth animation. DoubleBuffered = true; //Initialize the pointer used to write onto the bitmap stored in memory. pointer_to_graphic_surface = Graphics.FromImage(pointer_to_bitmap_in_memory); initialize_bitmap(); } //End of constructor of Sineframe class.