dragon fractal program i made for all who want to see and this is also my first post

i made a dragon fractal generating program because i was bored:

DO
CLEAR
CALL fractal
PRINT "press enter"
PRINT "to go again"
PRINT "or esc to"
PRINT "quit"

LET done=0
LET again=0
LET cheese=0

DO
IF key input then GET KEY cheese
IF cheese=13 then
LET again=1
ELSEIF cheese=27 then
LET done=1
END IF
LOOP until again=1 or done=1
LOOP until done=1
END

SUB fractal
DECLARE FUNCTION nextit$
DECLARE FUNCTION calcdeg

PRINT "Maximize first"
DO
PRINT "to what iteration (i dont recommend anything above 19)"
INPUT prompt ">" :iteration
LET iteration=iteration-1
LET current$="r"
IF iteration<0 then
CLEAR
PRINT "Maximize first"
PRINT "Must be at least 1"
END IF
LOOP until iteration>=0

LET starttime$=time$
FOR x=1 to iteration
CLEAR
PRINT "Calculating iteration:";
PRINT x+1
LET current$=nextit$(current$)
NEXT x

LET cx=0
LET cy=0
PLOT 0,3;cx,cy;
LET bx=cx
LET tx=cx
LET by=cy
LET ty=1

LET deg=0
CLEAR
PRINT "Calculating window size"

FOR x=1 to len(current$)
LET deg=calcdeg(current$,x,deg)

IF deg=0 then
LET cy=cy-1
ELSEIF deg=90 then
LET cx=cx-1
ELSEIF deg=180 then
LET cy=cy+1
ELSEIF deg=270 then
LET cx=cx+1
END IF

IF cxtx then
LET tx=cx
END IF

IF cyty then
LET ty=cy
END IF
NEXT x

SET WINDOW bx-3,tx+3,by-3,ty+3
CLEAR
PRINT "Plotting fractal"

LET length=len(current$)
SET COLOR MIX(22) 0,1,1
SET COLOR 22
LET cx=0
LET cy=0
PLOT 0,1;cx,cy;

LET deg=0

FOR x=1 to length
LET deg=calcdeg(current$,x,deg)

IF deg=0 then
LET cy=cy-1
ELSEIF deg=90 then
LET cx=cx-1
ELSEIF deg=180 then
LET cy=cy+1
ELSEIF deg=270 then
LET cx=cx+1
END IF

SET COLOR MIX(22) x/length,1/x,(length-x)/length
SET COLOR 22

PLOT cx,cy;
NEXT x

SET COLOR "black"
LET endtime$=time$

LET toth=val(endtime$[1:2])-val(starttime$[1:2])
LET totm=val(endtime$[4:5])-val(starttime$[4:5])
LET tots=val(endtime$[7:8])-val(starttime$[7:8])

IF totm<0 then
LET toth=toth-1
LET totm=mod(totm,60)
END IF

IF tots<0 then
LET totm=totm-1
LET tots=mod(tots,60)
END IF

PRINT "total time:"
PRINT str$(toth); "h|";
PRINT str$(totm); "m|";
PRINT str$(tots); "s"
PRINT "done"
END SUB

FUNCTION nextit$(c$)
DECLARE FUNCTION calc$
LET back$=c$
FOR y=1 to len(back$)
LET temp$=calc$(back$,y,temp$,x)
NEXT y
LET back$=temp$
LET nextit$=c$ & "r" & back$
END FUNCTION

FUNCTION calc$(back$,y,temp$,x)
IF back$[y:y]="r" then
LET temp$="l" & temp$
ELSE
LET temp$="r" & temp$
END IF
LET calc$=temp$
END FUNCTION

FUNCTION calcdeg(current$,x,deg)
IF current$[x:x]="r" then
LET deg=mod(deg+90,360)
ELSE
LET deg=mod(deg-90,360)
END IF
LET calcdeg=deg
END FUNCTION

Comments

i fixed the problem with your program

the following lines are wrong

IF cxtx then
LET tx=cx
END IF

IF cyty then
LET ty=cy
END IF
NEXT x

It should be this..

IF cx=tx then
LET tx=cx
END IF

IF cy=ty then
LET ty=cy
END IF
NEXT x

so this is your new program code..

DO
CLEAR
CALL fractal
PRINT "press enter"
PRINT "to go again"
PRINT "or esc to"
PRINT "quit"

LET done=0
LET again=0
LET cheese=0

DO
IF key input then GET KEY cheese
IF cheese=13 then
LET again=1
ELSEIF cheese=27 then
LET done=1
END IF
LOOP until again=1 or done=1
LOOP until done=1
END

SUB fractal
DECLARE FUNCTION nextit$
DECLARE FUNCTION calcdeg

PRINT "Maximize first"
DO
PRINT "to what iteration (i dont recommend anything above 19)"
INPUT prompt ">" :iteration
LET iteration=iteration-1
LET current$="r"
IF iteration<0 then
CLEAR
PRINT "Maximize first"
PRINT "Must be at least 1"
END IF
LOOP until iteration>=0

