Lindenmayer README and minor x11 cleanups
parent
b5a1d10c9c
commit
ac057cd8f9
|
|
@ -0,0 +1,74 @@
|
|||
|
||||
----------------------------------------------------------------------
|
||||
Install
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Load, compile and save your image:
|
||||
|
||||
"load.factor" run-file save
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Usage
|
||||
----------------------------------------------------------------------
|
||||
|
||||
USE: lindenmayer setup-window
|
||||
|
||||
Towards the end of the "lindenmayer.factor" file, there are words for
|
||||
various L-systems. Let's pick abop-1, which is an example from the
|
||||
book The Algorithmic Beauty of Plants
|
||||
|
||||
abop-1
|
||||
|
||||
Look at the axiom
|
||||
|
||||
axiom get .
|
||||
|
||||
And the productions
|
||||
|
||||
rules get .
|
||||
|
||||
The string to be interpreted is stored in the result variable. Start
|
||||
off by calling init to copy the axiom to result
|
||||
|
||||
init
|
||||
|
||||
Look at result
|
||||
|
||||
result get .
|
||||
|
||||
It's just the axiom. Now iterate the string
|
||||
|
||||
iterate
|
||||
|
||||
You should see a branch and a leaf. Look at the result again:
|
||||
|
||||
result get .
|
||||
|
||||
Call iterate as many times as you want. :-) After about 4 iterations
|
||||
the tree starts to grow beyond the edge of the window. Change the
|
||||
point that the camera is looking at:
|
||||
|
||||
{ 0 0 3 } camera-focus set-global display
|
||||
|
||||
You can also change where the camera is located:
|
||||
|
||||
{ 0 0 10 } camera-position set-global display
|
||||
|
||||
Happy gardening
|
||||
|
||||
----------------------------------------------------------------------
|
||||
See also
|
||||
----------------------------------------------------------------------
|
||||
|
||||
The Algorithmic Beauty of Plants
|
||||
by Przemyslaw Prusinkiewicz and Aristid Lindenmayer
|
||||
Available online: http://algorithmicbotany.org/papers/abop/abop.pdf
|
||||
|
||||
The Computational Beauty of Nature
|
||||
Gary William Flake
|
||||
|
||||
Algorithmic Botany at the University of Calgary
|
||||
http://algorithmicbotany.org/
|
||||
|
||||
Laurens Lapre's Lparser
|
||||
http://home.wanadoo.nl/laurens.lapre/lparser.html
|
||||
|
|
@ -36,9 +36,6 @@ SYMBOL: orientation
|
|||
: step ( length -- )
|
||||
>r position get orientation get 0 0 r> 3array m.v v+ position set-global ;
|
||||
|
||||
! : step ( length -- )
|
||||
! >r position get orientation get r> 0 0 3array m.v v+ position set-global ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: record-vertex ( -- ) position get first3 glVertex3f ;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ lparser-dialect "" result set-global
|
|||
: display ( -- )
|
||||
GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT bitor glClear
|
||||
glLoadIdentity
|
||||
camera-position get first3 camera-focus get first3 camera-up get first3 gluLookAt
|
||||
camera-position get first3 camera-focus get first3 camera-up get first3
|
||||
gluLookAt
|
||||
reset result get save-state interpret restore-state glFlush ;
|
||||
|
||||
: reshape ( { width height } -- )
|
||||
|
|
@ -40,7 +41,7 @@ display ;
|
|||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: init ( -- ) axiom get result set ;
|
||||
: init ( -- ) axiom get result set display ;
|
||||
|
||||
: iterate ( -- ) result [ rewrite ] change display ;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
IN: gl USING: kernel words sequences alien arrays namespaces x xlib x11 ;
|
||||
|
||||
! : >int-array ( seq -- <int-array> )
|
||||
! dup length "int-array" <c-object> swap dup length >array
|
||||
! [ pick set-int-nth ] 2each ;
|
||||
|
||||
: >int-array ( seq -- <int-array> )
|
||||
dup length "int" <c-array> swap dup length >array [ pick set-int-nth ] 2each ;
|
||||
|
||||
|
|
@ -16,6 +12,6 @@ dup length "int" <c-array> swap dup length >array [ pick set-int-nth ] 2each ;
|
|||
: create-context ( XVisualInfo* -- GLXContext )
|
||||
>r dpy get r> 0 <alien> True glXCreateContext ;
|
||||
|
||||
: make-current ( GLXContext -- Bool ) >r dpy get win get r> glXMakeCurrent ;
|
||||
: make-current ( GLXContext -- ) >r dpy get win get r> glXMakeCurrent drop ;
|
||||
|
||||
: swap-buffers ( -- ) dpy get win get glXSwapBuffers ;
|
||||
|
|
|
|||
Loading…
Reference in New Issue