Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tree
#3
(03-04-2025, 09:36 AM)1micha.elok Wrote: click the image to zoom in

Code:
'---------------------------------------------------------------------
'Tree V2
'
'Steps :
'1.Draw the trunk
'2.At the end of the trunk, split by some angle and draw some branches
'3.Repeat at the end of each branch
'
'REFERENCE
'https://rosettacode.org/wiki/Fractal_tree
'---------------------------------------------------------------------

#win32
set window "Tree V2",600*screenw()/screenh(),600,false
set redraw off

'color definition
green = [0,255,0]
black = [0,0,0]


'---------------
' MAIN PROGRAM
'---------------
counter = 0
do
    'clear screen
    set color black ; cls
    set color green
   
    'Tree(x1, y1, angle, level,enlarge)
    Tree(width()/2, height()-50, 270, 7,18)
   
    set caret 10,10
    wln "Info Box"
    wln "========================"
    wln "Press RETURN to continue"
    wln "Press ESCAPE to exit"
    wln
    wln counter
    counter = counter + 1
     
    redraw
   
    'pause
    do;wait 1;if keydown(KEY_ESCAPE,true) end;until keydown(KEY_RETURN,true)
loop


'-----------
' FUNCTIONS
'-----------
function Tree(x1, y1, angle, level,enlarge)   
    if level > 0 then
        x2 = x1 + cos(rad(angle)) * level * enlarge + rnd(3,4)
        y2 = y1 + sin(rad(angle)) * level * enlarge + rnd(3,4)
       
        'draw trunk/branch
        trunk(x1,y1,x2,y2,level)
       
        'split branch
        if rnd(0,1) then Tree(x2, y2, angle - rnd(15,48), level - 1,enlarge)
        Tree(x2, y2, angle + rnd(15,48), level - 1,enlarge)
        if rnd(0,1) then Tree(x2, y2, angle, level-1, enlarge)
        if rnd(0,1) then Tree(x2, y2, angle + rnd(10,30), level-1, enlarge)
    endif
endfunc


function trunk(x1,y1,x2,y2,t)
    'reduce thickness
    t = t/1.1

    for x = x1 to x2 step 0.01
        'equation of a line passing through 2 points
        y = (y2-y1)/(x2-x1)*(x-x1)+y1
        draw ellipse x,y,t,t,true                         
    next
endfunc

Fractals ❤️
Don’t Count Your Chickens Before They Hatch
Reply


Messages In This Thread
Tree - by 1micha.elok - 03-04-2025, 09:36 AM
RE: Tree - by johnno56 - 03-04-2025, 10:29 AM
RE: Tree - by indru91112 - 03-04-2025, 01:47 PM
RE: Tree - by aurel - 03-05-2025, 02:07 PM
RE: Tree - by Marcus - 03-06-2025, 04:04 PM
RE: Tree - by 1micha.elok - 03-07-2025, 03:22 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)