Dymetric class
using System.Windows.Forms;
namespace Dymetric
{
class Dymetric
{
private EllipticalPath ellipse_ride;
private bool do_simulation;
public Dymetric(int screen_width, int screen_height)
{
ellipse_ride = new EllipticalPath(screen_width, screen_height);
do_simulation = false;
}
public void decideAction(PaintEventArgs e, bool click_check)
{
if (do_simulation && click_check)
{
ellipse_ride.inPlay(e);
do_simulation = false;
}
else
{
ellipse_ride.clearAndDraw(e);
do_simulation = true;
}
}
}
}
C# code for EllipticalPath class
using System;
using System.Threading;
using System.Drawing;
using System.Windows.Forms;
namespace Dymetric
{
class EllipticalPath
{
private int h, k, a, b, x, y;
private const int dotDIAMETER = 10;
private Bitmap offscreen_bitmap;
Graphics offscreen_g;
private Brush dot_colour, bg_colour;
public EllipticalPath(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);
h = offscreen_bitmap.Width / 2;
k = offscreen_bitmap.Height / 2;
a = offscreen_bitmap.Width / 3;
b = offscreen_bitmap.Height / 3;
x = h - a;
y = k;
}
public void clearAndDraw(PaintEventArgs e)
{
offscreen_g.Clear(Color.LightGray);
offscreen_g.FillEllipse(dot_colour, x, 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 (x <= h + a)
{
y = (int)Math.Round(k - ((double)b / a) * Math.Sqrt(Math.Pow(a, 2) - Math.Pow((x - h), 2)));
offscreen_g.FillEllipse(dot_colour, x, y, dotDIAMETER, dotDIAMETER);
y = (int)Math.Round(k + ((double)b / a) * Math.Sqrt(Math.Pow(a, 2) - Math.Pow((x - h), 2)));
offscreen_g.FillEllipse(dot_colour, x, y, dotDIAMETER, dotDIAMETER);
gr.DrawImage(offscreen_bitmap, 0, 55, offscreen_bitmap.Width, offscreen_bitmap.Height);
x += 20;
Thread.Sleep(50);
}
x = h - a;
y = k;
}
}
}