NB. Umbilic Torus
NB.
NB. ref Helaman Ferguson, Math Monthly 97 #7 589-610
NB.
NB. Change DISPLAYMODE to see user-defined
NB. values provided to the renderer.

DISPLAYMODE=: GLU_FILL NB. GLU_OUTLINE_PATCH, GLU_OUTLINE_POLYGON

CLEARCOLOR=: 0
COLORMATERIAL=: 0
AMBIENT=: 0.8
DIFFUSE=: 0.75 0.75 1
SPECULAR=: DIFFUSE
SHININESS=: 100 0 0 1
ROTXYZ=: 10 130 100

makefumbtorus=: 1 : 0
't p r w'=. 4{. y.,<0
rn=. (0.5*r)*umbtorus p
rl=. 1 1 1.5
u. makefloop t;rn;w;rl
)

umbtorus=: 3 : 0
t=. steps (o. 1 5r3), y.
t=. t, steps (o. _1r3 1r3), y.
t=. t, steps (o. 1r3 1), y.
x=. +: ^ j. t
y=. ^ - +: j. t
cleanz (+. x-y) % 3
)

fn=: (2: * cos,sin,0:) f.
UMBTORUS=: fn makefumbtorus (steps 0 2p1 15);11;2;1r3

r3=. 3 %~ #UMBTORUS
TDATA=: UMBTORUS ,"2 [ r3 |. 1 2 { "2 UMBTORUS
TCLR=: (0 0 0 ,: 1 1 1) hue fit01 -0{"1 TDATA
TPATTERN=: 256 256$, RGBA 1 1# WHITE ,: LIGHTGRAY
TPATPOS=: */~ int01 <:#TDATA

demo=: 3 : 0
stdknotv=: i.
VORDER=: 3
stdlistlight''
gentexture2D TPATTERN
2 drawsurface makenewlist TDATA;TCLR;TPATPOS
)
