Author Topic: Rob's Lisp Adventures  (Read 15128 times)

0 Members and 1 Guest are viewing this topic.

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #15 on: February 28, 2015, 12:43:56 PM »
A Sierpinski pyramid (Racket Scheme)

Source compiled under Linux and Windows -- strangely the Windows version gives an empty screen when using glLists ..  so attached a somewhat crippled Windows version where every frame is recalculated all over  :-[   -- the Linux version performs the callList

sigh


the idea is to extend the Sierpinski recursion into 3D , it even may expanded in a way  obj1->...   objX ...  -> obj1 etc.. , i mean , here the pyramid is transformed into a congruent object , but everything is possible

best Rob , 

https://www.dropbox.com/s/aaqfxh9c5zf9kae/pyramidL.7z?dl=0   (for Linux)
https://www.dropbox.com/s/j71yh9n4mcohcl3/pyraWin.7z?dl=0   (for Windows)

addendum :  thanks for your reply Mike , messages crossed each other , -- excellent info !   :)



.

Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures
« Reply #16 on: February 28, 2015, 12:55:02 PM »
Hehe, it works though rather slow indeed and with only one iteration (5 pyramids all in all).

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #17 on: March 01, 2015, 12:07:32 PM »
Hi Mike,

You have to edit the text field , and then hit the update button.  However it is restricted to 6 iterations.
In the mean time , I tried it by combining two scripting language : newLISP together with tBasic.  Generating the pyramids is easier in Lisp (just mapping the 1->5 mutation repeatedly over the same growing lisp ).
However, for the max level 6 , Lisp needs 0.15 sec to build all the coordinates , and further around 0.7sec to convert the list into an array (vector in Scheme) (so it can be indexed and called by thinBasic ) the glList building up in tB takes (a lot of) time (several secs) for this level 6.
I also replaced the single pyramid by a single quad.

(tested under Windows and Wine)

best Rob
(use arrow keys and pgUp pgDown)


.
« Last Edit: March 01, 2015, 12:35:41 PM by RobbeK »

Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures
« Reply #18 on: March 01, 2015, 12:37:52 PM »
Hi Rob,

Quote
You have to edit the text field , and then hit the update button.

Actually, no. That didn't produce any visible effect for me. There would always be only 5 pyramids visible, 4 in the bottom row and 1 more on top of it. In other words, the proggy was unresponsive to the input in the text field.

The same effectively applies to this one as well. Changing the number in the text field has no effect, and the only way to change the display is to press the buttons. At the same time, I can't rotate or navigate the view and the structure is seen at some odd angle only.

And yes, it takes very long to recalc the scene... :(

.

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #19 on: March 01, 2015, 01:44:58 PM »
Hi Mike,

" Changing the number in the text field has no effect, "  --  oops , my mistake ; should be a label ;  but the navigation by the arrow key works here...

trying it with GFA then,   

however  :-\   , GFA does not accept gl vectors , needed for p.e. materials and lights -- it crashes on setting up arrays of single floats and giving back the array pointer to the GL functions.

thanks again,  Rob 



Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures
« Reply #20 on: March 01, 2015, 02:14:22 PM »
... but the navigation by the arrow key works here...

Oops, entirely my fault! :-[

I'm mostly a point-and-click guy, and pressing arrows is usually the last thing on my mind. As an alternative, I could use some WASD keys, which is natural for such a seasoned gamer as I am: :D



I'm sorry for my mistake; the arrow keys are functioning here too as intended.

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #21 on: March 02, 2015, 01:33:34 PM »
 ::)

on mine the parenthesis are almost gone !!

the problems :

-Racket Scheme can NOT do glLists under windows (tested by glGenLists and the answer is nil )  -- explaining does blank screens
-As you stated, there are other problems too
-newLISP and using glut under windows can show static images , the moment motion comes in, the window goes gaga (somewhat as single-buffer graphics , but worse)
 -can not find to set up gl vectors under GFA ,  single float array - arraypointer  ---  C style mAlloc with address --  etc nothing works.
-JAVA is not that stable under Linux , under Wine it is catastrophic
-embedding newLISP under a Linux programming environment is at least difficult if possible

etc etc ...

A pity about Racket Scheme ---  "Among the Racket com­mu­nity, which is laden with com­puter-sci­ence PhDs & pro­fes­sors ....   etc    "
(& I always start with the idea that it is me who made the mistake)

No problems with Steel Bank CL (for the moment)



Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures
« Reply #22 on: March 02, 2015, 02:36:59 PM »
::)
on mine the parenthesis are almost gone !!

