这是我自定义的一个函数:
Private Function tree(x As Integer, y As Integer, angle As Single, length As Single, n As Integer, k As Integer)
Dim x1 As Integer
Dim y1 As Integer
Dim x0 As Integer
Dim y0 As Integer
Dim s2 As Integer
Dim alpha As Single
Dim beita As Single
Dim leng As Single
BackColor = vbWhite
s2 = 2
If n > 0 Then
R = Rnd
x0 = Cos(angle) * length + x
y0 = Sin(angle) * length + y
If change Then
Picture1.Line (x, y)-(x0, y0), RGB(a, d, c)
chang = False
Else
Picture1.Line (x, y)-(x0, y0), RGB(50 * R, 100 * R, 10 * R)
End If
x1 = (x0 + x) / 2
y1 = (y0 + y) / 2
alpha = angle - k * PI / 180
beita = angle + k * PI / 180
leng = length / s2
Call tree(x1, y1, alpha, leng, n - 1, k)
Call tree(x1, y1, beita, leng, n - 1, k)
Call tree(x0, y0, alpha, leng, n - 1, k)
Call tree(x0, y0, beita, leng, n - 1, k)
Picture1.CurrentX = 4500
Picture1.CurrentY = 2500
Picture1.Font.Size = 25
End IfEnd Function
但是我想随机Call tree,可是不知道该怎样写这个随机函数.恳请各位高手帮帮忙!
Private Function tree(x As Integer, y As Integer, angle As Single, length As Single, n As Integer, k As Integer)
Dim x1 As Integer
Dim y1 As Integer
Dim x0 As Integer
Dim y0 As Integer
Dim s2 As Integer
Dim alpha As Single
Dim beita As Single
Dim leng As Single
BackColor = vbWhite
s2 = 2
If n > 0 Then
R = Rnd
x0 = Cos(angle) * length + x
y0 = Sin(angle) * length + y
If change Then
Picture1.Line (x, y)-(x0, y0), RGB(a, d, c)
chang = False
Else
Picture1.Line (x, y)-(x0, y0), RGB(50 * R, 100 * R, 10 * R)
End If
x1 = (x0 + x) / 2
y1 = (y0 + y) / 2
alpha = angle - k * PI / 180
beita = angle + k * PI / 180
leng = length / s2
Call tree(x1, y1, alpha, leng, n - 1, k)
Call tree(x1, y1, beita, leng, n - 1, k)
Call tree(x0, y0, alpha, leng, n - 1, k)
Call tree(x0, y0, beita, leng, n - 1, k)
Picture1.CurrentX = 4500
Picture1.CurrentY = 2500
Picture1.Font.Size = 25
End IfEnd Function
但是我想随机Call tree,可是不知道该怎样写这个随机函数.恳请各位高手帮帮忙!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货