1.
在窗体上放置一个图形框,两个命令按钮,设置标题为“画图”和“返回”。单击“画图”按钮,重新定义图形框坐标为(-4,4)-(4,-4)。用pset方法在图形框内绘制参数方程
X=r * cos4 * αcos4 * α,y=rcos4 * αsin2 * α在0~2∏之间的图形,其中r为半径,取图形框坐标系宽度的一半;单击“返回”,结束按钮。
2用line的方法在窗体上绘制艺术图案,构造图案的算法为:把一个半径为r的圆周等分为n份后,然后用直线将这些点两两相连
提示:1一个半径为r的圆周上,第i个等分点的坐标为:xi=r*cos(i*t)+x0,yi= r*sin(i*t)+y0。其中,t为等分角,(x0,y0)为圆心坐标,r为圆半径
2在双重循环内用line方法将这些点两两相连
3编一循环程序,用line在屏幕上随机产生20条长度,颜色,宽度各异的随机曲线
1.在form中加入如下代码,在窗体上添加两个按钮command1,command2和一个picturebox名为picture1。
Const Pi = 2 * 3.14
Private Sub Command1_Click()
Dim x As Single, y As Single, α, r As Single
Picture1.Scale (-4, 4)-(4, -4)
Picture1.Line (0, 4)-(0, -4)
Picture1.Line (4, 0)-(-4, 0)
r = 4
For α = 0 To Pi Step 0.01
y = r * Cos(4 * α) * Sin(2 * α)
x = r * Cos(4 * α) * Cos(4 * α)
Picture1.PSet (x, y)
Next
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
2.在form中加入如下代码,在窗体上添加两个按钮command1,command2和一个picturebox名为picture1。
Const Pi = 2 * 3.14
Private Sub Command1_Click()
Dim x As Single, y As Single, α, r As Single
Dim n, i As Integer
Picture1.Scale (-4, 4)-(4, -4)
r = 3
For α = 0 To Pi Step 0.01
y = r * Sin(α)
x = r * Cos(α)
Picture1.PSet (x, y)
Next
n = InputBox("请输入等分数并且必须为正整数:")
If n Mod 2 = 1 Then
For i = 0 To (n + 1) / 2
y = r * Sin(i * Pi / n)
x = r * Cos(i * Pi / n)
Picture1.Line (x, y)-(-x, -y)
Next
Else
For i = 0 To n / 2
y = r * Sin(i * Pi / n)
x = r * Cos(i * Pi / n)
Picture1.Line (x, y)-(-x, -y)
Next
End If
End Sub
Private Sub Command2_Click()
Picture1.Cls
End Sub
3.在form中添加如下代码,并添加一个command1按钮和一个picturebox控件名为picture1
Private Sub Command1_Click()
Dim i As Integer
Dim a(19) As Integer
Form1.AutoRedraw = True
Randomize Timer
i = 0
c = False
Do While i < 20
b = Int(Rnd * 40) + 1
For j = i To 0
If a(i) = b Then c = True
Next j
If Not c Then
a(i) = b
i = i + 1
c = False
End If
Loop
Picture1.Scale (-50, 50)-(50, -50)
For i = 0 To 19
Picture1.DrawWidth = (i Mod 5) + 1
Picture1.ForeColor = i
If i < 19 Then
Picture1.Line (a(i), a(i + 1))-(-a(i), -a(i + 1)), ColorGetByRndValue
Else
Picture1.Line (a(i), a(0))-(-a(i), -a(0)), ColorGetByRndValue
End If
Next
End Sub
Function ColorGetByRndValue() As Long
Dim tOutLong As Long
Dim tColorCount As Long
Dim tColorValue As Long
tColorCount = 2 ^ 24
tColorValue = Rnd * tColorCount
tOutLong = CLng(Rnd * tColorCount)
ColorGetByRndValue = tOutLong
End Function