Pythagoras (advanced)

Help Contents Examples Pythagoras (advanced)
Polyhedra-fractals (3d fractal) PythagorasTree (fractal)

Pythagoras (advanced)

Example:    Pithagoras.eli
Modified:   June 2, 2000
Version:    2.0
Author:     Pavel Boychev
E-mail:     pavel@elica.net

Copyright © 2000 Elica Group

This advanced program visualizes one of the many proofs of the Pythagoras theorem.

run "graphix

lookat point 0 0 12 point 0 0 0 point 0 1 0

make "zal 0
make "arial font "arial 0

make "t 0

to changeview
	make "t :t+5
	lookat point 5*(cos :t/5) 5*(sin :t/5) 9 vector 0 0 0 vector 0 0 1
end

to my_text :string :center :radiusx :radiusy

	run bf :text

	make local "color rgb_ 0 0 1
	make local "font :arial
	make local "mode "2

	to moveto :xx :yy :zz
		make "center vector :xx :yy :zz
	end
end

make "txc  my_text "'C' point 0 (-1) 0.2 0.5 0.5 
make "txc2 my_text "'2' point :txc.center.x+0.3 :txc.center.y+0.2 0.2 0.3 0.3

to small :x
	make "x.radius :x.radius/1.5
	make "x.color rgb_ 0.8 0.6 0.6
	output :x
end

to tiny :x
	make "x.width :x.width/1.5
	make "x.color rgb_ 0.8 0.6 0.6
	output :x
end

to my_point :x :y :z

	run bf :sphere
	local "r "radius "center "mode "light "color "precision
	make "r 0.1
	make "center point :x :y :z
	make "radius :r
	make "mode 2
	make "light "true
	make "precision 7
	make "color rgb_ 0.6 0.2 0.2

	to moveto :xx :yy :zz
		make "center point :xx :yy :zz
	end
end

make "alpha 25
make "a  2*(sin :alpha)
make "b  2*(cos :alpha)
make "h  :b*(sin :alpha)
make "ax :a*(sin :alpha)
make "bx :b*(cos :alpha)

make "A  my_point (-1) 0 0
make "B  my_point (+1) 0 0
make "C  my_point :B.x-:bx :B.y+:h 0

make "C3 my_point (-1) (-2) 0
make "B3 my_point (+1) (-2) 0

make "A1 my_point :A.x-:h :A.y+:ax 0
make "A2 my_point :A.x+:ax-:h :A.y+:ax+:h 0

make "B1 my_point :B.x+:h :B.y+:bx 0
make "B2 my_point :C.x+:h :C.y+:bx 0

make "P  small my_point :A.x-:h :A.y-:bx 0
make "Q  small my_point :B3.x-:ax :B3.y-:h 0
make "R  small my_point :B.x-:ax :B.y-:h 0
make "S  small my_point :A.x+:bx-:h :A.y-:bx-:h 0
make "T  small my_point :B3.x-:h :B3.y+:ax 0

make "txa  my_text "'A' point (:A.center.x+:A2.center.x)/2-0.2 (:A.center.y+:A2.center.y)/2-0.2 0.2 0.5 0.5
make "txa2 my_text "'2' point :txa.center.x+0.3 :txa.center.y+0.2 0.2 0.3 0.3

make "txb  my_text "'B' point (:B.center.x+:B2.center.x)/2-0.2 (:B.center.y+:B2.center.y)/2-0.2 0.2 0.5 0.5
make "txb2 my_text "'2' point :txb.center.x+0.3 :txb.center.y+0.2 0.2 0.3 0.3

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

to my_polygon :points

	run bf :polygon

	make local "mode 2
	make local "color rgb_ 1 0.8 0
	make local "center point 0 0 (-0.005)
end

to my_turn :float :fixed

	make local "x :float.x-:fixed.x
	make local "y :float.y-:fixed.y

	output point :x*:co+:y*:si+:fixed.x :y*:co-:x*:si+:fixed.y 0
end

to my_triangle :p1 :p2 :p3

	run bf :polygon

	make local "points (set :p1.center :p2.center :p3.center)
	make local "mode 2
	make local "pattern [Xo oX]
	make local "width 2
	make local "color rgb_ 0.4 0.4 1
	make local "center point 0 0 0.02

	to turn
		make "points.#2 my_turn :points.#2 :points.#1
		make "points.#3 my_turn :points.#3 :points.#1
		changeview
	end