LET starttime$=time$
FOR x=1 to iteration
CLEAR
PRINT "Calculating iteration:";
PRINT x+1
LET current$=nextit$(current$)
NEXT x

LET cx=0
LET cy=0
PLOT 0,3;cx,cy;
LET bx=cx
LET tx=cx
LET by=cy
LET ty=1

LET deg=0
CLEAR
PRINT "Calculating window size"

FOR x=1 to len(current$)
LET deg=calcdeg(current$,x,deg)

IF deg=0 then
LET cy=cy-1
ELSEIF deg=90 then
LET cx=cx-1
ELSEIF deg=180 then
LET cy=cy+1
ELSEIF deg=270 then
LET cx=cx+1
END IF

IF cx=tx then !placed = sign between cx and tx
LET tx=cx
END IF

IF cy=ty then !placed = sign between cy and ty
LET ty=cy
END IF
NEXT x

SET WINDOW bx-3,tx+3,by-3,ty+3
CLEAR
PRINT "Plotting fractal"

LET length=len(current$)
SET COLOR MIX(22) 0,1,1
SET COLOR 22
LET cx=0
LET cy=0
PLOT 0,1;cx,cy;

LET deg=0

FOR x=1 to length
LET deg=calcdeg(current$,x,deg)

IF deg=0 then
LET cy=cy-1
ELSEIF deg=90 then
LET cx=cx-1
ELSEIF deg=180 then
LET cy=cy+1
ELSEIF deg=270 then
LET cx=cx+1
END IF

SET COLOR MIX(22) x/length,1/x,(length-x)/length
SET COLOR 22

PLOT cx,cy;
NEXT x

SET COLOR "black"
LET endtime$=time$

LET toth=val(endtime$[1:2])-val(starttime$[1:2])
LET totm=val(endtime$[4:5])-val(starttime$[4:5])
LET tots=val(endtime$[7:8])-val(starttime$[7:8])

IF totm<0 then
LET toth=toth-1
LET totm=mod(totm,60)
END IF

IF tots<0 then
LET totm=totm-1
LET tots=mod(tots,60)
END IF

PRINT "total time:"
PRINT str$(toth); "h|";
PRINT str$(totm); "m|";
PRINT str$(tots); "s"
PRINT "done"
END SUB

FUNCTION nextit$(c$)
DECLARE FUNCTION calc$
LET back$=c$
FOR y=1 to len(back$)
LET temp$=calc$(back$,y,temp$,x)
NEXT y
LET back$=temp$
LET nextit$=c$ & "r" & back$
END FUNCTION

FUNCTION calc$(back$,y,temp$,x)
IF back$[y:y]="r" then
LET temp$="l" & temp$
ELSE
LET temp$="r" & temp$
END IF
LET calc$=temp$
END FUNCTION

FUNCTION calcdeg(current$,x,deg)
IF current$[x:x]="r" then
LET deg=mod(deg+90,360)
ELSE
LET deg=mod(deg-90,360)
END IF
LET calcdeg=deg
END FUNCTION

Re: dragon fractal listing ...

jackduffybailey ... Your program listing - as posted - found three errors when RUN. They are at lines 64:4, 66:5 and 67:4. Regards ... Tom M

listing? what do you mean,

listing? what do you mean, its one program and it works fine for me

Re: program listing code errors in your Forum message ...

jackduffybailey ... In your Forum program listing, there are two program lines that don't seem to be correct. They are:

IF cxtx then

and

IF cyty then

These lines are under the line containing "Calculating window size"

I highlighted, copied and pasted your Forum code into my TB Gold, and it didn't RUN. You try it. Regards ... Tom M

I corrected your Forum code listing ...

jackduffybailey ... I fixed the problem. When you posted your code, the TB Forum ignored the "greater than" and "less than" keyboard characters. When I restored them after the 'cut & paste' into my TB Gold, your program ran fine!!. In the future, to post program code, put the following lines BEFORE and AFTER your code lines:

post your code lines here

(I hope this message prints ok.)

The Forum has a problem with characters used in HTML. Regards ... Tom M

It didn't print ok. the two lines missing should have been:

ltcodegt and ltcode/gt, where lt is the 'less than' character and gt is the 'greater than' character. Regards ... Tom M

yea i know html codes,

yea i know html codes, forums usually allow typing them without the codes but if i must do that here then i will, or you could use java to find an replace when the user presses post, i'm in 8th grade and last year my friend did this, but he blocked posting, not replaced with char. codes, and he made the code from scratch

anyways thanks for telling me that before i posted more codes, right now, i am working on 3d plotting, i already made movement across the x,y,and z axis's and has paralex, not rotation of cam though.

edit: i dropped the 3d project, no time and got bored with it, may start it later