vb.net画正弦波 绘制正弦波( 二 )


第三,绘制一个点,当然是sin上的点 。第二步已经获得了x和y,正好是横坐标和纵坐标,我们为了让曲线平滑一些,可以Line方法 , 因为真的画点十分吃内存,比较卡,也就是我们画线不画点(很短很短的先近似于点),方法是Line (x1,y1)-(x2,y2)
最后,套用循环语句输出,其实说这是最后也不太合适,这部其实是套在第三步和第二步之外的,也就是确定x轴显示区间和曲线平滑度的作用 。
'代码
Private Sub Form_Load()
Me.AutoRedraw = True'开启自动重绘
Form1.Height = 2400'自定义窗体高度
Form1.Width = 8000'自定义窗体宽度
Scale (-16, 1.2)-(16, -1.2)'自定义坐标系
Line (-16, 0)-(16, 0)'绘制X轴
Line (0, 1.2)-(0, -1.2)'绘制Y轴
End Sub
Private Sub Command1_Click()
Line (-16, Sin(-16))-(-16, Sin(-16))'画起始点
Dim x As Double'定义x
Dim y As Double'定义y
For i = -16 To 16 Step 0.1'step越?。咴狡交?
x = i
y = Sin(x)
Line -(x, y)'连接上一个点
Next i
End Sub
如何用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
【vb.net画正弦波 绘制正弦波】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 lin0 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")

推荐阅读