Ahahahahahaha!!! You bet! I'm seeing the same about my C-ish braces! (fr. accolades)  ;D

Quote
the problems :
-> -> -> -> -> 
"Among the Racket com­mu­nity, which is laden with com­puter-sci­ence PhDs & pro­fes­sors ....   etc"

That's always the same with the communities overpopulated with fossil fauna. They would simply not know, or have long forgotten, their way around the graphics environment of a modern operating system. Take BP.org for example. The place is fly-bitten by a coupla marasmic characters that are doing their utmost to scare people off the place. I stopped posting there a while ago. Now I see Mr Russel of BBC BASIC has just slammed the door behind him. Who's next, guys?

John, how are you feeling yourself in that monkey house?

Quote
(& I always start with the idea that it is me who made the mistake)

And I'd say that would be the most reasonable behavioral pattern for a sentient being.

Quote
No problems with Steel Bank CL (for the moment)

So things aren't that bad after all, are they? :)

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #23 on: March 03, 2015, 03:02:53 AM »
Hi Mike,

"So things aren't that bad after all, are they? "  , yes , and nothing is gained by giving up  .  It *is* possible to generate 1 glList at the time when running under windows(Racket).  I tried manipulation by glGenLists , glDeleteLists etc..  but one is the max I get.
Nevertheless in most cases this gives a-look-worthy result (though the idea here was a "fluid" demonstration of the iteration (recursion) levels.
)

