导航:首页 > 软件知识 > 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程序设计如何制作函数图像相关的资料

热点内容
技术去斑效果怎么样 浏览:359
vss在哪个交易所 浏览:566
咸阳哪里有新市场 浏览:662
党政机关用房管局信息系统怎么登 浏览:414
有哪些银行可以代理 浏览:559
代理什么游戏充值好 浏览:171
二手货交易网站有哪些 浏览:893
强制险信息错误如何更改 浏览:530
电脑开机后显示处理器信息怎么办 浏览:797
招商银行回复什么取消两元信息费 浏览:625
程序表怎么打印 浏览:335
程序更新在哪里找 浏览:693
辽阳装备职业技术学院学费多少钱 浏览:179
九防健步潍坊总代理在哪里 浏览:405
手机无法开机怎么导出数据 浏览:240
航天信息是什么行业 浏览:338
支付宝电子营业执照小程序什么时候能用 浏览:208
我的世界冷知识村民能交易什么 浏览:997
上海市代理商有多少人缦霖 浏览:923
工具栏如何隐藏程序 浏览:837