Hippe013 Posted October 3, 2014 Posted October 3, 2014 (edited) 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 ) I hope that you enjoy! regards, Hippe013 Snake.LSP Edited October 3, 2014 by Hippe013 Added (princ) per comment Quote
marko_ribar Posted October 3, 2014 Posted October 3, 2014 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. Quote
Hippe013 Posted October 3, 2014 Author Posted October 3, 2014 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. Quote
Lee Mac Posted October 4, 2014 Posted October 4, 2014 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]) Quote
hanhphuc Posted October 6, 2014 Posted October 6, 2014 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 Quote
Pietari Posted October 6, 2014 Posted October 6, 2014 @ Hippe013: what a cool idea and such nice code. Well done! Quote
CADMASTER1128 Posted October 7, 2014 Posted October 7, 2014 Is it possible to have the game "Snake" run in AutoCAD? Talk about a Novelty LSP! Quote
Recommended Posts
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.