Dymetric class
using System.Windows.Forms;
namespace Dymetric
{
class Dymetric
{
private PeriodicFunction sine_curve;
private bool do_simulation;
public Dymetric(int screen_width, int screen_height)
{
sine_curve = new PeriodicFunction(screen_width, screen_height);
do_simulation = false;
}
public void decideAction(PaintEventArgs e, bool click_check)
{
if (do_simulation && click_check)
{
sine_curve.inPlay(e);
do_simulation = false;
}
else
{
sine_curve.clearAndDraw(e);
do_simulation = true;
}
}
}
}
C# code for PeriodicFunction class
using System;
using System.Threading;
using System.Drawing;
using System.Windows.Forms;
namespace Dymetric
{
class PeriodicFunction
{
private int theta, a, y, half_vert_screen;
private const int dotDIAMETER = 10;
private Bitmap offscreen_bitmap;
Graphics offscreen_g;
private Brush dot_colour, bg_colour;
public PeriodicFunction(int screen_width, int screen_height)
{
dot_colour = new SolidBrush(Color.Yellow);
bg_colour = new SolidBrush(Color.LightGray);
offscreen_bitmap = new Bitmap(screen_width, screen_height - 55,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
offscreen_g = Graphics.FromImage(offscreen_bitmap);
offscreen_g.Clear(Color.LightGray);
theta = 0;
a = offscreen_bitmap.Height / 3;
half_vert_screen = offscreen_bitmap.Height / 2 - dotDIAMETER / 2;
y = (int)Math.Round(a * Math.Sin(theta * Math.PI / 180)) + half_vert_screen;
}
public void clearAndDraw(PaintEventArgs e)
{
offscreen_g.Clear(Color.LightGray);
offscreen_g.DrawLine(Pens.Black, 0, half_vert_screen + dotDIAMETER / 2,
offscreen_bitmap.Width, half_vert_screen + dotDIAMETER / 2);
offscreen_g.FillEllipse(dot_colour, theta, y, dotDIAMETER, dotDIAMETER);
Graphics gr = e.Graphics;
gr.DrawImage(offscreen_bitmap, 0, 55, offscreen_bitmap.Width, offscreen_bitmap.Height);
}
public void inPlay(PaintEventArgs e)
{
Graphics gr = e.Graphics;
while (theta < offscreen_bitmap.Width - dotDIAMETER)
{
offscreen_g.FillEllipse(dot_colour, theta, y, dotDIAMETER, dotDIAMETER);
gr.DrawImage(offscreen_bitmap, 0, 55, offscreen_bitmap.Width, offscreen_bitmap.Height);
theta += 15;
y = (int)Math.Round(a * Math.Sin(theta * Math.PI / 180)) + half_vert_screen;
Thread.Sleep(50);
}
theta = 0;
y = (int)Math.Round(a * Math.Sin(theta * Math.PI / 180)) + half_vert_screen;
}
}
}