The bezier curve generator is now fully functionnal (LETSGOOOOOOOOO)
This commit is contained in:
@@ -41,8 +41,9 @@ namespace Paint_2
|
|||||||
WidthsRedo = new List<int>();
|
WidthsRedo = new List<int>();
|
||||||
Name = name;
|
Name = name;
|
||||||
|
|
||||||
MessageBox.Show("Lerp test\nTest with start 20;20 and end 40;40 with 0.5f\n result : "+Lerp(new Point(20,20),new Point(40,40),0.5f));
|
//I KNOW I KNOW I LITTERALLY REINVENTED UNIT TEST BUT IF I CREATE SOME I WILL NEED TO DO THEM ALL STOP HARASSING ME
|
||||||
MessageBox.Show("Lerp test\nTest with start 40;40 and end 20;20 with 0.5f\n result : " + Lerp(new Point(40, 40), new Point(20, 20), 0.5f));
|
//MessageBox.Show("Lerp Test\nstart = 100;100\nend = 200;200\nt = 0.2\nExpected : 120;120 Actual : "+Lerp(new Point(100,100),new Point(200,200),0.2f));
|
||||||
|
//MessageBox.Show("Lerp Test\nstart = 200;200\nend = 100;100\nt = 0.2\nExpected : 180;180 Actual : " + Lerp(new Point(200, 200), new Point(100, 100), 0.2f));
|
||||||
}
|
}
|
||||||
public void Add(Point point)
|
public void Add(Point point)
|
||||||
{
|
{
|
||||||
@@ -90,9 +91,41 @@ namespace Paint_2
|
|||||||
{
|
{
|
||||||
//float xRatio = Math.Min((float)start.X,end.X) / Math.Max((float)start.X,end.X);
|
//float xRatio = Math.Min((float)start.X,end.X) / Math.Max((float)start.X,end.X);
|
||||||
//float yRatio = Math.Min((float)start.Y, end.Y) / Math.Max((float)start.Y, end.Y);
|
//float yRatio = Math.Min((float)start.Y, end.Y) / Math.Max((float)start.Y, end.Y);
|
||||||
float xDiff = Math.Abs(start.X - end.X);
|
int xDiff = end.X - start.X;
|
||||||
float yDiff = Math.Abs(start.Y -end.Y);
|
int yDiff = end.Y - start.Y;
|
||||||
Point result = new Point(Math.Min(start.X,end.X) + (int)(t *xDiff),Math.Min(start.Y,end.Y) + (int)(t * yDiff));
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
public void Paint(Bitmap canvas)
|
public void Paint(Bitmap canvas)
|
||||||
@@ -129,24 +162,40 @@ namespace Paint_2
|
|||||||
gr.DrawLine(new Pen(Colors[i - 3], Widths[i - 3]), p2, p3);
|
gr.DrawLine(new Pen(Colors[i - 3], Widths[i - 3]), p2, p3);
|
||||||
gr.DrawLine(new Pen(Colors[i - 2], Widths[i - 2]), p3, p4);
|
gr.DrawLine(new Pen(Colors[i - 2], Widths[i - 2]), p3, p4);
|
||||||
|
|
||||||
float t = 0.5f;
|
//float t = 0.5f;
|
||||||
|
float precision = 0.01f;
|
||||||
|
|
||||||
//Drawing
|
for (float t = 0; t <= 1; t += precision)
|
||||||
Point p1_2 = Lerp(p1, p2, t);
|
{
|
||||||
Point p2_2 = Lerp(p2, p3, t);
|
//float t = 0.2f;
|
||||||
Point p3_2 = Lerp(p3, p4, t);
|
//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.FillEllipse(new SolidBrush(Color.BlueViolet),new Rectangle(p1_2.X,p1_2.Y,10,10));
|
//gr.DrawLine(new Pen(GetRandomColor(), Widths[0]), p1_2, p2_2);
|
||||||
|
//gr.DrawLine(new Pen(GetRandomColor(), Widths[0]), p2_2, p3_2);
|
||||||
|
|
||||||
gr.DrawLine(new Pen(Color.Pink,10),p1_2,p2_2);
|
//Drawing the second step of the curve
|
||||||
gr.DrawLine(new Pen(Color.Red, 10), p2_2,p3_2);
|
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]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private Color GetRandomColor()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
return Color.FromArgb(rnd.Next(0,256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
}
|
||||||
public void Start(Color color, int width)
|
public void Start(Color color, int width)
|
||||||
{
|
{
|
||||||
Color = color;
|
Color = color;
|
||||||
|
|||||||
Reference in New Issue
Block a user