Cleaned Bezier code to prepare the following

This commit is contained in:
2022-06-03 11:13:49 +02:00
parent dec7669842
commit 8cdfc0acfa

View File

@@ -95,36 +95,6 @@ namespace Paint_2
int yDiff = end.Y - start.Y;
int resultX = start.X + (int)(t * xDiff);
int resultY = start.Y + (int)(t * yDiff);
/*
if (xDiff > 0)
{
//Ex start 100 end 200
resultX = start.X + (int)(t * xDiff);
//resultX = (int)(t * xDiff);
}
else if(xDiff < 0){
//Ex start 200 end 100
resultX = start.X + (int)(t * xDiff);
}
else
{
resultX = 0;
}
if (yDiff > 0)
{
//Ex start 100 end 200
resultY =
}
else if (yDiff < 0)
{
//Ex start 200 end 100
resultY = start.Y + (int)(t * yDiff);
}
else
{
resultY = 0;
}
*/
Point result = new Point(resultX,resultY);
return result;
}
@@ -149,48 +119,50 @@ namespace Paint_2
{
pointSize = new Size(Widths[i - 1], Widths[i - 1]);
gr.FillEllipse(new SolidBrush(Colors[i - 1]), new Rectangle(new Point(points[i - 1].X - pointSize.Width / 2, points[i - 1].Y - pointSize.Height / 2), pointSize));
if (i % 4 == 0)
if(i >= 4)
{
//Drawing the given sharp outline
Point p1 = points[i - 4];
Point p2 = points[i - 3];
Point p3 = points[i - 2];
Point p4 = points[i - 1];
gr.DrawLine(new Pen(Colors[i - 4], Widths[i - 4]), p1, p2);
gr.DrawLine(new Pen(Colors[i - 3], Widths[i - 3]), p2, p3);
gr.DrawLine(new Pen(Colors[i - 2], Widths[i - 2]), p3, p4);
//float t = 0.5f;
float precision = 0.01f;
for (float t = 0; t <= 1; t += precision)
{
//float t = 0.2f;
//Drawing the first step of the curve
Point p1_2 = Lerp(p1, p2, t);
Point p2_2 = Lerp(p2, p3, t);
Point p3_2 = Lerp(p3, p4, t);
//gr.DrawLine(new Pen(GetRandomColor(), Widths[0]), p1_2, p2_2);
//gr.DrawLine(new Pen(GetRandomColor(), Widths[0]), p2_2, p3_2);
//Drawing the second step of the curve
Point p1_3 = Lerp(p1_2, p2_2, t);
Point p2_3 = Lerp(p2_2, p3_2, t);
//gr.DrawLine(new Pen(GetRandomColor(), Widths[0]), p1_3, p2_3);
//Drawing the Bezier Point
Point p1_4 = Lerp(p1_3, p2_3, t);
gr.FillEllipse(new SolidBrush(GetRandomColor()), new Rectangle(p1_4.X, p1_4.Y, Widths[0], Widths[0]));
}
BezierGenerator(gr,p1,p2,p3,p4,i);
}
}
}
}
private void BezierGenerator(Graphics gr,Point p1,Point p2,Point p3,Point p4,int i)
{
gr.DrawLine(new Pen(Colors[i - 4], Widths[i - 4]), p1, p2);
gr.DrawLine(new Pen(Colors[i - 3], Widths[i - 3]), p2, p3);
gr.DrawLine(new Pen(Colors[i - 2], Widths[i - 2]), p3, p4);
//float t = 0.5f;
float precision = 0.01f;
for (float t = 0; t <= 1; t += precision)
{
//Quadratic Bezier Curve creator
//Drawing the first step of the curve
Point p1_2 = Lerp(p1, p2, t);
Point p2_2 = Lerp(p2, p3, t);
Point p3_2 = Lerp(p3, p4, t);
//gr.DrawLine(new Pen(GetRandomColor(), Widths[0]), p1_2, p2_2);
//gr.DrawLine(new Pen(GetRandomColor(), Widths[0]), p2_2, p3_2);
//Drawing the second step of the curve
Point p1_3 = Lerp(p1_2, p2_2, t);
Point p2_3 = Lerp(p2_2, p3_2, t);
//gr.DrawLine(new Pen(GetRandomColor(), Widths[0]), p1_3, p2_3);
//Drawing the Bezier Point
Point p1_4 = Lerp(p1_3, p2_3, t);
gr.FillEllipse(new SolidBrush(GetRandomColor()), new Rectangle(p1_4.X - Widths[0] / 2, p1_4.Y - Widths[0] / 2, Widths[0], Widths[0]));
}
}
private Color GetRandomColor()
{
Random rnd = new Random();