end

to transp :x :c
	make "x.pattern [Xo oX]
	make "x.color :c
	make "x.center point 0 0 0.01
	output :x
end


to my_segment :aa :bb

	run bf :segment

	local "width "color "initial "final

	make "width 4
	make "initial :aa.center
	make "final :bb.center
	make "color rgb 0 0 0

	to moveto :a :b
		make "initial :a.center
		make "final :b.center
	end
end

make "ab   my_segment :A :B
make "ac3  my_segment :A :C3
make "bb3  my_segment :B :B3
make "c3b3 my_segment :C3 :B3


to how
	make "ab2   my_segment :A :B2
	make "a2b   my_segment :A2 :B

	make "aa1   my_segment :A :A1
	make "a1a2  my_segment :A1 :A2

	make "bb1   my_segment :B :B1
	make "b1b2  my_segment :B1 :B2

	make "ap    tiny my_segment :A :P
	make "pq    tiny my_segment :P :Q
	make "sb    tiny my_segment :S :B
	make "qb3   tiny my_segment :Q :B3
	make "tb3   tiny my_segment :T :B3
	make "ar    tiny my_segment :A :R

	make "sq_a2 my_polygon (set :A.center :A1.center :A2.center :C.center)
	make "sq_b2 my_polygon (set :B.center :B1.center :B2.center :C.center)
	make "sq_c2 my_polygon (set :A.center :B.center :B3.center :C3.center)

	make "sq_bb transp my_polygon (set :A.center :R.center :S.center :P.center) rgb_ 0.8 0.6 0.6
	make "sq_aa transp my_polygon (set :B3.center :Q.center :S.center :T.center) rgb_ 0.6 0.8 0.6
end

how

make "sqrt2 sqrt 2

to aaa
	make "si sin :alpha
	make "co cos :alpha
	make "a  2*:si
	make "b  2*:co
	make "h  :b*:si
	make "ax :a*:si
	make "bx :b*:co
	make "x0 90-:alpha
	make "x1 180-:alpha

	C.moveto  :B.center.x-:bx :B.center.y+:h 0
	A1.moveto :A.center.x-:h :A.center.y+:ax 0
	A2.moveto :A.center.x+:ax-:h :A.center.y+:ax+:h 0

	txa.moveto (:A.center.x+:A2.center.x)/2-0.2 (:A.center.y+:A2.center.y)/2-0.2 0.2
	txa2.moveto :txa.center.x+0.3 :txa.center.y+0.2 0.2

	B1.moveto :B.center.x+:h :B.center.y+:bx 0
	B2.moveto :C.center.x+:h :C.center.y+:bx 0

	txb.moveto (:B.center.x+:B2.center.x)/2-0.2 (:B.center.y+:B2.center.y)/2-0.2 0.2
	txb2.moveto :txb.center.x+0.3 :txb.center.y+0.2 0.2

	P.moveto  :A.center.x-:h :A.center.y-:bx 0
	Q.moveto  :B3.center.x-:ax :B3.center.y-:h 0
	R.moveto  :B.center.x-:ax :B.center.y-:h 0
	S.moveto  :A.center.x+:bx-:h :A.center.y-:bx-:h 0
	T.moveto  :B3.center.x-:h :B3.center.y+:ax 0

	how

	make "zal :zal+9
	make "alpha 45+45*(sin :zal)
	if :t>0 [changeview]
end


make "alpha 25
make "z arcsin (-20/45)

repeat 40 [aaa]

repeat 8
[
	make "tr1 my_triangle :A :P :C3
	make "tr2 my_triangle :B3 :Q :C3

	make "si sin 2
	make "co cos 2

	make "tr1 my_triangle :A :P :C3
	make "tr2 my_triangle :B3 :Q :C3

	make "z 0

	repeat 45 [tr2.turn]

	make "si (-:si)
	repeat 45 [tr1.turn]

	repeat 45 [tr2.turn]

	make "si (-:si)
	repeat 45 [tr1.turn]

	delete "tr1
	delete "tr2
	repeat 3 [aaa]
]

repeat 170 [changeview]
repeat 100 [aaa]

Polyhedra-fractals (3d fractal) PythagorasTree (fractal)