導航:首頁 > 軟體知識 > vb程序設計如何製作函數圖像

vb程序設計如何製作函數圖像

發布時間:2023-02-13 13:23:57

㈠ 求助各位大蝦,關於繪制vb二次函數圖像超小白的問題~~

第一步:用標簽工具做三個標簽
A=
B=
C=
在這二個標簽後面做三個文本框text1
text2
text3
第二步:請建立一個命令按鈕,改這個按鈕名稱為:二次函數的圖像生成
第三步:請將以下代碼復制到按鈕的代碼框內;
Private
Sub
Command1_Click()
a
=
Val(Text1.Text)
b
=
Val(Text2.Text)
c
=
Val(Text3.Text)
Cls
Scale
(-10,
10)-(10,
-10)
Line
(-9,
0)-(9,
0)
Line
(0,
-8)-(0,
8)
CurrentX
=
0.5
CurrentY
=
9
Print
"y"
CurrentX
=
9
CurrentY
=
-0.5
Print
"x"
For
x
=
-8
To
8
Step
1
PSet
(x,
0.1)
Next
x
For
y
=
-6
To
6
Step
1
PSet
(0.1,
y)
Next
y
For
x
=
-8
To
8
Step
0.01
y
=
a
*
x
*
x
+
b
*
x
+
c
PSet
(x,
y)
Next
x
End
Sub
第四步:運行,輸入A\B\C的值,就可以得到二次函數的圖像了!

㈡ 怎麼用VB畫函數圖像

那個你總得有個函數來畫呀。你出一個函數我上代碼

下面上一個正弦函數的代碼,其餘的你也可以類推

PrivateSubCommand1_Click()
DimjdAsDouble
DimxAsDouble
DimyAsDouble
Me.Picture1.Scale(-10,10)-(360,-10)
Me.Picture1.Line(-10,0)-(100,0)


Fori=1To360
x=i
jd=i*3.14/180
y=5*Sin(jd)
Me.Picture1.PSet(x,y)
Nexti

EndSub

PrivateSubForm_Load()
Me.Width=16000
Me.Height=12000
Me.Picture1.Height=8200
Me.Picture1.Width=11145
EndSub

㈢ 如何用VB畫出二次函數圖像和波長圖像

在窗體上放置一個名為 PicDraw 的圖片框,兩個按鈕,分別命名為 CmdDrawQuad 與 CmdDrawWave,全部代碼如下[Visual Basic 6.0]:

Option Explicit

'聲明平面直角坐標系的左上角、右下角的坐標
Const sngCrdL_X As Single = -50
Const sngCrdL_Y As Single = 100
Const sngCrdR_X As Single = 100
Const sngCrdR_Y As Single = -50
'聲明二次函數的解析式(Y = AX^2 + BX + C)
Const sngA As Single = 1 / 5
Const sngB As Single = 0
Const sngC As Single = 10

'================================
'計算 PI
'================================
Property Get PI() As Single
PI = Atn(1) * 4
End Property

'================================
'計算一次/二次函數
'================================
Function CalculateFunction(X As Single, Optional A As Single, Optional B As Single, Optional C As Single) As Single
CalculateFunction = A * X ^ 2 + B * X + C
End Function

'================================
'計算波
'Swin
振幅
'PeriodsDistance
每一個周期的長度
'================================
Function CalculateWave(X As Single, Swin As Single, PeriodsDistance As Single) As Single
CalculateWave = Sin(X / PeriodsDistance * PI * 2) * Swin
End Function

'================================
'准備平面直角坐標系
'================================
Sub Prepare()
Dim X As Long, Y As Long
PicDraw.Cls
'清空圖片框
PicDraw.Scale (sngCrdL_X, sngCrdL_Y)-(sngCrdR_X, sngCrdR_Y)
'設置坐標
PicDraw.Line (sngCrdL_X, 0)-(sngCrdR_X, 0), vbBlue
'繪制 X 軸
PicDraw.Line (0, sngCrdL_Y)-(0, sngCrdR_Y), vbBlue
'繪制 Y 軸
For X = sngCrdL_X To sngCrdR_X

For Y = sngCrdR_Y To sngCrdL_Y

PicDraw.PSet (X, Y), vbCyan
'繪制網格

Next Y
Next X
End Sub

Private Sub CmdDrawQuad_Click()
Prepare
Dim sngX As Single, sngY As Single
Dim LastX As Single, LastY As Single
Dim bDrawing As Boolean
For sngX = sngCrdL_X To sngCrdR_X Step 0.5

LastY = sngY

sngY = CalculateFunction(sngX, sngA, sngB, sngC)
'計算與X坐標所對應的Y坐標

If bDrawing Then

PicDraw.Line (LastX, LastY)-(sngX, sngY)
'繪制線段

End If

LastX = sngX

bDrawing = True
Next sngX
End Sub

Private Sub CmdDrawWave_Click()
Prepare
Dim sngX As Single, sngY As Single
Dim LastX As Single, LastY As Single
Dim bDrawing As Boolean
For sngX = sngCrdL_X To sngCrdR_X Step 0.5

LastY = sngY

sngY = CalculateWave(sngX, 50, 50)
'計算與X坐標所對應的Y坐標

If bDrawing Then

PicDraw.Line (LastX, LastY)-(sngX, sngY)
'繪制線段

End If

LastX = sngX

bDrawing = True
Next sngX
End Sub

聲明一點,由於知識水平原因,CalculateWave函數是我自己摸索出來的,如果有問題,請告知,謝謝!

