《101》中的rs代码
Call Main()
Sub Main()
Dim ptStart: ptStart = Array(0,0,0)
Dim vecDir: vecDir = Array(0,0,1)
Dim Props: Props = Array(3,4,6,5,0.8,30,0.7)
Dim Generation: Generation = 2
Call RecursiveGrowth(ptStart, vecDir, Props, Generation)
End Sub
Sub RecursiveGrowth(ByVal ptStart, ByVal vecDir, ByVal Props(), ByVal Generation)
If Generation > Props(2) Then Exit Sub
Dim ptGrow, vecGrow, newTwig
Dim newProps : newProps = Props
newProps(3) = Props(3) * Props(4)
newProps(5) = Props(5) * Props(6)
If newProps(5) > 90 Then newProps(5) = 90
Dim N, maxN
maxN = CInt(Props(0) + Rnd() * (Props(1) - Props(0)))
For N = 1 To maxN
ptGrow = RandomPointInCone(ptStart, vecDir, 0.25*Props(3), Props(3), Props(5))
newTwig = AddArcDir(ptStart, ptGrow, vecDir)
If Not IsNull(newTwig) Then
vecGrow = CurveTangent(newTwig, CurveDomain(newTwig)(1))
Call RecursiveGrowth(ptGrow, vecGrow, newProps, Generation+1)
End If
Next
End Sub作者: panhao1 时间: 2010-3-28 19:07
我的关键性代码
If isnothing(pt) Then Exit Sub
Dim Svector As New On3dPoint(0, 0, 1)
Dim props2 As Integer = 0
Dim arcs As New List(Of OnArc)
Call Start(pt, svector, props0, props1, props2, gen, max1, min1, max2, min2, arcs)
a = arcs
Public Sub start(ByVal pt As On3dPoint, ByVal dir As on3dvector, ByVal props0 As Integer, ByVal props1 As Integer, ByVal props2 As Integer, ByVal gen As Integer, ByVal max1 As Double, ByVal min1 As Double, ByVal max2 As Double, ByVal min2 As Double, ByRef arcs As list(Of onarc))
If props2 >gen Then Exit Sub
'randomize
For i As int32=1 To (rnd() * props1 + props0)
Dim randpt As New on3dpoint
randpt = randompoint(pt, max1, min1, max2, min2, dir)
Dim wing As New OnArc
wing = addarc(pt, randpt, dir)
If isnothing(wing) Then Exit Sub
Dim direction As New on3dvector
direction = wing.TangentAt(wing.Domain(1))
arcs.add(wing)
Call Start(randpt, direction, props0, props1, props2 + 1, gen, max1, min1, max2, min2, arcs)
Next
End Sub作者: yl0110 时间: 2010-3-28 21:01
编程流的啊·······作者: odys 时间: 2010-3-28 22:48
晕,GH里不还得用VB嘛。。其实差不多的作者: panhao1 时间: 2010-3-28 23:29 本帖最后由 panhao1 于 2010-3-29 12:18 编辑