Dymetric class
using System.Windows.Forms;
namespace Dymetric
{
class Dymetric
{
private CircularRegion cycle_zone;
private bool do_simulation;
public Dymetric(int screen_width, int screen_height)
{
cycle_zone = new CircularRegion(screen_width, screen_height);
do_simulation = false;
}
public void decideAction(PaintEventArgs e, bool click_check)
{
if (do_simulation && click_check)
{
cycle_zone.inPlay(e);
do_simulation = false;
}
else
{
cycle_zone.clearAndDraw(e);
do_simulation = true;
}
}
}
}
C# code for CircularRegion class
using System;
using System.Threading;
using System.Drawing;
using System.Windows.Forms;
namespace Dymetric
{
class CircularRegion
{
private int x_square, y_square, previous_x, previous_y;
private const int squareLENGTH = 80;
private int a, b, r;
private const int dotDIAMETER = 10;
private Bitmap offscreen_bitmap;
Graphics offscreen_g;
private Brush bg_colour;
private Pen square_pen;
public CircularRegion(int screen_width, int screen_height)
{
square_pen = new Pen(Color.Yellow);
square_pen.Width = 5;
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);
previous_x = x_square = 10;
previous_y = y_square = offscreen_bitmap.Height / 2 - squareLENGTH / 2;
a = offscreen_bitmap.Width / 2;
b = offscreen_bitmap.Height / 2;
r = offscreen_bitmap.Height / 3;
}
public void clearAndDraw(PaintEventArgs e)
{
offscreen_g.DrawEllipse(Pens.Black, a - r, b - r, 2 * r, 2 * r);
offscreen_g.FillRectangle(bg_colour, previous_x - 5, previous_y - 5, squareLENGTH + 10, squareLENGTH + 10);
offscreen_g.DrawRectangle(square_pen, x_square, y_square, squareLENGTH, squareLENGTH);
previous_x = x_square;
previous_y = y_square;
Graphics gr = e.Graphics;
gr.DrawImage(offscreen_bitmap, 0, 55, offscreen_bitmap.Width, offscreen_bitmap.Height);
}
public void inPlay(PaintEventArgs e)
{
while (x_square < offscreen_bitmap.Width - squareLENGTH)
{
int square_left = x_square;
int square_right = x_square + squareLENGTH;
int square_top = y_square;
int square_bottom = y_square + squareLENGTH;
int x_left_det = (int)Math.Round(Math.Sqrt(Math.Pow(r, 2) - Math.Pow((square_left - a), 2)));
int x_right_det = (int)Math.Round(Math.Sqrt(Math.Pow(r, 2) - Math.Pow((square_right - a), 2)));
int y_up_det = (int)Math.Round(Math.Sqrt(Math.Pow(r, 2) - Math.Pow((square_top - b), 2)));
int y_down_det = (int)Math.Round(Math.Sqrt(Math.Pow(r, 2) - Math.Pow((square_bottom - b), 2)));
square_pen.Dispose();
square_pen = new Pen(Color.Yellow);
if (square_top > b - x_left_det && square_bottom < b + x_left_det
&& square_top > b - x_right_det && square_bottom < b + x_right_det
&& square_left > a - y_up_det && square_right < a + y_up_det
&& square_left > a - y_down_det && square_right < a + y_down_det)
{
square_pen = new Pen(Color.Green);
}
square_pen.Width = 5;
clearAndDraw(e);
x_square += 10;
Thread.Sleep(50);
}
x_square = 10;
y_square = offscreen_bitmap.Height / 2 - squareLENGTH / 2;
}
}
}