Jump to content

Novelty Lisp Program


Hippe013

Recommended Posts

I have attached a novelty lisp program that uses object reactors to link several circles together into a snake type figure. The snake head is manipulated using grread.

 

The two main functions are 'Snake' and 'Snake2'.

 

Snake: Is just the original idea. (More circles)

 

Snake2: Is fewer circles but the circles can push the other circles around. (AutoCAD doesn't like it so much when I add too many circles to this one :oops:)

 

I hope that you enjoy!

 

regards,

 

Hippe013

Snake.LSP

Edited by Hippe013
Added (princ) per comment
Link to comment
Share on other sites

Hippe013, what can I say... Awaysome... Both versions are simply fantastic... Only one thing, add (princ) at the end of lisp, it'll remove repeating of text as output... I must admit I don't use reactors too much, but this one is perfect...

 

Regards, all the best, M.R.

Link to comment
Share on other sites

Thanks Marko! I had one co-worker say that it was a good stress reliever. I have to give kudos to Lee Mac as I was I inspired both by his Bored.lsp and his ingenious use of mapcar and lambda which I am now finally starting to understand and use more frequently.

Link to comment
Share on other sites

Great idea Hippe - and thank you for the kudos, I'm delighted to have inspired you! :)

 

If you were looking for suggestions, I would personally avoid the use of reactors for this task, e.g.:

([color=BLUE]defun[/color] c:snake ( [color=BLUE]/[/color] c1 cl el gr p1 r1 r2 rl vs )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] p1 ([color=BLUE]getpoint[/color] [color=MAROON]"\nClick to generate the snake! "[/color]))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] vs ([color=BLUE]getvar[/color] 'viewsize)
                 r1 ([color=BLUE]/[/color] vs (LM:randrange 30 80))
           )
           ([color=BLUE]repeat[/color] 20
               ([color=BLUE]setq[/color] el ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] -1 ([color=BLUE]entmakex[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"CIRCLE"[/color]) ([color=BLUE]cons[/color] 10 p1) ([color=BLUE]cons[/color] 40 r1) ([color=BLUE]cons[/color] 62 ([color=BLUE]logand[/color] (LM:randrange 2 255) ([color=BLUE]~[/color] 1)))))) el)
                     cl ([color=BLUE]cons[/color] p1 cl)
                     rl ([color=BLUE]cons[/color] r1 rl)
                     r2 ([color=BLUE]/[/color] vs (LM:randrange 30 80))
                     p1 ([color=BLUE]cons[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] p1) r1 r2) ([color=BLUE]cdr[/color] p1))
                     r1 r2
               )
           )
           ([color=BLUE]setq[/color] el ([color=BLUE]reverse[/color] el)
                 cl ([color=BLUE]reverse[/color] cl)
                 rl ([color=BLUE]reverse[/color] rl)
           )
           ([color=BLUE]while[/color] ([color=BLUE]=[/color] 5 ([color=BLUE]car[/color] ([color=BLUE]setq[/color] gr ([color=BLUE]grread[/color] [color=BLUE]t[/color] 13 0))))
               ([color=BLUE]entmod[/color] ([color=BLUE]list[/color] ([color=BLUE]car[/color] el) ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] c1 ([color=BLUE]cadr[/color] gr)))))
               ([color=BLUE]setq[/color] cl
                   ([color=BLUE]cons[/color] c1
                       ([color=BLUE]mapcar[/color]
                          '([color=BLUE]lambda[/color] ( a b c d )
                               ([color=BLUE]entmod[/color] ([color=BLUE]list[/color] a ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] c1 ([color=BLUE]polar[/color] c1 ([color=BLUE]angle[/color] c1 c) ([color=BLUE]+[/color] b d))))))
                               c1
                           )
                           ([color=BLUE]cdr[/color] el) ([color=BLUE]cdr[/color] rl) ([color=BLUE]cdr[/color] cl) rl
                       )
                   )
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; Rand  -  Lee Mac[/color]
[color=GREEN];; PRNG implementing a linear congruential generator with[/color]
[color=GREEN];; parameters derived from the book 'Numerical Recipes'[/color]

([color=BLUE]defun[/color] LM:rand ( [color=BLUE]/[/color] a c m )
   ([color=BLUE]setq[/color] m   4294967296.0
         a   1664525.0
         c   1013904223.0
         $xn ([color=BLUE]rem[/color] ([color=BLUE]+[/color] c ([color=BLUE]*[/color] a ([color=BLUE]cond[/color] ($xn) (([color=BLUE]getvar[/color] 'date))))) m)
   )
   ([color=BLUE]/[/color] $xn m)
)

[color=GREEN];; Random in Range  -  Lee Mac[/color]
[color=GREEN];; Returns a pseudo-random integral number in a given range (inclusive)[/color]

([color=BLUE]defun[/color] LM:randrange ( a b )
   ([color=BLUE]fix[/color] ([color=BLUE]+[/color] a ([color=BLUE]*[/color] (LM:rand) ([color=BLUE]-[/color] b a -1))))
)
([color=BLUE]princ[/color])

Link to comment
Share on other sites

Nice creativity!! Good inspire!

i prefer realtime entmod which, however rarely see reactor example, good approach! Thank you guys for sharing!

Hippe & Lee you both deserve kudos :thumbsup:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...