1. To do a debugging tool, collect sensor data and display. Draw the curve attention to coordinate reversal, line tension can be. The curves in the project are shown from right to left, the coordinates of the lines are placed in the list, and the effect is as follows:
2. Code on
public class Drawingcurve {private Graphics Graphics; the//graphics class provides a way to draw objects to display devices private Bitmap Bitmap Bitmap object private int timeLine = 60;//60s private int canvaswidth = 600;//Canvas length private int slicecount
= 0;//Tick number = timeLine private int xslice = 10;//x Axis Tick-point width private int xsliceheight = 10;//x Axis scale height private float tension = 0.5f;
Tension coefficient private bool showx = true;
private bool showy = true;
private bool Showz = true; Queue<pointf> que = new queue<pointf> ();//Curve FIFO///<summary>///constructor///&L
T;/summary> public Drawingcurve () {this.xslice = This.canvaswidth/timeline; ///<summary>///Draw canvas///</summary>///<param name= "width" ></pa
ram>///<param name= "height" ></param>///<param name= "points" ></param> <returns></returns> public Bitmap drawcanvas (int width, int height,list<float> points) {if (bitmap!= null) {bitmap.
Dispose ();
bitmap = null;
} bitmap = new Bitmap (width, height);
Graphics = graphics.fromimage (bitmap); Graphics.
FillRectangle (Brushes.black, New Rectangle (0, 0, width, height)); Graphics. Transform = new Matrix (1, 0, 0,-1, 0, 0); The//y axis is positive and x is graphics to the right.
TranslateTransform (0, HEIGHT/2, matrixorder.append);
Pen pen = new Pen (color.red, 1); Pen.
DashStyle = DashStyle.Custom; Pen.
DashPattern = new float[] {2, 2}; Graphics.
DrawLine (pen, New Point (0, HEIGHT/4), new Point (width, HEIGHT/4)); Graphics.
DrawLine (pen, New Point (0, Height/-4), new point (width, height/-4)); Graphics. DrawLine (New Pen (color.greenyellow,1), NEW Point (0, 0), new point (width, 0)); Graphics.
DrawString ("0", New Font ("Vendara",), Brushes.white, New Point (0,-15)); Graphics.
DrawString ("+", New Font ("Vendara", ten), Brushes.white, New Point (0, HEIGHT/4)); Graphics.
DrawString ("-", New Font ("Vendara", ten), Brushes.white, New Point (0, Height/-4-15)); Graphics. Transform = new Matrix (1, 0, 0, 1, 0, 0); The//y axis is positive and x is graphics to the right.
TranslateTransform (0, HEIGHT/2, matrixorder.append); Graphics.
DrawString (" -59s", New Font ("Vendara", 8), Brushes.white, New Point (0, height/2-15)); Graphics.
DrawString ("0s", new Font ("Vendara", 8), Brushes.white, New Point (width-20, HEIGHT/2-15));
for (int i = 0; i < timeLine i++) {int scale = i * xslice; Graphics.
DrawLine (New Pen (New SolidBrush (Color.Blue)), 0 + scale, 0 + xsliceheight * 0.1f, 0 + scale, 0-xsliceheight * 0.1f); } graphIcs. Transform = new Matrix ( -1, 0, 0,-1, 0, 0); The//y axis is positive and x is graphics to the right.
TranslateTransform (width, HEIGHT/2, matrixorder.append);
if (SHOWX) drawx (graphics, points);
if (showy) Drawy (graphics, points);
if (SHOWZ) Drawz (graphics, points); Graphics.
Dispose ();
return bitmap; #region Draw curve private void drawx (Graphics Graphics, list<float> points) {Pen
Curvepen = new Pen (Color.cyan, 2); pointf[] curvepointf = new pointf[points.
Count];
float keys = 0;
float values = 0; for (int i = 0; i < points. Count;
i++) {keys = Xslice * i;
Values = ten * (Points[i]/10);
Curvepointf[i] = new PointF (keys, values); } graphics.
DrawCurve (Curvepen, curvepointf, this.tension); } private void Drawy (Graphics Graphics, list<float> poiNTS) {Pen curvepen = new Pen (color.purple, 2); pointf[] curvepointf = new pointf[points.
Count];
float keys = 0;
float values = 0; for (int i = 0; i < points. Count;
i++) {keys = Xslice * i;
Values = ten * (Points[i]/10);
Curvepointf[i] = new PointF (keys, values); } graphics.
DrawCurve (Curvepen, curvepointf, this.tension); } private void Drawz (Graphics Graphics, list<float> points) {pen curvepen = new Pen (Co Lor.
Orangered, 2); pointf[] curvepointf = new pointf[points.
Count];
float keys = 0;
float values = 0; for (int i = 0; i < points. Count;
i++) {keys = Xslice * i;
Values = ten * (Points[i]/10);
Curvepointf[i] = new PointF (keys, values); } graphics. Drawcurve (Curvepen, curvepointf, this.tension); ///<summary>///curve switch///</summary>///<param name= "_xyz" ></par
am>///<param name= "show" ></param> public void Hidecurve (String _xyz,bool show) {
Switch (_xyz) {case ' x ': Showx = Show;
Break
Case "Y": showy = Show;
Break
Case "Z": Showz = Show;
Break
Default:break; }} #endregion}
3.UI using ThreadStart to make calls, set the sleep time as needed, and set the PictureBox display.