home *** CD-ROM | disk | FTP | other *** search
- /*
- This is the E version of the 'Tree of Pythagoras'.
- Written by Raymond Hoving, Waardgracht 30, 2312 RP Leiden,
- The Netherlands.
- Requires Kickstart V2.04+ and reqtools.library V37+
- This version uses the mathffp.library/SpXxx functions for float
- calculations.
- Creation date: Sun Jan 3 18:43:34 1993, Version: 1.0
- */
-
- OPT STACK=25000 /* Just to be sure (we use a recursive algorithm). */
- OPT OSVERSION=37 /* Kickstart 2.04+ only. */
-
- MODULE 'intuition/intuition', 'intuition/screens', 'utility/tagitem',
- 'reqtools', 'graphics/displayinfo', 'exec/ports', 'exec/libraries',
- 'libraries/reqtools'
-
- DEF pythscreen=NIL : PTR TO screen,
- pythwindow=NIL : PTR TO window,
- pythidcmp=NIL : PTR TO mp,
- depth=1, mdepth=10 : LONG
-
- ENUM MSG_READY, MSG_ABORT, ERROR_REQTLIB, ERROR_SCREEN, ERROR_WINDOW
-
- PROC pythcleanup(errornumber)
- IF pythwindow<>NIL THEN CloseWindow(pythwindow)
- IF pythscreen<>NIL THEN CloseScreen(pythscreen)
- IF reqtoolsbase<>NIL THEN CloseLibrary(reqtoolsbase)
- SELECT errornumber
- CASE ERROR_REQTLIB
- WriteF('ERROR: Couldn\at open reqtools.library.\n')
- CASE ERROR_SCREEN
- WriteF('ERROR: Couldn\at open new screen.\n')
- CASE ERROR_WINDOW
- WriteF('ERROR: Couldn\at open new window.\n')
- CASE MSG_ABORT
- WriteF('***Break\n')
- CASE MSG_READY
- WriteF('I just drew \d little house\s!\n',
- Shl(1,mdepth)-1,
- IF mdepth=1 THEN '' ELSE 's')
- ENDSELECT
- CleanUp(errornumber)
- ENDPROC
-
- PROC pythtree(a1,a2,b1,b2)
- DEF c1,c2,d1,d2,e1,e2, /* We use the LONG type */
- ci1,ci2,di1,di2 : LONG /* to hold FFP float numbers! */
- /* Check for the close gadget. */
- IF GetMsg(pythidcmp)<>NIL THEN pythcleanup(MSG_ABORT)
- IF depth<=mdepth
- INC depth
- SetAPen(stdrast,depth)
- c1 := SpAdd(SpSub(a2,a1),b2) ; ci1 := SpFix(c1)
- c2 := SpSub(b1,SpAdd(a1,a2)) ; ci2 := SpFix(c2)
- d1 := SpSub(a2,SpAdd(b1,b2)) ; di1 := SpFix(d1)
- d2 := SpAdd(SpSub(b1,a1),b2) ; di2 := SpFix(d2)
- /* Calculate the new points. */
- e1 := SpMul(0.5,SpAdd(SpAdd(SpSub(c2,c1),d1),d2))
- e2 := SpMul(0.5,SpAdd(SpSub(d1,SpAdd(c1,c2)),d2))
- Move(stdrast,ci1,ci2)
- Draw(stdrast,SpFix(a1),SpFix(a2))
- Draw(stdrast,SpFix(b1),SpFix(b2))
- Draw(stdrast,di1,di2)
- Draw(stdrast,ci1,ci2)
- Draw(stdrast,SpFix(e1),SpFix(e2))
- Draw(stdrast,di1,di2) /* Draw the little house. */
- pythtree(c1,c2,e1,e2)
- pythtree(e1,e2,d1,d2) /* Recursive procedure calls. */
- DEC depth
- ENDIF
- ENDPROC
-
- PROC main()
- IF (reqtoolsbase:=OpenLibrary('reqtools.library',37))=NIL THEN pythcleanup(ERROR_REQTLIB)
- IF (RtGetLongA({mdepth},'Tree in E needs input...',NIL,
- [RTGL_MIN,1,
- RTGL_MAX,14,
- RTGL_TEXTFMT,'Enter maximum depth of the tree:',
- RT_WINDOW,pythwindow,
- TAG_DONE,TAG_DONE]))=FALSE THEN pythcleanup(MSG_ABORT)
- IF (pythscreen:=OpenScreenTagList(NIL, [SA_WIDTH,640,
- SA_HEIGHT,400,
- SA_DEPTH,4,
- SA_TYPE,CUSTOMSCREEN,
- SA_DISPLAYID,DEFAULT_MONITOR_ID OR HIRESLACE_KEY,
- SA_TITLE,'Screen of Pythagoras',
- TAG_DONE,TAG_DONE]))=NIL THEN pythcleanup(ERROR_SCREEN)
- IF (pythwindow:=OpenWindowTagList(NIL, [WA_TOP,1,
- WA_WIDTH,640,
- WA_HEIGHT,399,
- WA_IDCMP,IDCMP_CLOSEWINDOW,
- WA_FLAGS,WFLG_CLOSEGADGET OR WFLG_ACTIVATE,
- WA_TITLE,'Tree of Pythagoras by Raymond Hoving',
- WA_CUSTOMSCREEN,pythscreen,
- TAG_DONE,TAG_DONE]))=NIL THEN pythcleanup(ERROR_WINDOW)
- LoadRGB4(ViewPortAddress(pythwindow), [$000,$89a,$640,
- $752,$762,$771,$781,$680,$580,$080,$090,$0a0,
- $0b0,$0c0,$0d0,$0e0] : INT, 16)
- stdrast:=pythwindow.rport
- pythidcmp:=pythwindow.userport
- pythtree(SpFlt(273),SpFlt(394),SpFlt(367),SpFlt(394)) /* Go for it! */
- WaitPort(pythidcmp)
- pythcleanup(MSG_READY)
- ENDPROC
-