0 Members and 1 Guest are viewing this topic.

#### Ben Clark

• Newt
• Posts: 94
##### Random Appolonian Gasket in Autolisp
« 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

#### Stefan

• Bull Frog
• Posts: 239
##### Re: Random Appolonian Gasket in Autolisp
« Reply #1 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: "))
6.       (setq i (getint    "\nSpecify Gasket Level (3...10): "))
7.       (<= 3 i 10)
8.     )
9.       (setq a (* r      (sqrt 3) )
10.             b (/ r (+ 2 (sqrt 3)))
11.             c (/ a (+ 2 (sqrt 3)))
12.       )
13.
14.       (setq cen
15.         (cons (list p b)
16.               (lambda (u)
17.                 (list (polar p u (* 2.0 r)) a)
18.               )
19.             )
20.             (list (/ pi 6) (/ (* 5 pi) 6) (* 1.5 pi))
21.           )
22.         )
23.       )
24.
25.       (setq lst
26.         (cons
27.           (list (inverted_circle (car cen) (circ p r)))
28.               (lambda (ctr u)
29.                 (list (inverted_circle ctr (circ (polar p u (- r c)) c)))
30.               )
31.             )
32.             (cdr cen)
33.             (list (/ (*  7 pi) 6) (/ (* 11 pi) 6) (/ pi 2))
34.           )
35.         )
36.       )
37.
38.       (repeat (- i 3)
39.         (setq lst
40.               (lambda (c l)
41.                 (mapcar '(lambda (p) (inverted_circle c p)) l)
42.               )
43.             )
44.             cen
45.             (list
50.             )
51.           )
52.         )
53.       )
54.     )
55.   )
56.   (princ)
57. )
58.
59. (defun m2p (a b) (mapcar (function (lambda (a b) (/ (+ a b) 2))) a b))
60.
61. (defun circ (p r) (entmakex (list '(0 . "circle") (cons 10 p) (cons 40 r))) (list p r))
62.
63. (defun inverted_circle (l1 l2 / p1 r1 p2 r2 a d e1 e2)
64.   (mapcar (function set) '(p1 r1) l1)
65.   (mapcar (function set) '(p2 r2) l2)
66.   (setq a  (angle p1 p2)
67.         d  (distance p1 p2)
68.         e1 (polar p1 a (/ (* r1 r1) (+ d r2)))
69.         e2 (polar p1 a (/ (* r1 r1) (- d r2)))
70.   )
71.   (circ (m2p e1 e2) (/ (distance e1 e2) 2))
72. )
« Last Edit: October 09, 2020, 06:51:21 PM by Stefan »

#### Ben Clark

• Newt
• Posts: 94
##### Re: Random Appolonian Gasket in Autolisp
« Reply #2 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.

#### d2010

• Newt
• Posts: 84
##### Re: Random Appolonian Gasket in Autolisp
« Reply #3 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).
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;`
Found some use for one of my favorite toys, inverted circles...
How to develope Artistic'Sources?
« Last Edit: October 12, 2020, 03:39:32 PM by d2010 »