{"id":1286,"date":"2007-03-22T14:35:54","date_gmt":"2007-03-22T06:35:54","guid":{"rendered":"http:\/\/ftp-highflybird.uu8.dnsnd.com\/blog\/?p=32"},"modified":"2020-02-29T22:52:18","modified_gmt":"2020-02-29T14:52:18","slug":"lisp%e7%9a%84%e4%b9%90%e8%b6%a3","status":"publish","type":"post","link":"https:\/\/www.highflybird.com\/blog\/?p=1286","title":{"rendered":"\u725b\u987f\u5206\u5f62\u7684LISP\u7a0b\u5e8f"},"content":{"rendered":"<p>\u725b\u987f\u5206\u5f62\u7b80\u4ecb\uff1a<br \/>\n\u5728\u590d\u6570\u57df\u4e0a\u4f7f\u7528\u725b\u987f\u8fed\u4ee3\u751f\u6210\u5206\u5f62\u56fe\u50cf\uff0c\u51fd\u6570\u516c\u5f0fF(z) = z^3 \u2013 1\u5728\u590d\u6570\u57df\u4e0a\u9762\u6709\u4e09\u4e2a\u6839\uff0c\u4e00\u4e2a\u662f1\uff0c\u53e6\u5916\u4e24\u4e2a\u5206\u522b\u662f\u590d\u6570-0.5+0.866i \u4e0e -0.5 \u2013 0.866i\u6839\u636e\u8ba1\u7b97\u51fa\u6765\u6839\u7684\u503c\u4e0d\u540c\u8f6c\u6362\u4e3aRGB\u4e09\u79cd\u4e0d\u540c\u7684\u989c\u8272\uff0c\u6839\u636e\u8fed\u4ee3\u6b21\u6570\u7684\u591a\u5c11\u8bbe\u7f6e\u989c\u8272\u503c\u7684\u5927\u5c0f\uff0c\u5373\u989c\u8272\u5f3a\u5ea6\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-123\" src=\"https:\/\/www.highflybird.com\/blog\/wp-content\/uploads\/2014\/08\/Newtons-Fractal-300x300.jpg\" alt=\"Newton's Fractal\" width=\"300\" height=\"300\"><br \/>\n\u4e0b\u9762\u662f\u7528LISP\u4ee3\u7801\u7684\u5b9e\u73b0\u3002<br \/>\n<!--more--><\/p>\n<pre lang=\"lisp\" line=\"1\">;;;************\n;;;\u725b\u987f\u8fed\u4ee3\u5206\u5f62\n;;;************\n(defun C:Nt (\/ con eps  OLDCMD oldsnap t0  gg ita)\n  (vl-load-com)\n  (setq *APP (vlax-get-acad-object))\n  (setq\tcolObj (vla-getinterfaceobject *APP \"AutoCAD.AcCmColor.16\"))\n  (setq OLDCMD (getvar \"CMDECHO\"))\n  (setq oldsnap (getvar \"OSMODE\"))\n  (princ \"n\u8bf7\u9009\u62e9\u4e09\u79cd\u4e0d\u540c\u7684\u989c\u8272:\")\n  (princ \"n\u9009\u62e9\u989c\u82721:n\")\n  (setq c1 (acad_truecolordlg 1))\n  (princ \"n\u9009\u62e9\u989c\u82722:n\")\n  (setq c2 (acad_truecolordlg 3))\n  (princ \"n\u9009\u62e9\u989c\u82723:n\")\n  (setq c3 (acad_truecolordlg 5))\n  (setq gg (getint \"n\u8f93\u5165\u989c\u8272\u68af\u5ea6:\"))\n  (setq sol (getint \"n\u8f93\u5165\u5206\u8fa8\u7387:\"))\n  (setq EPS (getreal \"n\u8f93\u5165\u8fed\u4ee3\u8bef\u5dee:\"))     ;\u8fed\u4ee3\u8bef\u5dee\n  (setq ita (getint \"n\u6700\u5927\u8fed\u4ee3\u6b21\u6570:\"))\n  (if (and c1 c2 c3 gg sol EPS ita)\n    (progn   \n      (setvar \"CMDECHO\" 0)\n      (setvar \"OSMODE\" 0)\n      (setq t0 (getvar \"TDUSRTIMER\"))\n      (NewTon_fractal sol sol EPS c1 c2 c3 gg ita)\n      (princ \"n\u753b\u725b\u987f\u5206\u5f62\u7528\u65f6\")\n      (princ (* (- (getvar \"TDUSRTIMER\") t0) 86400))\n      (princ \"\u79d2\")\n      ;;(command \".ZOOM\" '(39 39) '(361 361))\n      (command \".ZOOM\" \"E\")\n      (setvar \"OSMODE\" oldsnap)\n      (setvar \"CMDECHO\" OLDCMD)\n    )\n    (alert \"n\u4f60\u6ca1\u6709\u8f93\u5165\u6709\u6548\u9009\u62e9!\")\n  )\n  (gc)\n  (princ)\n)\n(defun trans-&gt;RGB (color \/ ccc) \n  (if (setq ccc (cdr (assoc 420 color)))\n    (Number-&gt;RGB ccc)\n    (Index-&gt;RGB colObj (cdr (assoc 62 color)))\n  )\n)\n(defun NewTon_fractal(solx soly EPS c1 c2 c3 grad ita \/\n\t\t      col1 col2 col3 hsl1 hsl2 hsl3 con xx yy nx ny\n\t\t      cm newx newy x y k)\n  (setq col1 (trans-&gt;RGB c1))  \n  (setq HSL1 (RGB-&gt;HSL (car col1) (cadr col1) (caddr col1)))\n  (setq col2 (trans-&gt;RGB c2))  \n  (setq HSL2 (RGB-&gt;HSL (car col2) (cadr col2) (caddr col2)))\n  (setq col3 (trans-&gt;RGB c3))  \n  (setq HSL3 (RGB-&gt;HSL (car col3) (cadr col3) (caddr col3)))\n  (setq CON (\/ (sqrt 3.0) 2))\n  (setq xx (\/ solX 4.0))\n  (setq yy (\/ solY 4.0))\n  (setq nx (\/ solx -2))\n  (repeat solx\n    (setq ny (\/ soly -2))\n    (repeat soly\n      (setq x (\/ nx xx))\n      (setq y (\/ ny yy))\n      (setq k 0)\n      (while (and (&lt; k ita) (\/= (dist x y) 0))\n\t(setq cm   (* 3 (dist x y) (dist x y))\n\t      newx (+ (* 2 x (\/ 1.0 3)) (\/ (- (* x x) (* y y)) cm))\n              newy (- (* 2 y (\/ 1.0 3)) (\/ (* 2 x y) cm))\n              x    newx\n\t      y    newy\n\t)\n\t(cond\n\t  ( (&lt; (dist (1- x) y) EPS)\n\t    (putcolor hsl1 nx ny k)\n\t    (setq k ita)\n\t  )\n          ( (&lt; (dist (+ x 0.5) (- y con)) EPS)\n            (putcolor hsl2 nx ny k)\n\t    (setq k ita)\n          )\n          ( (&lt; (dist (+ x 0.5) (+ y con)) EPS)\n\t    (putcolor hsl3 nx ny k)\n\t    (setq k ita)\n          )\n        )\t   \n\t(setq k (1+ k))\n      )\n      (setq ny (1+ ny))\n    )\n    (setq nx (1+ nx))\n  )\n)\n;;\u8ddd\u79bb\u5e73\u65b9\u51fd\u6570\n(defun dist (a b)\n  (+ (* a a) (* b b))\n)\n(defun putcolor\t(HSL nx ny k \/ nH ncolor)\n  (setq nH (rem (+ (car HSL) (* grad k)) 361))\n  (setq ncolor (hsl-&gt;rgb nH (cadr hsl) (caddr hsl)))\n  (setq ncolor (rgb-&gt;number ncolor))\n  (putpixel nx ny ncolor)\n)\n;;;==========================\n;;;\u7528entmake\u65b9\u6cd5\u753b\u50cf\u7d20\u70b9\u51fd\u6570 \n;;;==========================\n(defun putpixel (a b c)\n  (entmake\n    (list\n      '(0 . \"LWPOLYLINE\")    \n      '(100 . \"AcDbEntity\")\n      '(100 . \"AcDbPolyline\")\n      '(90 . 2)\n      '(43 . 1.0)\n      (cons 420 c)\n      (cons 10 (list a b))\n      (cons 10 (list (1+ a) b))\n    )\n  )\n)\n;;\u753b\u50cf\u7d20\u70b9\u51fd\u6570\n(defun putpixel2 (a b c)\n  (entmake\n    (list\n      '(0 . \"LWPOLYLINE\")    \n      '(100 . \"AcDbEntity\")\n      '(100 . \"AcDbPolyline\")\n      '(90 . 2)\n      '(43 . 1.0)\n      (cons 62 c)\n      (cons 10 (list a b))\n      (cons 10 (list (1+ a) b))\n    )\n  )\n)\n(defun putpixel1 (a b c)\n  (entmake\n    (list\n      '(0 . \"POINT\")\n      (cons 10 (list a b 0))\n      (cons 62 c)\n    )\n  )\n)\n\n;;;===============\n;;;HSL\u503c\u8f6cRGB\u503c   \n;;;\u8fd4\u56deRGB\u503c\u7684\u5217\u8868\n;;;===============\n;;;Hue\u8f6cRGB       \n(defun Hue-&gt;rgb (v1 v2 vHue \/ vH)\n  (cond\n    ((&lt; vHue 0) (setq vH (1+ vHue)))\n    ((&gt; vHue 1) (setq vH (1- vHue)))\n    (t (setq vH vHue))\n  )\n  (cond\n    ((&lt; (* 6 vH) 1) (+ v1 (* (- v2 v1) 6 vH)))\n    ((&lt; (* 2 vH) 1) v2)\n    ((&lt; (* 3 vH) 2) (+ v1 (* (- v2 v1) 6 (- 0.66666667 vH))))\n    (t v1)\n  ) \n)\n(defun Hsl-&gt;rgb (Hue Saturation Light \/ h s l r g b var2 var1)\n  (setq h (\/ Hue 360.0)\n\ts (\/ Saturation 100.0)\n\tl (\/ Light 100.0)\n  )\n  (if (= s 0)\n    (setq r (* l 255)\n\t  g (* l 255)\n\t  b (* l 255)\n    )\n    (setq var2 (if (&lt; l 0.5)\n\t\t (* l (1+ s))\n\t\t (+ l s (* s l -1))\n\t       )\n          var1 (- (* 2 l) var2)\n          r (* 255 (Hue-&gt;RGB var1 var2 (+ h 0.33333333)))\n          g (* 255 (Hue-&gt;RGB var1 var2 h))\n          b (* 255 (Hue-&gt;RGB var1 var2 (- h 0.33333333)))\n    )\n  )\n  (list (fix r) (fix g) (fix b))\n)\n;;;===============\n;;;RGB\u503c\u8f6cHSL\u503c   \n;;;\u8fd4\u56deHSL\u503c\u7684\u5217\u8868\n;;;===============\n(defun RGB-&gt;HSL(R G B \/ var_R var_G var_B var_min var_max\n\t\t        del_max del_R del_G del_B H L S)\n  (setq var_R (\/ R 255.0))\n  (setq var_G (\/ G 255.0))\n  (setq var_B (\/ B 255.0))\n  (setq var_min (min var_R var_G var_B))\n  (setq var_max (max var_R var_G var_B))\n  (setq del_max (- var_max var_min))\n  (setq L (\/ (+ var_max var_min) 2))\n  (if (= del_max 0)\n    (setq H 0 S 0)\n    (progn \n      (setq S (if (&lt; L 0.5)\n                (\/ del_max (+ var_max var_min))\n                (\/ del_max (- 2 var_max var_min))\n              )\n\t    del_R (\/ (+ (\/ (- var_max var_R) 6)  (\/ del_Max 2 )) del_max)\n\t    del_G (\/ (+ (\/ (- var_max var_G) 6)  (\/ del_Max 2 )) del_max)\n\t    del_B (\/ (+ (\/ (- var_max var_B) 6)  (\/ del_Max 2 )) del_max)\n      )\n      (cond\n\t( (= var_R var_max)\n\t  (setq H (- del_B del_G))\n\t)\n\t( (= var_G var_max)\n\t  (setq H (+ (\/ 1.0 3) del_R (- del_B)))\n\t)\n        ( (= var_B var_max)\n\t  (setq H (+ (\/ 2.0 3) del_G (- del_R)))\n\t)\n      )\n      (cond\n\t( (&lt; H 0) (setq  H (1+ H)))\n\t( (&gt; H 1) (setq  H (1- H)))\n      )\n    )\n  )\n  (setq h (* 360 H)\n\tS (* 100 S)\n\tl (* 100 l) \n  )\n  (list (fix H) (fix S) (fix L))\n)\n;;;===============\n;;;\u628atruecolordlg \n;;;420\u6784\u6210\u7684\u6570\u503c\u8fd4\n;;;\u56deRGB\u5217\u8868.     \n;;;===============\n(defun Number-&gt;RGB (C)\n  (list (lsh C -16)\n        (lsh (lsh C 16) -24)\n        (lsh (lsh C 24) -24)\n  )\n)\n;;;===============\n;;;\u628atruecolordlg \n;;;420\u6784\u6210\u7684\u6570\u503c\u8fd4\n;;;\u56deRGB\u5217\u8868.     \n;;;===============\n(defun RGB-&gt;Number (lst)\n  (+ (lsh (car lst) 16) (lsh (cadr lst) 8) (caddr lst))\n)\n;;;===============\n;;;RGB\u8f6c\u5316\u6210\u7d22\u5f15\u53f7\n;;;===============\n(defun RGB-&gt;Index (colorObj colRGB \/ )\n  (vla-setRGB colorobj (car colRGB) (cadr colRGB) (caddr colRGB)) \n  (vla-get-ColorIndex colorobj)\n)\n;;;===============\n;;;\u7d22\u5f15\u53f7\u8f6c\u5316\u6210RGB\n;;;===============\n(defun Index-&gt;RGB (colorobj ci \/ )\n  (vla-put-ColorIndex  colorobj ci)\n  (list (vla-get-red   colorobj)\n        (vla-get-green colorobj)\n        (vla-get-blue  colorobj)\n  )\n)\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u725b\u987f\u5206\u5f62\u7b80\u4ecb\uff1a \u5728\u590d\u6570\u57df\u4e0a\u4f7f\u7528\u725b\u987f\u8fed\u4ee3\u751f\u6210\u5206\u5f62\u56fe\u50cf\uff0c\u51fd\u6570\u516c\u5f0fF(z) = z^3 \u2013 1\u5728\u590d\u6570\u57df\u4e0a\u9762\u6709\u4e09\u4e2a\u6839\uff0c<\/p>\n<p class=\"more-link\"><a href=\"https:\/\/www.highflybird.com\/blog\/?p=1286\" class=\"themebutton2\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1286","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1286"}],"version-history":[{"count":0,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1286\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}