May 26, 2022, 03:26:40 PM

## News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!

## Tree of Pythagoras

Started by GWS, October 16, 2011, 10:07:12 AM

0 Members and 1 Guest are viewing this topic.

#### GWS

##### October 16, 2011, 10:07:12 AM
Hi,

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

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

`' Creative - Tree of Pythagorus' GWS Oct 2011 ' a recursion example ..def w:windowdef wstyle,i:intdef wW,wH,c:intdeclare pythTree(ax:int, ay:int, bx:int, by:int, recur:int)wW = 1024wH = 768wstyle = @minboxwindow w,-wW,0,wW,wH,wstyle,0,"Creative Basic",messagessetwindowcolor w,rgb(0,0,30)centerwindow wcontrol 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 = 1waituntil run = 0closewindow wENDSUB messagesselect @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) endselectendselectreturnsub 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) endifreturn`

best wishes,

Graham
Tomorrow may be too late ..

#### aurelCB

##### October 19, 2011, 06:35:26 AM #1
Excellent Graham..
forum for hobby programming:<br />https://aurelsoft.ucoz.com

#### aurelCB

##### October 20, 2011, 07:00:06 AM #2
Is there a way to made this program without recursive calling...
forum for hobby programming:<br />https://aurelsoft.ucoz.com

#### GWS

##### October 20, 2011, 09:36:11 PM #3
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

.. but I haven't tried it.

Fractals are amazing things ..

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

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

all the best,

Graham
Tomorrow may be too late ..

#### Brian

##### November 05, 2021, 04:34:16 AM #4
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