文件名称:用vb编写的函数作图软件
文件大小:32KB
文件格式:EXE
更新时间:2013-05-03 11:46:42
用vb编写的函数作图软件
用vb编写的函数作图软件的代码: Const Pi = 3.1415926535 '定义圆周率 Dim a, wor '定义用于在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() '画正弦曲线 '用For循环绘点,使其按正弦规律变化。 '步长小,使曲线比较平滑,还能形成动画效果 b = InputBox("输入振幅", "") c = InputBox("输入周期", "") d = InputBox("输入初相", "") h = InputBox("输入平衡位置", "") Cls XY For a = -2 * Pi / c To 2 * Pi / c Step Pi / 6000 Dot = DrawDot(a, Sin(c * a + d) * b + h, RGB(0, 255, 0)) Next a Picture2.Print "振幅b="; b Picture2.Print "周期c="; c Picture2.Print "初相d="; d Picture2.Print "平衡位置h="; h wor = PrintWord(3, -6, "正弦曲线 y=bsin(cx+d)+h") End Sub Private Sub Command2_Click() '画正弦曲线 '用For循环绘点,使其按正弦规律变化。 '步长小,使曲线比较平滑,还能形成动画效果 b = InputBox("输入振幅", "") c = InputBox("输入周期", "") d = InputBox("输入初相", "") h = InputBox("输入平衡位置", "") Cls XY For a = -2 * Pi / c To 2 * Pi / c Step Pi / 6000 Dot = DrawDot(a, Cos(c * a + d) * b + h, RGB(0, 255, 0)) Next a Picture2.Print "振幅b="; b Picture2.Print "周期c="; c Picture2.Print "初相d="; d Picture2.Print "平衡位置h="; h wor = PrintWord(3, -6, "正弦曲线 y=bcos(cx+d)+h") End Sub Private Sub Command3_Click() XY End Sub Private Sub Form_Load() Form1.Width = 14000 Form1.Height = 10000 Picture1.Width = 4 * Form1.Width / 5 Picture1.Height = 9 * Form1.Height / 10 Picture1.Left = Form1.Width / 10 Picture1.Top = Form1.Height / 160 Picture2.Width = 1 * Form1.Width / 12 Picture2.Height = 9 * Form1.Height / 10 Picture2.Left = 21 * Form1.Width / 24 Picture2.Top = Form1.Height / 160 Command1.Width = 2 * Form1.Width / 23 Command1.Height = 2 * Form1.Height / 53 Command1.Left = Form1.Width / 350 Command1.Top = Form1.Height / 160 Command2.Width = 2 * Form1.Width / 23 Command2.Height = 2 * Form1.Height / 53 Command2.Left = Form1.Width / 350 Command2.Top = 40 * Form1.Height / 160 Command3.Width = 2 * Form1.Width / 23 Command3.Height = 2 * Form1.Height / 53 Command3.Left = Form1.Width / 350 Command3.Top = 80 * Form1.Height / 160 Command4.Width = 2 * Form1.Width / 23 Command4.Height = 2 * Form1.Height / 53 Command4.Left = Form1.Width / 350 Command4.Top = 120 * Form1.Height / 160 Command1.Caption = "正弦曲线" Command2.Caption = "余弦曲线" Command3.Caption = "清空" Command4.Caption = "宁永明" Picture1.BackColor = vbWhite End Sub