Omritning för varje nytt värde

This commit is contained in:
2021-03-26 08:41:38 +01:00
parent 0a186bbe30
commit 37a49c2610

View File

@ -17,12 +17,15 @@ namespace TestWinFormsDataVis
{
Pen myPen = new Pen(Color.Black);
Pen myCPenR = new Pen(Color.Red);
Pen myCPenG = new Pen(Color.Green);
Graphics g = null;
List<StraightLine> koordCross = new();
List<TwoPoints> CurveSin = new();
List<TwoPoints> CurveCos = new();
public bool CrossDrawn { get; set; } = false;
public bool CurvesDrawn { get; set; } = false;
static int _yMid = 0;
static int _yxPos = 3;
@ -131,6 +134,7 @@ namespace TestWinFormsDataVis
private void drawKoordCrossLines()
{
myPen.Color = Color.Black;
foreach (var x in koordCross)
{
Point[] points =
@ -140,7 +144,24 @@ namespace TestWinFormsDataVis
};
g.DrawLines(myPen, points);
}
CrossDrawn = true;
//CrossDrawn = true;
}
private void executeCurves()
{
//myPen.Color = Color.Red;
//myPen.Color = Color.Green;
foreach (var tp in CurveCos)
{
g.DrawLines(myCPenG, tp.drwPoints());
}
foreach (var tp in CurveSin)
{
g.DrawLines(myCPenR, tp.drwPoints());
}
}
private void drawCurves()
@ -152,33 +173,38 @@ namespace TestWinFormsDataVis
_timeYSin = _yMid + (int)(Math.Sin(_timeX) * -1 * _yMid);
CurveSin.Add(new TwoPoints { X1 = _timeXPosOld, Y1 = _prevYSin, X2 = _timeXPos, Y2 = _timeYSin });
foreach (var tp in CurveSin)
{
g.DrawLines(myPen, tp.drwPoints());
}
//foreach (var tp in CurveSin)
//{
// g.DrawLines(myPen, tp.drwPoints());
//}
//Debug.WriteLine($"p1 (x1,y1,x2,y2) -> {points[0].X},{points[0].Y},{points[1].X},{points[1].Y} ");
_timeYCos = _yMid + (int)(Math.Cos(_timeX) * _yMid);
CurveSin.Add(new TwoPoints { X1 = _timeXPosOld, Y1 = _prevYCos, X2 = _timeXPos, Y2 = _timeYCos });
foreach (var tp in CurveCos)
{
g.DrawLines(myPen, tp.drwPoints());
}
//foreach (var tp in CurveCos)
//{
// g.DrawLines(myPen, tp.drwPoints());
//}
//Debug.WriteLine($"p2 (x1,y1,x2,y2) -> {xpoints[0].X},{xpoints[0].Y},{xpoints[1].X},{xpoints[1].Y} ");
_timeXPosOld = _timeXPos;
CurvesDrawn = true;
}
private void pnlCanvas_Paint(object sender, PaintEventArgs e)
{
if (!CrossDrawn)
{
//if (!CrossDrawn)
//{
myPen.Width = 1;
g = pnlCanvas.CreateGraphics();
drawKoordCrossLines();
//}
if (CurvesDrawn)
{
executeCurves();
}
//drawCurves();
}
@ -187,7 +213,7 @@ namespace TestWinFormsDataVis
{
_timeXPos += 1;
drawCurves();
//pnlCanvas.Refresh();
pnlCanvas.Refresh();
}
}
}