|
Option Explicit
'Script written by <insert name>
'Script copyrighted by <insert company name>
'Script version 2009年3月11日 22:13:15
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
Function RandomPointInCone(ByVal Origin, ByVal Direction, _
ByVal MinDistance, ByVal MaxDistance, ByVal MaxAngle)
Dim vecTwig
vecTwig = VectorUnitize(Direction)
vecTwig = VectorScale(vecTwig, MinDistance + Rnd() * (MaxDistance-MinDistance))
Dim MutationPlane
MutationPlane = PlaneFromNormal(Array(0,0,0), vecTwig)
vecTwig = VectorRotate(vecTwig, Rnd() * maxAngle, MutationPlane(1))
vecTwig = VectorRotate(vecTwig, Rnd() * 360, Direction)
RandomPointInCone = PointAdd(Origin, vecTwig)
End Function
Function AddArcDir(ByVal ptStart, ByVal ptEnd, ByVal vecDir)
AddArcDir = Null
Dim vecBase : vecBase = PointSubtract(ptEnd, ptStart)
If VectorLength(vecBase) = 0.0 Then Exit Function
If IsVectorParallelTo(vecBase, vecDir) Then Exit Function
vecBase = VectorUnitize(vecBase)
vecDir = VectorUnitize(vecDir)
Dim vecBisector : vecBisector = VectorAdd(vecDir, vecBase)
vecBisector = VectorUnitize(vecBisector)
Dim dotProd : dotProd = VectorDotProduct(vecBisector, vecDir)
Dim midLength : midLength = (0.5 * Distance(ptStart, ptEnd)) / dotProd
vecBisector = VectorScale(vecBisector, midLength)
AddArcDir = AddArc3Pt(ptStart, ptEnd, PointAdd(ptStart, vecBisector))
End Function
自己对照着看吧 |
|