Dymetric class
using System.Windows.Forms;
namespace Dymetric
{
class Dymetric
{
private CircularPath cycle;
private bool do_simulation;
public Dymetric(int screen_width, int screen_height)
{
cycle = new CircularPath(screen_width, screen_height);
do_simulation = false;
}
public void decideAction(PaintEventArgs e, bool click_check)
{
if (do_simulation && click_check)
{
cycle.inPlay(e);
do_simulation = false;
}
else
{
cycle.clearAndDraw(e);
do_simulation = true;
}
}
}
}
C# code for CircularPath class
using System;
using System.Threading;
using System.Drawing;
using System.Windows.Forms;
namespace Dymetric
{
class CircularPath
{
private int a, b, r, x, y;
private const int dotDIAMETER = 10;
private Bitmap offscreen_bitmap;
Graphics offscreen_g;
private Brush dot_colour, bg_colour;
public CircularPath(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);
a = offscreen_bitmap.Width / 2;
b = offscreen_bitmap.Height / 2;
r = offscreen_bitmap.Height / 3;
x = a - r;
y = b;
}
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 <= a + r)
{
y = b - (int)Math.Round(Math.Sqrt(Math.Pow(r, 2) - Math.Pow((x - a), 2)));
offscreen_g.FillEllipse(dot_colour, x, y, dotDIAMETER, dotDIAMETER);
y = b + (int)Math.Round(Math.Sqrt(Math.Pow(r, 2) - Math.Pow((x - a), 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 = a - r;
y = b;
}
}
}