|
Post by Guilect on Dec 3, 2006 10:35:18 GMT -5
option explicit
dim bRunning bRunning = True
Dim totalSteps Dim branchPerStep Dim fixSize Dim fixAngel Dim brokenBranches Dim leafLevel Dim widthSize Dim widthScale Dim windDirection Dim onTop Dim fastPaint Dim playSound Dim changeBackground Dim goRender Dim goOut Dim myStep
totalSteps = 30 branchPerStep = 2 fixSize = 0 fixAngel = 0 brokenBranches = 25 leafLevel = 5 widthSize = 5 widthScale = 5 windDirection = 5 myStep = 0 Dim ScrnHeight Dim ScrnWidth ScrnHeight = 600 ScrnWidth = 800
randomize
sub main()
if (graphics.initialize(ScrnWidth, ScrnHeight) <> True) then exit sub graphics.setTitle "Demo - Tree - press [ESC] to exit" key.initialize graphics.clear 255 nextBranch ScrnWidth / 2, ScrnHeight - ScrnHeight / 5, 180
do while bRunning = True if key.pressed(1) or key.pressed(0) = True then bRunning = False system.processMessages loop key.terminate graphics.terminate
end sub
Call Main()
' this is the main function that several times refer to itself Function nextBranch(ByVal startX, ByVal startY , ByVal myDegree) On Error resume next 'this is for overflow error controlling when size of a branche became very high in random states Dim j Dim mySize Dim endX , endY , myWidth , degreeGrow If myStep >= totalSteps Or goOut Then Exit Function If brokenBranches > 0 And myStep > 2 Then If Rnd(1) * 100 < brokenBranches Then Exit Function ' this is for making broken branches system.processMessages if key.pressed(1) or key.pressed(0) = True then Exit Function myStep = myStep + 1 ' different width for branches from root to leaves. if you are beginner try myWidth=2 myWidth = (widthSize / 5) * (15 + totalSteps / 4) / (myStep ^ (widthScale / 10 + 0.5)) ' in new update , for "Width Scale" action I added [^ (widthScale / 10 + 0.5)] If myWidth < 1 Then myWidth = 1
' length of branch. if you are beginner try mySize = 500 ( in one line only ,delete following 3 lines) and also with lower values for "Total Steps" mySize = ((totalSteps - myStep * leafLevel / 5) * IIf(leafLevel >= 5, leafLevel / 5, (leafLevel + 5) / 10)) / (1 + Abs(leafLevel - 5) / 15) mySize = IIf(mySize > 0, mySize, 1) * (ScrnHeight / totalSteps ^ 1.9) * IIf(fixSize > 0, fixSize / 80, Rnd(1) * 1.5 + 0.1)
If myStep < 3 Then mySize = mySize * (2 - myStep / 3) ' I added this statement in update (2) because I want higher length for trunk of tree. you can simply remove it ! ' [ * Pi / 180 ] is for changing degrees to radians endX = Sin(myDegree * Pi / 180) * mySize + startX endY = Cos(myDegree * Pi / 180) * mySize + startY ' this paints the tree branch graphics.setline startX, startY, endX, endY, ARGB(255, 100, 255 * myStep / totalSteps, 50) ' I prefer different colors from root to leaves graphics.display ' this calculate degree for next branch degreeGrow = (IIf(fixAngel > 0, fixAngel, (Int(Rnd(1) * 120) - 60))) * 2 / branchPerStep ' this is the place that function run itself again For j = 1 To branchPerStep nextBranch endX, endY, (myDegree * (1 - (windDirection - 5) / 100) - degreeGrow / 2 + degreeGrow * (j - branchPerStep / 2)) Mod 360 ' for Wind action, I added this statement in last update [/li][li] Next myStep = myStep - 1 End Function
Function IIf (exp1, exp2, default) If exp1 then IIf = exp2 Else IIf = default End If End Function
|
|
|
Post by matthew on Dec 3, 2006 18:08:33 GMT -5
^^
Nice ;D
|
|
|
Post by u9 on Dec 4, 2006 14:04:47 GMT -5
Haha... I didn't notice, I just figured it was matthew who posted this one... But it wasn't Anyways, it looks nice.
|
|