Logo programming with its recursive procedure capability enables easy creation of fractal geometry. In VRMath2, many of the existing fractals by tranditional 2D Logo programs can be viewed in 3D and reconstructed to be 3D fractals. This project will explore existing and new ideas about fractals, and use the 3D Logo programming environemnt in VRMath2 to generate and share 3D fractals online. Below are some classic examples of fractals.
Fractals in the nature
1. Fern leaf
Perhaps one of the most popular fractals in the nature, the fern leaf has a recursive structure, which can be described and coded using the Logo turtle geometry.
|
; Recursive fern procedure ; TO fern :size :sign IF :size < 1 [ STOP ] FD :size RT 70 * :sign fern :size * 0.5 :sign * -1 LT 70 * :sign FD :size LT 70 * :sign fern :size * 0.5 :sign RT 70 * :sign RT 7 * :sign fern :size - 1 :sign LT 7 * :sign JB :size * 2 ; jb = jumpback END CS ; clearscreen SETBG 29 ; set background to index 29 CM ; centimeter NCOFF ; next color off SETPCNAME "green ; set pen color by name RU 90 ; roll up 90 degrees PD ; pen down fern 16 1 PU ; pen up
|
In VRMath2, the third dimention can be utilised to cretae a curved 3D fern leaf, which is based on the 2D recursive procedure above.
|
; Recursive 3D fern procedure TO fern :size :sign :curve IF :size < 1 [ STOP ] ; exit condition FD :size RT 70 * :sign ; right branch fern :size * 0.5 :sign * -1 :curve ; alternates branches LT 70 * :sign FD :size LT 70 * :sign ; left branch fern :size * 0.5 :sign :curve RT 70 * :sign ; main body with a 7 degrees turn RT 7 * :sign RD :curve ; this rd (rollup) makes it 3D fern :size - 1 :sign :curve RU :curve LT 7 * :sign JB :size * 2 ; jb = jumpback END ; beginning construction CS ; clearscreen SETBG 29 ; set background 29: Blue-White Examine CM ; centimeter SETPCNAME "green ; set pen color by name RU 90 ; roll up 90 degrees PD ; pen down fern 16 1 10 PU ; pen up
|
2. Trees
There are a few popular trees created in traditional 2D Logo. In this project, we can experiemnt based on these 2D procedures and make 3D trees. Below are two tree examples, and you may copy the codes into the VRMath2 Editor to make them 3D.
|
; recursive tree ; TO tree :size IF :size < 5 [FORWARD :size JUMPBACK :size STOP] FORWARD :size/3 LEFT 30 tree :size*2/3 RIGHT 30 FORWARD :size/6 RIGHT 25 tree :size/2 LEFT 25 FORWARD :size/3 RIGHT 25 tree :size/2 LEFT 25 FORWARD :size/6 JUMPBACK :size END RESET CLEARSCREEN CM ; change to cemtimeter LINE ; change to line mode RU 90 PD tree 100 PU
|
Another tree (binary).
|
; Recursive tree ; TO trunk :size IF :size < 5 [STOP] FD :size LT 30 trunk :size*.7 RT 60 trunk :size*.7 LT 30 JB :size END RESET CS SETBG 29 CM RU 90 PD trunk 100 PU
|
Mathematical fractals
Fractals are recursive and self-similar. Using mathematical ideas with recursive programming could produce a variety of fractals. Here are some well known fractals.
1. Koch snowflake
Start with a triangle
| First iteration
| Second iteration
| Third iteration
|
2. Sierpiński triangle
Generated by recursive procedure
Start with a triangle
| First iteration
| Second iteration
| Thrid iteration
|
Generated by random procedure
2D, 3000 points
| 3D, 5000 points, tetrahedron
| 3D, 5000 points, Egyptian pyramid
|