turtle3D

Help Contents 3D Turtle Graphics turtle3D
3D Turtle Graphics turtle3D.f

turtle3D


Definition:

domain [Turtle3D] "Turtle3D

to turtle3D

	local "f "u "r "p "oldp

	make "f vector 0 1 0 ; forward vector
	make "u vector 0 0 1 ; upward vector
	make "r vector 1 0 0 ; right vector
	make "p vector 0 0 0 ; current position
	make "oldp :p

	to store
		output (vector :f :u :r :p)
	end

	to restore :x
		make "f :x.x
		make "u :x.y
		make "r :x.z
		make "p :x.#1
	end

	to forward :n
		make "oldp :p
		make "p vector  :p.x+:n*:f.x  :p.y+:n*:f.y  :p.z+:n*:f.z
	end

	to fd :n
		forward :n
	end

	to go :n
		forward :n
	end

	to back :n
		forward 0-:n
	end

	to bk :n
		back :n
	end

	to left :a
		local "s "c "ff "rr
		make "s sin :a
		make "c cos :a
		make "ff (vector  :f.x*:c-:r.x*:s  :f.y*:c-:r.y*:s  :f.z*:c-:r.z*:s )
		make "rr (vector  :f.x*:s+:r.x*:c  :f.y*:s+:r.y*:c  :f.z*:s+:r.z*:c )
		make "f :ff
		make "r :rr
	end

	to lt :a
		left :a
	end

	to right :a
		left 0-:a
	end

	to rt :a
		right :a
	end

	to uppitch :a
		local "s "c "ff "rr
		make "s sin :a
		make "c cos :a
		make "ff (vector  :u.x*:s+:f.x*:c  :u.y*:s+:f.y*:c  :u.z*:s+:f.z*:c )
		make "uu (vector :u.x*:c-:f.x*:s  :u.y*:c-:f.y*:s  :u.z*:c-:f.z*:s )
		make "f :ff
		make "u :uu
	end

	to up :a
		uppitch :a
	end

	to downpitch :a
		up 0-:a
	end

	to down :a
		downpitch :a
	end

	to rightRoll :a
		local "s "c "rr "uu
		make "s sin :a
		make "c cos :a
		make "rr  (vector  :r.x*:c-:u.x*:s  :r.y*:c-:u.y*:s  :r.z*:c-:u.z*:s )
		make "uu (vector  :r.x*:s+:u.x*:c  :r.y*:s+:u.y*:c  :r.z*:s+:u.z*:c )
		make "r :rr
		make "u :uu
	end

	to rr :a
		rightRoll :a
	end

	to cw :a
		rightRoll :a
	end

	to leftRoll :a
		cw 0-:a
	end

	to lr :a
		leftRoll :a
	end

	to ccw :a
		leftRoll :a
	end
end

make "Turtle3D "turtle3D

Examples:

References:

3D Turtle Graphics turtle3D.f