Title: **Tree of Pythagoras**

Post by:**GWS** on **October 16, 2011, 10:07:12 AM**

Post by:

Hi,

Here's a Creative version of an interesting recursion program I found on the web, with a few tweaks of my own .. :P

I've never really understood recursion - I always expect it to blow up the computer .. ;D

best wishes, :)

Graham

Here's a Creative version of an interesting recursion program I found on the web, with a few tweaks of my own .. :P

I've never really understood recursion - I always expect it to blow up the computer .. ;D

Code Select

' Creative - Tree of Pythagorus

' GWS Oct 2011

' a recursion example ..

def w:window

def wstyle,i:int

def wW,wH,c:int

declare pythTree(ax:int, ay:int, bx:int, by:int, recur:int)

wW = 1024

wH = 768

wstyle = @minbox

window w,-wW,0,wW,wH,wstyle,0,"Creative Basic",messages

setwindowcolor w,rgb(0,0,30)

centerwindow w

control w,"B,Exit,(wW-60)/2+50,wH*0.88,60,25,0,1"

control w,"B,Redo,(wW-60)/2-60,wH*0.88,60,25,0,2"

pythtree((wW/2-wW/12-5), wH-50, (wW/2+wW/12-5), wH-50, 0)

run = 1

waituntil run = 0

closewindow w

END

SUB messages

select @class

case @idclosewindow

run = 0

case @idcontrol

select @controlID

case 1

run = 0

case 2

setwindowcolor w,rgb(0,0,30)

pythtree((wW/2-wW/12-5), wH-50, (wW/2+wW/12-5), wH-50, 0)

endselect

endselect

return

sub pythTree(ax, ay, bx, by, recur)

def red,grn,blu:int

cx = ax-ay+by

cy = ax+ay-bx

dx = bx+by-ay

dy = ax-bx+by

ex = 0.5*(cx-cy+dx+dy)

ey = 0.5*(cx+cy-dx+dy)

red = rnd(200)+55: grn = rnd(100)+155 :blu = rnd(200)+55

frontpen w,rgb(red,grn,blu)

Line w, cx, cy, ax, ay

Line w, ax, ay, bx, by

Line w, bx, by, dx, dy

Line w, dx, dy, cx, cy

Line w, cx, cy, ex, ey

Line w, ex, ey, dx, dy

if recur < 24

pythTree(cx, cy, ex, ey, recur+rnd(4)+1)

pythTree(ex, ey, dx, dy, recur+rnd(4)+1)

endif

return

best wishes, :)

Graham

Title: **Re: Tree of Pythagoras**

Post by:**aurelCB** on **October 19, 2011, 06:35:26 AM**

Post by:

Excellent Graham.. ;)

Title: **Re: Tree of Pythagoras**

Post by:**aurelCB** on **October 20, 2011, 07:00:06 AM**

Post by:

Is there a way to made this program without recursive calling...

Title: **Re: Tree of Pythagoras**

Post by:**GWS** on **October 20, 2011, 09:36:11 PM**

Post by:

Hi Aurel,

Good question .. and I dunno ::)

I'm no expert, but I believe an alternative method would involve iteration.

I took a look around, and found this ..

http://codeunivers.com/source-codes/matlab/pythagoras_tree (http://codeunivers.com/source-codes/matlab/pythagoras_tree)

.. but I haven't tried it.

Fractals are amazing things ..

http://www.miqel.com/fractals_math_patterns/visual-math-iterative-fractals.html (http://www.miqel.com/fractals_math_patterns/visual-math-iterative-fractals.html)

I might pursue a few more of these if I get time .. ;D

all the best, :)

Graham

Good question .. and I dunno ::)

I'm no expert, but I believe an alternative method would involve iteration.

I took a look around, and found this ..

http://codeunivers.com/source-codes/matlab/pythagoras_tree (http://codeunivers.com/source-codes/matlab/pythagoras_tree)

.. but I haven't tried it.

Fractals are amazing things ..

http://www.miqel.com/fractals_math_patterns/visual-math-iterative-fractals.html (http://www.miqel.com/fractals_math_patterns/visual-math-iterative-fractals.html)

I might pursue a few more of these if I get time .. ;D

all the best, :)

Graham

Title: **Re: Tree of Pythagoras**

Post by:**Brian** on **November 05, 2021, 04:34:16 AM**

Post by:

Hello,

I noticed someone on the Forum looking at GWS' code for a Tree of Pythagoras. It was in Creative Basic, so I have converted it to IWB for anyone that is interested

Brian

I noticed someone on the Forum looking at GWS' code for a Tree of Pythagoras. It was in Creative Basic, so I have converted it to IWB for anyone that is interested

Brian