Cubic (3d fractal)

Help Contents Examples Cubic (3d fractal)
ClipCube (simple 3d) Decoration (fractal)

Cubic (3d fractal)

Example:   Cubic
File name: Cubic.eli
Modified:  May 20, 2000
Author:    Pavel Christov Boychev
Version:   5.0
E-mail:    pavel@elica.net

Copyright © 1999-2000 Elica Group

This example shows a 3D fractal built from cubes of different sizes and colors.

When the figure passes all states all cubes except the 8 'most external' vanish into infinity.

run "graphix

; This is a new cube object, which is defined
; by its center and length of its sides

to fracube :cen :size

	make "size :size/2

	make local "radiusx 2*:size
	make local "color rgb_ (:cen.x+1.4)*0.4  (:cen.y+1.4)*0.4  (:cen.z+1.4)*0.4
	make local "center point :cen.x-:size :cen.y-:size :cen.z-:size
	make local "mode 0
	make local "light "true

	to ondrawimage 
		output dll.graphix.drawcube 
	end
end

; Point of view procedure, which makes all the rotations
make "z 0
make "dz 1
make "focus vector 0 0 0
make "updir vector 0 0 1
make "dist 4

to changeview
	make "eye vector  :dist*(cos 2*:z)  :dist*(sin 3*:z)  :dist*(sin 2*:z)
	lookat :eye :focus :updir
	make "z :z+:dz
end

; This procedure builds recursively all cubes

to build :name :size :center

	make :name fracube :center :size

	if :size>0.2
	[
		make local "s :size/2
		make local "c :size*3/4

		build word :name "a :s point :center.x+:c :center.y    :center.z
		build word :name "b :s point :center.x-:c :center.y    :center.z
		build word :name "c :s point :center.x    :center.y+:c :center.z
		build word :name "d :s point :center.x    :center.y-:c :center.z
		build word :name "e :s point :center.x    :center.y    :center.z+:c
		build word :name "f :s point :center.x    :center.y    :center.z-:c
	]
	changeview
end

; This procedure converts recursively all cubes
; from point to wireframe style (if m=1) and from
; wireframe to solid color style (if m=2)

to convert :name :size :m

	make (:name)("mode) :m
	changeview

	if :size > 0.2
	[ 
		make local "s :size/2

		convert word :name "a :s :m
		convert word :name "b :s :m
		convert word :name "c :s :m
		convert word :name "d :s :m
		convert word :name "e :s :m
		convert word :name "f :s :m
	]
end

; This procedure moves recursively all cubes
; which are not at the 'vertexes' of the fractal

to ruin :name :size

	if ((last :name)<>(last bl :name)) or ((last :name)<>(last bl bl :name))
	[
		make "temp :(:name)
		delete :name

		repeat 1
		[
			(make "temp.center 
				(point 
					:temp.center.x*1.15
					:temp.center.y*1.15
					:temp.center.z*1.15
				)
			)
			changeview
		]
		delete "temp
	]
	changeview

	if :size > 0.2
	[
		make local "s :size/2

		ruin word :name "a :s
		ruin word :name "b :s
		ruin word :name "c :s
		ruin word :name "d :s
		ruin word :name "e :s
		ruin word :name "f :s
	]
end

; Create the fractal and then keep the
; point of view change for 50 units more
build "zz 1 point 0 0 0
repeat 50 [ changeview ]

; Convert the fractal from point to 
; wireframe style
convert "zz 1 1
repeat 50 [ changeview ]

; Convert the fractal from wireframe  
; to solid color style
convert "zz 1 2
repeat 50 [ changeview ]

; Move the whole fractal far away
while :dist<50
[
	changeview 
	make "dist :dist*1.01
]

; Bring it back close to us
while :dist>5
[
	changeview 
	make "dist :dist/1.1
]

; Move almost all fractal components
; away from the center, each of them
; to its own direction
ruin "zz 1

; Connect remaining cubes with segments
make "sac segment :zzaaa.cen :zzccc.cen
make "sad segment :zzaaa.cen :zzddd.cen
make "sae segment :zzaaa.cen :zzeee.cen
make "saf segment :zzaaa.cen :zzfff.cen
make "sbc segment :zzbbb.cen :zzccc.cen
make "sbd segment :zzbbb.cen :zzddd.cen
make "sbe segment :zzbbb.cen :zzeee.cen
make "sbf segment :zzbbb.cen :zzfff.cen
make "sce segment :zzccc.cen :zzeee.cen
make "scf segment :zzccc.cen :zzfff.cen
make "sde segment :zzddd.cen :zzeee.cen
make "sdf segment :zzddd.cen :zzfff.cen

; ...and rotate the remaining double pyramid a bit.
make "dz 0.5
repeat 550 [ changeview ]

ClipCube (simple 3d) Decoration (fractal)