so, attached something that works --  the X button does nothing - it's for testing some things not so clear to me.
Done on a ten years old machine running XP, it may work too fast on your computer -- i tuned the timer loop as fast as possible for this museum item (but even then it's not a defective show)

best Rob

.
« Last Edit: March 03, 2015, 03:22:37 AM by RobbeK »

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #24 on: March 03, 2015, 12:12:45 PM »
ADDENDUM

out of desperation ... 

switched to the ancestor of Racket -- PLT Scheme :  http://plt-scheme.org/

"maintained for historical reasons only"
yep, and also the calculations run about twice as fast , smaller executables ,  no glList problems ,  no flashing screen under Wine , and while (on another Win7 machine , Racket reclaimed there was no OGL context )  PLT runs happy there.

some gadgets are missing ,  have to look if lazy Scheme and typed Scheme are present (declarations like in CL - the slowness of these Lisps is very related every number may be a big number or a complex number - when turned off , Lisp speeds up a lot (not that something as Steelbank CL is slow -- (once in the top ten ...  ))

best Rob  (prog : you can change the recursion level now)    -- update : no levels under Win7 , works on XP (? at least here)  this is all very strange

.
« Last Edit: March 04, 2015, 01:51:44 AM by RobbeK »

Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures
« Reply #25 on: March 04, 2015, 02:50:20 AM »
Hi Rob,

Sierpinski PLT runs very nice here and very fast too under XP (not yet checked under 7). But! It eats memory as the structure spins round and round. When stopped, memory leakage ceases.

Did you limit the max number of iterations? It looks like my PC could use a few more iterations without slowdown...


[UPD]

It works under Win 7 exactly as it does under XP for me. I can increase and decrease the number of iterations as I please but the memory leak is also seen here.
« Last Edit: March 04, 2015, 03:41:36 AM by Mike Lobanovsky »

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #26 on: March 04, 2015, 06:39:45 AM »
Hi Mike,

I replaced (sleep/yield 0) (DoEvents equivalent ) with a "straight" sleep for 10mSec now , it runs now under Win7 too , but sometimes i have to double/triple click the buttons .

OK an updated version -- 4 you up to level 8 (this info in the label field now). on the 10 yrs old machine level 6 is about the max.
Ah,yes for fun..  a pyramid with a triangular base.
If too fast I'll put up two textfields :  one with the angle increase/frame value -- the other with the timer interval , these can be fed to the code (while running).

the problem with glCallLisp under Racket Scheme ,  may be related with attached image -- it seems the FFI does not convert the Scheme number into a C uint32 (???)  --from running the code in the REPL

best Rob (and now a hexagonal base ??  8)

--  ouput sensors / cpu usage (Linux) attached  -- that's too optimistic 20-25% is more correct --  u can c i almost had a melt-down  ;D

.
« Last Edit: March 04, 2015, 07:06:08 AM by RobbeK »

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #27 on: March 05, 2015, 02:50:45 PM »
And some Lsystems in 3D  (maybe this is something new )

Code is ready to accept any L-system / # recursions as input - (need to write the text-fields for it)
(for the moment the section is only calculated as a square , but I think I'll change to hexagonal later)

a lot of recursion is used :

-------------------------------------------------the core of the code -----------------

(define-syntax-rule (gl-begin-end Vertex-Mode statement ...)
  (let () (glBegin Vertex-Mode) statement ... (glEnd)))

 
(define rot 0)

(define world (list 'l))
(define rule (list 'l 45 'l -90 'l 45 'l))

(define needs-recalc #t)
(define level 1)

(define (mutate* L M)
  (if (null? L) M
      (if (eq? (car L) 'l) (mutate* (cdr L) (cons rule M))
          (mutate* (cdr L) (cons (car L) M)))))

(define (mutate x)
  (let ((L world))
    (for ((i (in-range x))) (set! L (flatten (mutate* L '() ))))
    L ))

(define (->rad x) (/ (* x pi) 180))

(define (cartesian* L xo yo ao M)
  (if (null? L) M
    (if (eq? (car L) 'l) (cartesian* (cdr L) (+ xo (cos (->rad ao))) (+ yo (sin (->rad ao))) ao (cons (list xo yo) M))
        (cartesian* (cdr L) xo yo (+ (car L) ao) M))))

(define (cartesian L) (cartesian* L 0.0 0.0 0.0 '() ))

 
(define (scale* f L M)
  (if (null? L) M
      (scale* f (cdr L) (cons (list (- (* f (caar L)) 1) (+ 0.005 (* f (cadar L)))) M))))

---------------------------------------------------the JIT compiler does TCO (all replaced by iteration)

written in PLT Scheme - compiled for Windows (and identical code for Linux too --not attached)

best Rob (quiet interesting imho)

 


.

Charles Pegge

  • Guest
Re: Rob's Lisp Adventures
« Reply #28 on: March 06, 2015, 02:28:37 AM »
I found the Sierpinski Tetrahedron irresistable, though rendering it with OpenGl geometry is quite intensive.

The pyramid is less congested, and may be a useful roof structure, using a combination of girders and pencils :)

.
« Last Edit: March 06, 2015, 02:53:20 AM by Charles Pegge »

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #29 on: March 06, 2015, 04:44:10 AM »
Cool Charles  8)   -- it has the looks of a  tubular construction of extreme strength !!  -- did you build it with string arrays ??

In the mean time the Lsystem is ready for user input :
use a " l " for "line"  -- (lower L) and any angle.
The system is every l in the "world" is replaced by the "rule" (recursively)  -- in the example attached it starts with two lines now.
to avoid convergence and divergence it is best to keep the sum of the angles =0 in the rule (and world).


** for scaling and positioning the code does not scale for negatives coordinates (not yet) -- so if you build a square as "the world" start with 90° (is upwards) -- in this way the values will not go below zero.
I'll make a "Charles style"  wired / tubed version too -- sometimes a lot is hidden inside

best Rob   (compiled and tested under Ubuntu Linux and Win32 XP (attached))



.