home *** CD-ROM | disk | FTP | other *** search
- \ Sliding polygons demo. Load this file and type poly-demo
- \
- \ Type any key to stop it.
- \
- \ The demo initially draws triangles. By typing
- \ n vertices poly-demo
- \ where 3 <= n < 64, you can change it to draw polygons with more vertices
-
- needs rnd random.fth
- needs line-a-init linea.fth
- line-a-init
- decimal
- 5 xbios: _setscreen { w.rez l.phyz l.log -- }
- 37 xbios: vsync { -- } \ wait till next vertical retrace then return
-
- scradr constant old-screen
- get-rez
- constant cury
- constant curx
-
- create source-buff 256 allot
- create dest-buff 256 allot
- create spare-buff 256 allot
- create new-scr-buff 1024 32 * 512 + allot
- new-scr-buff 512 mod 512 swap - new-scr-buff + constant new-screen
- variable keep-going keep-going on
- variable #verts 3 #verts !
-
- : set-buf ( addr -- ) \ randomize a buffer
- dup #verts @ 0
- do curx rnd over w! 2+ cury rnd over w! 2+ loop
- over w@ over w! 2+ swap 2+ w@ swap w!
- ;
-
- : move-buf ( -- ) \ convert one buffer to another
- dest-buff source-buff keep-going off #verts @ 1+ 2* 0
- do
- dup w@ 2 pick w@ 2dup 2dup <> -rot 1+ <> and
- if over >
- if 2+
- else 2-
- then over w! keep-going on
- else 2drop
- then 2+ swap 2+ swap
- loop 2drop
- ;
- : draw-source ( -- ) \ draw the source polygon
- source-buff #verts @ poly-line
- ;
- : vertices ( n -- ) \ set the number of vertices
- #verts !
- ;
- : poly-demo
- 27 emit ascii f emit
- -1 -1 new-screen _setscreen erase-screen
- -1 -1 old-screen _setscreen erase-screen
- 2 _wrt_mod w!
- dest-buff set-buf source-buff set-buf
- -1 new-screen old-screen _setscreen vsync draw-source
- -1 old-screen new-screen _setscreen vsync draw-source
- source-buff spare-buff #verts @ 1+ 4 * cmove
- begin
- begin
- -1 old-screen new-screen _setscreen
- spare-buff #verts @ vsync poly-line
- source-buff spare-buff #verts @ 1+ 4 * cmove
- move-buf draw-source
-
- -1 new-screen old-screen _setscreen
- spare-buff #verts @ vsync poly-line
- source-buff spare-buff #verts @ 1+ 4 * cmove
- move-buf draw-source
- key?
- if -1 old-screen old-screen _setscreen
- 27 emit ascii e emit exit
- then
- keep-going @ 0=
- until dest-buff set-buf
- again
- ;
-