I am facing an issue with Forms Graphics, as this is my first project on it. I'll try to simplify my issue as possible as I can.
I have a code in which, 1. A smaller circle revolves around bigger (// Animation 1
) & 2. Drawing rectangle to form a wave line(// Animation 2
).
while (true)
{
// Issue line
g.Clear(Color.White);
g.DrawEllipse(pen, mainCircle);
loc = nextPoint(radius, angle, cntr_mainCircle);
innerCircle.X = loc.X - (innerCircle.Width / 2) + mainCircle.X;
innerCircle.Y = loc.Y - (innerCircle.Height / 2) + mainCircle.Y;
//Animation 1
g.DrawEllipse(pen, innerCircle);
//Animation 2
g.DrawLine(pen, cntr_mainCircle.X + 30, cntr_mainCircle.Y + 30, innerCircle.X + innerCircle_lenX / 2, innerCircle.Y + innerCircle_lenY / 2);
g.FillRectangle(Brushes.Red, startIndex, innerCircle.Y + 25, 3, 3);
fg.DrawImage(btm, new PointF(20, 20));
if (angle < 360)
{
angle += 1.0f;
}
else
{
angle = 0;
}
startIndex++;
}
I am getting a problem with line g.Clear(Color.White);
. It clears the entire screen, but I requirement is to clear // Animation 1
and not clear // Animation 2
Above code gives below output. The circle animation is correct as intended, but if you see.. there's a small RED rectangle which animates like a wave.. but because of Clear() the wave gets erased.
I need a wave to look like below.(Below output is when I remove the // Issue line
or say Clear() function)
My expectation output is as below, i.e Circle animation (// Animation 1) which is clearing screen and doing motion animation & Wave animation (// Animation 2) which should not be clearing previously drawn rectangles.
I need suggestions to correct my code or I am even open for suggestions for applying a new approach if the current code is not upto the standards.