Public Class Form1
    Dim W As Integer = 0
    Dim nP As Point
    Dim P As New Point(0, 0)
    Dim BM As Bitmap
    Dim Pen As Pen
    Dim Pts As New List(Of Point)
    Dim G As Graphics
    Dim Speed As Integer = 5
    Dim Th As New System.Threading.Thread(AddressOf Thr)
    Private PerCounter As System.Diagnostics.PerformanceCounter
    Dim SPP As Integer
    Dim Col As Color
    Dim Pns As New Pen(Color.FromArgb(40, 255, 255, 255), 5)
    Dim Pns2 As New Pen(Color.White, 1)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Th.Start()
    End Sub
    Sub Thr()
        Do
            G.Clear(Color.Transparent)
            Dim Pr As Integer = Integer.Parse(Format(PerCounter.NextValue, "##0"))
            nP = New Point(W, SPP - SPP * Pr / 100 + 5)
            Pts.Add(nP)
            If W > PictureBox1.Width Then
                For I As Integer = 0 To Pts.Count - 1
                    Pts(I) = New Point(Pts(I).X - Speed, Pts(I).Y)
                Next
                If Speed * Pts.Count > PictureBox1.Width / 2 Then
                    Pts.RemoveAt(0)
                End If
                W = W
            Else
                W += Speed
            End If
            Col = Color.FromArgb(255, 255 - Pr * 2.5, 0)
            Label2.ForeColor = Col
            G.DrawCurve(Pns, Pts.ToArray)
            G.DrawCurve(Pns2, Pts.ToArray)

            PictureBox1.Image = BM
            Threading.Thread.Sleep(100 / Speed)
        Loop
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Th.Abort()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BM = New Bitmap(PictureBox1.Width, PictureBox1.Height)
        Pts.Add(P)
        G = Graphics.FromImage(BM)
        G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
        Back()
        Speed = TrackBar1.Value + 2
        Label3.Text = "Скорость " & Speed
        SPP = BM.Height - 10
        '=================
        PerCounter = New System.Diagnostics.PerformanceCounter
        PerCounter.CategoryName = "Processor"
        PerCounter.CounterName = "% Processor Time"
        PerCounter.InstanceName = "_Total"
    End Sub

    Sub Back()
        Dim BMM As New Bitmap(My.Resources.Граф)
        Dim SQ As New Bitmap(My.Resources.Sq)
        Dim S As Integer = SQ.Width
        Dim Gr As Graphics = Graphics.FromImage(BMM)
        For I As Integer = 0 To BMM.Width \ S + 1 'Step S
            For T As Integer = 0 To BMM.Height \ S + 1 'Step S
                Gr.DrawImage(SQ, New Rectangle(I * S, T * S, S, S))
            Next
        Next
        PictureBox1.BackgroundImage = BMM
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        Speed = TrackBar1.Value + 2
        Label3.Text = "Скорость " & Speed
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()
    End Sub
End Class
