2017年12月11日 星期一

VB2010-繪製多項式函數

VB2010-繪製多項式函數



Public Class Form1
    Dim Painting As Bitmap

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Const Cv As Single = 0.0174523
        Painting = New Bitmap(400, 400)
        Dim G As Graphics = Graphics.FromImage(Painting)
        Dim P As Pen = New Pen(Color.Black, 1)
        Dim P1 As Pen = New Pen(Color.Violet, 1)
        Dim P2 As Pen = New Pen(Color.Blue, 1)
        Dim P3 As Pen = New Pen(Color.OrangeRed, 1)

        Dim X As Single, ShfX As Single
        Dim Y As Single, ShfY As Single
        Dim lX As Single
        Dim lY As Single
        Dim A As Double
        Dim Fc As Single

        lX = -1000
        lY = -1000
        ShfX = 100
        ShfY = 120
        Fc = 0.005

        G.DrawLine(P1, 0, ShfY, ShfX * 2 * 2, ShfY)
        G.DrawLine(P1, ShfX * 2, 0, ShfX * 2, ShfY * 2)

        For Y = -20000 To 20000 Step 2000
            G.DrawLine(P2, ShfX * 2 - 10, ShfY - Y * Fc, ShfX * 2 + 10, ShfY - Y * Fc)
        Next

        For X = -100 To 100
            Y = 5678 + 2 * X - 2 * X ^ 2 - 0.2 * Math.Cos(X * Cv) * X ^ 3
            Y = Y * Fc
            P = New Pen(P.Color, 2)
            G.DrawLine(P, (lX + ShfX) * 2, -lY + ShfY, (X + ShfX) * 2, -Y + ShfY)

            If Y > 0 Then
                A = A + Y
                If X Mod 3 = 0 Then
                    P = New Pen(P.Color, 1)

                    G.DrawLine(P3, (X + ShfX) * 2, ShfY, (X + ShfX) * 2, -Y + ShfY)
                End If
            End If

            lX = X
            lY = Y
        Next

        G.DrawString("Area=" & (A / Fc), Me.Font, Brushes.Black, 50, 160)

        Me.BackgroundImageLayout = ImageLayout.None
        Me.BackgroundImage = Painting
    End Sub

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

沒有留言:

張貼留言

WOKWI LED + MQTT Node-Red SQLite

WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...