]> gitweb.factorcode.org Git - factor.git/commitdiff
Add roll-until-horizontal to turtle.factor
authorwayo.cavazos <wayo.cavazos@gmail.com>
Sun, 8 Oct 2006 12:02:49 +0000 (12:02 +0000)
committerwayo.cavazos <wayo.cavazos@gmail.com>
Sun, 8 Oct 2006 12:02:49 +0000 (12:02 +0000)
contrib/lindenmayer/turtle.factor

index f07679d9da99258f99d3e049d9eac231dfbc17bf..50032f6cc722d3f499083a1881eb71326e407d03 100644 (file)
@@ -116,4 +116,20 @@ turtle-position >position
 turtle-orientation >orientation ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! roll-until-horizontal
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+: V ( -- V ) { 0 1 0 } ;
+
+: X ( -- 3array ) orientation> [ first  ] map ;
+: Y ( -- 3array ) orientation> [ second ] map ;
+: Z ( -- 3array ) orientation> [ third  ] map ;
+
+: set-X ( seq -- ) orientation> [ 0 swap set-nth ] 2each ;
+: set-Y ( seq -- ) orientation> [ 1 swap set-nth ] 2each ;
+: set-Z ( seq -- ) orientation> [ 2 swap set-nth ] 2each ;
+
+: roll-until-horizontal ( -- )
+V Z cross normalize set-X
+Z X cross normalize set-Y ;