當前位置:編程學習大全網 - 源碼下載 - 如何用vb畫出簡易函數圖像

如何用vb畫出簡易函數圖像

用vb畫出簡易函數圖像的操作步驟為:

(1)新建壹個工程,新建壹個Form1,在上面添加壹個picture控件和壹個command控件;

(2)選中此控件,右擊"復制",在窗體空白處右擊"粘貼",在彈出的對話框中選擇"是",創建了壹個Command控件數組,復制,使窗體上總***出現7個Command控件;

(3)復制代碼:

Const Pi = 3.1415926535 '定義圓周率

Dim a, wor

Dim i As Integer

Static Function Loge(X)

Loge = Log(X) / Log(Exp(1))

End Function

'定義用於在Picture1上的壹個位置打印字符函數

Private Function PrintWord(X, y, Word As String)

With Picture1

.CurrentX = X

.CurrentY = y

.ForeColor = RGB(0, 0, 255)

End With

Picture1.Print Word

End Function

Private Function DrawDot(Px, Py, Color)

Picture1.PSet (Px, Py), Color

End Function

Sub XY() '建立直角坐標系

Picture1.DrawWidth = 1 '設置線條寬度

Picture1.Cls

'設定用戶坐標系,坐標原點在Picture1中心

Picture1.Scale (-10, 10)-(10, -10)

Picture1.Line (-10, 0)-(10, 0), RGB(0, 0, 255)

Picture1.Line -(9.5, 0.5), RGB(0, 0, 255)

Picture1.Line (10, 0)-(9.5, -0.5), RGB(0, 0, 255)

Picture1.ForeColor = RGB(0, 0, 255)

Picture1.Print "X"

'畫 X 軸

Picture1.Line (0, -10)-(0, 10), RGB(0, 0, 255)

Picture1.Line -(0.5, 9.5), RGB(0, 0, 255)

Picture1.Line (0, 10)-(-0.5, 9.5), RGB(0, 0, 255)

Picture1.Print "Y"

'畫 Y 軸

For lin = -9 To 9

Picture1.Line (lin, 0)-(lin, 0.25)

wor = PrintWord(lin - 0.5, -0.5, Str(lin))

Picture1.Line (0, lin)-(-0.25, lin)

If lin <> 0 Then

wor = PrintWord(-0.9, lin, Str(lin))

End If

Next lin

Picture1.DrawWidth = 2

End Sub

Private Sub Command1_Click(Index As Integer)

Select Case Index

Case 0

For a = -3 To 3 Step Pi / 6000

Dot = DrawDot(a, a ^ 2, RGB(0, 0, 0))

Next a

wor = PrintWord(4, 9, "二次曲線 y=x^2")

Case 1

For a = -9 To 9 Step Pi / 6000

Dot = DrawDot(a, a, RGB(0, 0, 0))

Next a

wor = PrintWord(8, 5, "壹次曲線 y=x")

Case 2

For a = -9 To 3 Step Pi / 6000

Dot = DrawDot(a, Exp(a), RGB(0, 0, 0))

Next a

wor = PrintWord(4, 9, "指數曲線 y=e^x")

Case 3

For a = 0.0001 To 9 Step Pi / 6000

Dot = DrawDot(a, Loge(a), RGB(0, 0, 0))

Next a

wor = PrintWord(8, 3, "對數曲線 y=ln x")

Case 4

For a = -10 To 10 Step Pi / 6000

Dot = DrawDot(a, Sin(a), RGB(0, 0, 0))

Next a

wor = PrintWord(-5, 2, "正弦曲線 y=sin x")

Case 5

For a = -10 To 10 Step Pi / 6000

Dot = DrawDot(a, Cos(a), RGB(0, 0, 0))

Next a

wor = PrintWord(-9, 2, "余弦曲線 y=cos x")

Case 6

XY

End Select

End Sub

Private Sub Form_Load()

Me.Caption = "數學函數作圖?quot;"

Me.Show

Me.AutoRedraw = True

Picture1.AutoRedraw = True

Command1(0).Caption = "二次曲線"

Command1(1).Caption = "壹次曲線"

Command1(2).Caption = "指數曲線"

Command1(3).Caption = "對數曲線"

Command1(4).Caption = "正弦曲線"

Command1(5).Caption = "余弦曲線"

Command1(6).Caption = "清空"

XY

End Sub

Private Sub Form_Resize()

Picture1.Width = Me.Width * 0.94

Picture1.Height = Me.Height - (Command1(0).Height * 4 + 100)

Command1(0).Top = Me.Height - (Command1(0).Height * 2.5 + 100)

Command1(0).Left = Me.Width * 0.01

For i = 1 To 6

Command1(i).Top = Me.Height - (Command1(0).Height * 2.5 + 100)

Command1(i).Left = Command1(i - 1).Left + 1000

Next

XY

End Sub

  • 上一篇:Pt源代碼
  • 下一篇:VB編寫的打字程序
  • copyright 2024編程學習大全網