Walker (advanced 3d)

Help Contents Examples Walker (advanced 3d)
triFrac (3d)

Walker (advanced 3d)

is a nice little animated line man walking and looking around.

run "graphix
run "turtle3D

make "O vector 0 0 0
make "v0 vector 0 0 100
make "v1 vector 0 0 1
make "t 0
make "D 1000

to changeview
	make "t :t+1
	; lookat vector :D*(cos 3*:t) :D*(sin 3*:t) 0 :v0 :v1
	lookat vector :D/2 :D/2 0 :v0 :v1
end

to dist :a :b
	output sqrt ((:a.x-:b.x)*(:a.x-:b.x)+(:a.y-:b.y)*(:a.y-:b.y)+(:a.z-:b.z)*(:a.z-:b.z))
end

to bodydef :name

	run bf :turtle3D

	to path :suffix
		make word :name :suffix segment :oldp :p
	end

	to neckdef

		make local "forward 0
		make local "len 8.5

		to draw
			down :forward
			up   90
			go   :len
			path "neck
			down 90
		end
	end

	make local "neck neckdef

	local "shouder_L "shouder_R

	to shoudersdef

		local "len  "up  "forward

		make "len 20
		make "up -5
		make "forward 0

		to draw
			make local "mm store
			left 90
			right :forward
			up :up
			go :len
			make "shouder_L store
			path "shouderl 
			restore :mm
			right 90
			left :forward
			up :up
			go :len
			make "shouder_R store
			path "shouderr
			restore :mm
		end
	end

	make local "shouders shoudersdef

	local "waist_L "waist_R

	to waistdef

		make local "len 20

		to draw
			make local "mm store
			left 90
			go :len
			make "waist_L store
			path "waistl 
			restore :mm
			right 90
			go :len
			make "waist_R store
			path "waistr
			restore :mm
		end
	end

	make local "waist waistdef

	to lefthanddef

		local  "len1  "len2  "angle1  "angle2

		make "len1 35
		make "len2 40
		make "angle2 45
		make "angle1 0

		to draw
			restore :shouder_L
			right 90
			down 90 
			up :angle1
			go :len1
			path "handl1
			up :angle2
			go :len2
			path "handl2
		end
	end

	make local "lefthand lefthanddef

	to righthanddef

		local  "len1  "len2  "angle1  "angle2

		make "len1 35
		make "len2 40
		make "angle2 45
		make "angle1 0

		to draw
			restore :shouder_R
			left 90
			down 90 
			up :angle1
			go :len1
			path "handr1
			up :angle2
			go :len2
			path "handr2
		end
	end

	make local "righthand righthanddef

	to leftlegdef

		local  "len1  "len2  "angle1  "angle2

		make "len1 60
		make "len2 50
		make "angle1 0
		make "angle2 0

		to draw
			restore :waist_L
			right 90
			down 90
			up :angle1 
			go :len1
			path "legl1
			down :angle2
			go :len2
			path "legl2
		end
	end

	make local "leftleg leftlegdef

	to rightlegdef

		local  "len1  "len2  "angle1  "angle2

		make "len1 60
		make "len2 50
		make "angle1 0
		make "angle2 0

		to draw
			restore :waist_R
			left 90
			down 90
			up :angle1 
			go :len1
			path "legr1
			down :angle2
			go :len2
			path "legr2
		end
	end

	make local "rightleg rightlegdef

	to backbonedef

		make local "len 65

		to draw
			down 90
			go len
			path "backbone
			up 90
		end
	end

	make local "backbone backbonedef

	to headdef

		local "len  "rot_left  "nod_down  "nod_left
		
		make "len vector 13 18 30
		make "rot_left 0
		make "nod_down 0
		make "nod_left 0

		to draw
			left :rot_left
			down :nod_down
			ccw  :nod_left
			go   :len.y
			path "head1

			up 80
			go :len.z/4
			path "head2
			make local "hh store
			down 90
			left 90
			go 5
			go -10
			path "head2a
			restore :hh

			go :len.z/4
			path "head2b

			up 40
			go 5
			path "head3

			down 20+90
			make local "mm store
			left 90
			go 6
			make word :name "head4a point :p.x :p.y :p.z
			up 90
			go 4
			down 90 
			go 6
			path "head4
			restore :mm

			right 90
			go 6
			make word :name "head4b point :p.x :p.y :p.z
			up 90
			go 4
			down 90
			go 6
			path "head5
			restore :mm

			up 90
			go :len.z/2-5
			path "head6
		end
	end

	make local "head headdef

	to draw
		make local "mm store
		;calculate vertical offset
		down 90
		go backbone.len

		make local "m2 store
		up :rightleg.angle1 
		go :rightleg.len1
		down :rightleg.angle2
		go :rightleg.len2

		make local "hr :p.z
		restore :m2
		up :leftleg.angle1 
		go :leftleg.len1
		down :leftleg.angle2
		go :leftleg.len2
		make local "hl :p.z

		restore :mm
		up 90

		if :hl < :hr
		[
			go 00-:hr
		]
		[
			go 00-:hl
		]
		down 90
		make "m store
		restore :m

		;draw the body
		neck.draw
		head.draw
		restore :m

		shouders.draw
		lefthand.draw
		righthand.draw
		restore :m

		backbone.draw
		waist.draw
		leftleg.draw
		rightleg.draw
		restore :mm
	end
end

make "body bodydef "siemens
body.draw

repeat 100000
[
	;make "body.p.x :body.p.x-30
	make "body.head.nod_down 15+15*(sin 20*:t)
	make "body.head.rot_left 10+20*(sin 10*:t)
	make "body.lefthand.angle1 30*(sin 180+40*:t)
	make "body.righthand.angle1 30*(sin 40*:t)
	make "body.leftleg.angle1 15+30*(sin 40*:t)

	if :body.leftleg.angle1 > 5
	[
		make "body.leftleg.angle2 :body.leftleg.angle1
	]
	[
		make "body.leftleg.angle2 5
	]
	make "body.rightleg.angle1 15+30*(sin 180+40*:t)

	if :body.rightleg.angle1 > 5
	[
		make "body.rightleg.angle2 :body.rightleg.angle1
	]
	[
		make "body.rightleg.angle2 5
	]
	body.draw
	changeview
]

triFrac (3d)