USING: accessors arrays colors combinators kernel locals math math.constants math.matrices math.order math.ranges math.vectors math.quadratic random sequences specialized-arrays.float vectors jamshred.oint ;
IN: jamshred.tunnel
-: n-segments ( -- n ) 5000 ; inline
+CONSTANT: n-segments 5000
TUPLE: segment < oint number color radius ;
C: <segment> segment
: random-color ( -- color )
{ 100 100 100 } [ random 100 / >float ] map first3 1.0 <rgba> ;
-: tunnel-segment-distance ( -- n ) 0.4 ;
-: random-rotation-angle ( -- theta ) pi 20 / ;
+CONSTANT: tunnel-segment-distance 0.4
+USE: words.constant
+DEFER: random-rotation-angle
+\ random-rotation-angle pi 20 / define-constant
: random-segment ( previous-segment -- segment )
clone dup random-rotation-angle random-turn
[ dup peek random-segment over push ] dip 1- (random-segments)
] [ drop ] if ;
-: default-segment-radius ( -- r ) 1 ;
+CONSTANT: default-segment-radius 1
: initial-segment ( -- segment )
float-array{ 0 0 0 } float-array{ 0 0 -1 } float-array{ 0 1 0 } float-array{ -1 0 0 }
: wall-normal ( seg oint -- n )
location>> vector-to-centre normalize ;
-: distant ( -- n ) 1000 ;
+CONSTANT: distant 1000
: max-real ( a b -- c )
#! sometimes collision-coefficient yields complex roots, so we ignore these (hack)