几个vb编程题(图形操作)

2024-12-16 15:12:00
推荐回答(1个)
回答1:

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.01y = r * Cos(4 * α) * Sin(2 * α)
x = r * Cos(4 * α) * Cos(4 * α)
Picture1.PSet (x, y)
NextEnd SubPrivate 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.01y = 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 IfEnd SubPrivate Sub Command2_Click()
Picture1.Cls
End Sub 3.在form中添加如下代码,并添加一个command1按钮和一个picturebox控件名为picture1Private 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