The problem is that the CPU curve in the task manager is displayed in a straight line with a balance of 50%,
Then write another program to display the CPU curve in the form of a sine curve,
Haha, it's interesting. I was fascinated by last night's viewing, but because it was too late, I didn't pay too much attention to it,
However, I am still a little curious, because I have never written a sine curve before,
Therefore, the sine curve is written together in the morning. Of course, this sine curve does not display the CPU curve in a sine curve,
Instead, return the sine curve with an image.
If anyone is interested, you can definitely try the question above. It's awesome to come up with such a question.
The Code is as follows:
Try
{
Using (Bitmap sinImage = new Bitmap (360,120 ))
{
Using (Graphics myGraphics = Graphics. FromImage (sinImage ))
{
MyGraphics. Clear (Color. White );
MyGraphics. SmoothingMode = SmoothingMode. AntiAlias;
Rectangle r1 = new Rectangle (0, 0,360, 20 );
Rectangle r2 = new Rectangle (0, 20,360, 40 );
Rectangle r3 = new Rectangle (0, 60,360, 40 );
Rectangle r4 = new Rectangle (0,100,360, 20 );
Brush brush1 = new SolidBrush (Color. OrangeRed );
Brush brush2 = new SolidBrush (Color. SkyBlue );
Brush brush3 = new SolidBrush (Color. Pink );
Brush brush4 = new SolidBrush (Color. YellowGreen );
MyGraphics. FillRectangle (brush1, r1 );
MyGraphics. FillRectangle (brush2, r2 );
MyGraphics. FillRectangle (brush2, r3 );
MyGraphics. FillRectangle (brush1, r4 );
MyGraphics. DrawString ("0", new Font ("", 8), brush1, new PointF (3, 65 ));
MyGraphics. DrawString ("90", new Font ("", 8), brush1, new PointF (85, 65 ));
MyGraphics. DrawString ("180", new Font ("", 8), brush1, new PointF (170, 65 ));
MyGraphics. DrawString ("360", new Font ("", 8), brush1, new PointF (336, 65 ));
Point myPoint = new Point (0, 60 );
Float sinValue = 0.0F;
For (int I = 0; I <360; I ++)
{
SinValue = Convert. ToSingle (Math. Sin (Convert. ToSingle (I * Math. PI)/180) * 40;
// In fact, there is no need to pay attention to the positive and negative values of sinValue.
// When it is negative, 60-sinvalue will increase
Point thisPoint = new Point (I, Convert. ToInt32 (60-sinValue ));
MyGraphics. DrawLine (new Pen (brush3), thisPoint, myPoint );
MyPoint = thisPoint;
}
}
Using (System. IO. MemoryStream MS = new System. IO. MemoryStream ())
{
Context. Response. ContentType = "Image/PNG ";
Context. Response. Clear ();
Context. Response. BufferOutput = true;
SinImage. Save (MS, ImageFormat. Png );
Ms. Flush ();
Context. Response. BinaryWrite (ms. GetBuffer ());
}
}
}
Catch
{
Return;
}