TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Ben Clark on October 07, 2020, 12:03:53 PM

Title: Random Appolonian Gasket in Autolisp
Post by: Ben Clark on October 07, 2020, 12:03:53 PM
Anyone tried to code this yet? Seems like it would be a good challenge. Similar to doing a mandelbrot fractal, koch snowflake, Sierpinski triangel, etc.

If anyone is into recursion I'm sure it'd be fun  :laugh:

Title: Re: Random Appolonian Gasket in Autolisp
Post by: Stefan on October 07, 2020, 11:34:05 PM
Found some use for one of my favorite toys, inverted circles...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:gasket ( / p r i a b c cen lst msg)
  2.   (if
  3.     (and
  4.       (setq p (getpoint  "\nSpecify Gasket Center: "))
  5.       (setq r (getdist p "\nSpecify Gasket Radius: "))
  6.       (setq i (getint    "\nSpecify Gasket Level (3...10): "))
  7.       (<= 3 i 10)
  8.     )
  9.     (progn
  10.       (setq a (* r      (sqrt 3) )
  11.             b (/ r (+ 2 (sqrt 3)))
  12.             c (/ a (+ 2 (sqrt 3)))
  13.       )
  14.  
  15.       (setq cen
  16.         (cons (list p b)
  17.           (mapcar
  18.             (function
  19.               (lambda (u)
  20.                 (list (polar p u (* 2.0 r)) a)
  21.               )
  22.             )
  23.             (list (/ pi 6) (/ (* 5 pi) 6) (* 1.5 pi))
  24.           )
  25.         )
  26.       )
  27.  
  28.       (setq lst
  29.         (cons
  30.           (list (inverted_circle (car cen) (circ p r)))
  31.           (mapcar
  32.             (function
  33.               (lambda (ctr u)
  34.                 (list (inverted_circle ctr (circ (polar p u (- r c)) c)))
  35.               )
  36.             )
  37.             (cdr cen)
  38.             (list (/ (*  7 pi) 6) (/ (* 11 pi) 6) (/ pi 2))
  39.           )
  40.         )
  41.       )
  42.  
  43.       (repeat (- i 3)
  44.         (setq lst
  45.           (mapcar
  46.             (function
  47.               (lambda (c l)
  48.                 (mapcar '(lambda (p) (inverted_circle c p)) l)
  49.               )
  50.             )
  51.             cen
  52.             (list
  53.               (append (cadr lst) (caddr lst) (cadddr lst))
  54.               (append (car  lst) (caddr lst) (cadddr lst))
  55.               (append (car  lst) (cadr  lst) (cadddr lst))
  56.               (append (car  lst) (cadr  lst) (caddr  lst))
  57.             )
  58.           )
  59.         )
  60.       )
  61.     )
  62.   )
  63.   (princ)
  64. )
  65.  
  66. (defun m2p (a b) (mapcar (function (lambda (a b) (/ (+ a b) 2))) a b))
  67.  
  68. (defun circ (p r) (entmakex (list '(0 . "circle") (cons 10 p) (cons 40 r))) (list p r))    
  69.  
  70. (defun inverted_circle (l1 l2 / p1 r1 p2 r2 a d e1 e2)
  71.   (mapcar (function set) '(p1 r1) l1)
  72.   (mapcar (function set) '(p2 r2) l2)
  73.   (setq a  (angle p1 p2)
  74.         d  (distance p1 p2)
  75.         e1 (polar p1 a (/ (* r1 r1) (+ d r2)))
  76.         e2 (polar p1 a (/ (* r1 r1) (- d r2)))
  77.   )
  78.   (circ (m2p e1 e2) (/ (distance e1 e2) 2))
  79. )
Title: Re: Random Appolonian Gasket in Autolisp
Post by: Ben Clark on October 09, 2020, 04:36:05 PM
Incredible!!! I still don't fully understand what an inverted circle is after looking it up, but this is really cool. It will take me some time to understand your code. Well done.
Title: Re: Random Appolonian Gasket in Autolisp
Post by: d2010 on October 10, 2020, 03:24:50 PM
In the future you must use three-letters+ for name-of-variabiles
(I see. popf, cwd see my picture). :angel:
Code: [Select]
Eg. I replace  ~ (repeat (- i 3)~ with
                ~for(;levelator>=0;levelator=levelator-1)~
I think (Pi) is obsolute. I re-use kpi from ObjectARx-Sdk-AutoCad2010.
const double kPi = 3.14159265358979323846;
const double kTwoPi = 6.28318530717958647692;
const double kHalfPi = 1.57079632679489661923;
const double kTolerance = 1.0e-10;
const double kEpsilon = 1.0e-10;
:-o
Found some use for one of my favorite toys, inverted circles...
How to develope Artistic'Sources?