From 209bb2ff4edcb0f0c1fb854f60580373b5d8fe14 Mon Sep 17 00:00:00 2001 From: "wayo.cavazos" Date: Sun, 8 Oct 2006 12:02:49 +0000 Subject: [PATCH] Add roll-until-horizontal to turtle.factor --- contrib/lindenmayer/turtle.factor | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/contrib/lindenmayer/turtle.factor b/contrib/lindenmayer/turtle.factor index f07679d9da..50032f6cc7 100644 --- a/contrib/lindenmayer/turtle.factor +++ b/contrib/lindenmayer/turtle.factor @@ -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 ; -- 2.34.1