㈣ 用VB如何繪制函數圖像大概的代碼是什麼

一般的vb畫函數圖像,用的是pset()函數
如你要畫y=3*x
(x從1到3)
可以用
for
x=1
to
3
step=0.01
'步伐越小畫得越精細
y=3*x
form1.pset(x,y)
next
x
就可以畫出該圖像來了,其他的函數的畫法也一樣的

㈤ 如何用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

㈥ 用VB編程繪制函數圖像步驟

1。建立坐標系 用line畫 x y軸2 。計算函數的X ,Y值3。用pset畫出x,y不同的點

㈦ VB畫正弦函數圖像的演算法

Private Const pi = 3.14159
Private a

Private Sub Form_Load()
Me.AutoRedraw = True
'首先清除me內的圖形
Me.Cls

'Scale方法設定用戶坐標系,坐標原點在me中心
Me.ScaleMode = 0
Me.ScaleMode = 3
Me.Scale (-10, 10)-(10, -10)

'設置繪線寬度
Me.DrawWidth = 1

'繪坐標系的X軸及箭頭線
Me.Line (-10, 0)-(10, 0), vbBlue
Me.Line (9, 0.5)-(10, 0), vbBlue
Me.Line -(9, -0.5), vbBlue
Me.ForeColor = vbBlue
Me.Print "X"
'繪坐標系的Y軸及箭頭線
Me.Line (0, 10)-(0, -10), vbBlue
Me.Line (0.5, 9)-(0, 10), vbBlue
Me.Line -(-0.5, 9), vbBlue
Me.Print "Y"
'指定位置顯示原點O
Me.CurrentX = 0.5
Me.CurrentY = -0.5
Me.Print "O"
'重設繪線寬度
Me.DrawWidth = 2

'用For循環繪點,使其按正弦規律變化。步長值很小,使其形成動畫效果
For a = -2 * pi To 2 * pi Step pi / 6000
Me.PSet (a, Sin(a) * 5), vbRed
Next

'指定位置顯示描述文字
Me.CurrentX = pi / 2
Me.CurrentY = -7
Me.ForeColor = vbBlack
Me.Print "正弦曲線示意"
End Sub

㈧ 用VB在VS2012中寫軟體時怎麼畫函數圖像

在窗體上添加一個PictureBox1控制項,兩個按鈕控制項:
代碼如下:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'繪制圖形的三步曲
'1,獲得一個Graphics對象
Dim MyGraphics As Graphics
MyGraphics = PictureBox1.CreateGraphics

'2,定義一個Pen對象,用於繪制圖形(輪廓線)
Dim MyPen As New Pen(Color.Black)

'3,定義一個Brush對象,用於填充圖形(如果需要填充的話)
Dim MyBrush As New SolidBrush(Color.Orange)

MyGraphics.FillEllipse(MyBrush, 200, 200, 100, 100) '繪制一個實心圓,該圓在:直線x=200,y=200,x=200+100,y=200+100所劃的矩形區域內
MyGraphics.DrawEllipse(MyPen, 200, 200, 100, 100) '繪制一個空心圓,該圓在:直線x=200,y=200,x=200+100,y=200+100所劃的矩形區域內

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'1,獲得一個Graphics對象
Dim MyGraphics As Graphics
MyGraphics = PictureBox1.CreateGraphics

'2,定義一個Pen對象,用於繪制圖形(輪廓線)
Dim MyPen As New Pen(Color.Black, 3)

'3,定義一個Brush對象,用於填充圖形(如果需要填充的話)
Dim MyBrush As New SolidBrush(Color.Orange)

Dim MyPoints() As Point = {New Point(20, 50), New Point(200, 30), New Point(250, 60)}
MyGraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
'MyGraphics.DrawClosedCurve(MyPen, MyPoints) '繪制光滑的封閉曲線
'MyGraphics.DrawCurve(MyPen, MyPoints) '繪制光滑的曲線

'用直線連接連點,繪制折線
Dim i As Integer
For i = 0 To 1
MyGraphics.DrawLine(MyPen, MyPoints(i), MyPoints(i + 1))
Next
End Sub
End Class

㈨ 如何在VB中畫函數圖像

按C1調用計時器過程畫
按C2調用一般過程畫
按C3調用Cls清除

閱讀全文

與vb程序設計如何製作函數圖像相關的資料

熱點內容
外賣小程序起什麼名稱好 瀏覽:805
澳洲有哪些好工業產品 瀏覽:118
好孝心的產品都有哪些 瀏覽:569
普雲交易怎麼給子賬號用 瀏覽:610
湘鄉市水果批發市場在哪個地方 瀏覽:510
數據挖掘論文怎麼寫 瀏覽:115
產品經理面試注意哪些 瀏覽:926
期貨模擬交易怎麼賺錢 瀏覽:175
技術去斑效果怎麼樣 瀏覽:359
vss在哪個交易所 瀏覽:567
咸陽哪裡有新市場 瀏覽:662
黨政機關用房管局信息系統怎麼登 瀏覽:415
有哪些銀行可以代理 瀏覽:560
代理什麼游戲充值好 瀏覽:172
二手貨交易網站有哪些 瀏覽:894
強制險信息錯誤如何更改 瀏覽:530
電腦開機後顯示處理器信息怎麼辦 瀏覽:797
招商銀行回復什麼取消兩元信息費 瀏覽:626
程序表怎麼列印 瀏覽:337
程序更新在哪裡找 瀏覽:695