' Creative Basic translated to IWB - Tree of Pythagoras ' GWS Oct 2011 - a recursion example... autodefine "off" window w INT wW = 1024 INT wH = 768 OPENwindow w,0,0,wW,wH,@MINBOX,0,"Tree of Pythagoras",&messages setwindowcolor w,rgb(0,0,30) control w,@BUTTON,"Exit",(wW-60)/2+50,wH*0.88,60,25,0,1 control w,@BUTTON,"Redo",(wW-60)/2-60,wH*0.88,60,25,0,2 ' Draw the Tree pythTree((wW/2-wW/12-5),wH-50,(wW/2+wW/12-5),wH-50,0) waituntil IsWindowClosed(w) END SUB messages(),INT select @MESSAGE case @idcreate centerwindow w case @idclosewindow CLOSEWINDOW w case @idcontrol select @controlID case 1 CLOSEWINDOW w 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 0 ENDSUB ' Redo sub pythTree(ax as int,ay as int,bx as int,by as int,recur as int) UINT red,grn,blu INT cx,cy,dx,dy,ex,ey 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 ENDSUB