代码改变世界

AutoLISP 绘制表情图案

2011-03-28 12:51  精诚所至 金石为开  阅读(473)  评论(0编辑  收藏  举报

AutoLISP 绘制表情图案,喜怒哀乐表情,代码如下。

(defun c:test()
  (setvar "cmdecho" 0)
  (princ "\n选取圆或[ENTER]自定圆心半径:")
  (setq en (entsel))
  (if (null en)
    (progn
      (setq srr (getvar "circlerad"))
      (setq cen (getpoint "\n中心点:"))
      (setq rr (getpoint cen (strcat "\n半径<" (rtos srr 2) ">:")))
      (if (null rr) (setq rr srr))
      (command "circle" cen rr)
      (setq en (entlast))
      )
    (progn
      (setq en (car en))
      (setq endata (entget en))
      (setq cen (cdr (assoc 10 endata)))
      (setq rr (cdr (assoc 40 endata)))
      )
    )
  (initget "A B C D")
  (setq facetype (getkword "\nA-喜,B-怒,C-哀,D-乐,<A>:"))
  (if (null facetype) (setq facetype "A"))
  (cond ((= facetype "A") (lsp_21a))
    ((= facetype "B") (lsp_21b))
    ((= facetype "C") (lsp_21c))
    ((= faceytpe "D") (lsp_21d))
    )
  (prin1)
  )
(defun lsp_21a()
  (setq eye_1 (polar cen (/ pi 3) (/ rr 2)))
  (setq eye_2 (polar cen (- pi (/ pi 3)) (/ rr 2)))
  (command "donut" 0 (/ rr 5) eye_1 eye_2 "")
  (setq mon_1 (polar cen 0 (* rr 0.7)))
  (setq mon_2 (polar cen pi (* rr 0.7)))
  (command "arc" mon_2 "e" mon_1 "a" 180)
  )
(defun lsp_21b()
  (setq eye_1 (polar cen (/ pi 2.5) (/ rr 4)))
  (setq eye_2 (polar eye_1 (/ pi 6) (/ rr 2)))
  (command "line" eye_1 eye_2 "")
  (setq en1 (entlast))
  (setq eye_3 (polar (polar eye_1 (/ pi 6) (/ rr 10)) (- (/ pi 3)) (/ rr 20)))
  (command "donut" 0 (/ rr 10) eye_3 "")
  (setq en2 (entlast))
  (command "mirror" en1 en2 "" cen (polar cen (/ pi 2) rr) "")
  (setq mon_1 (polar cen (* pi 1.25) rr))
  (setq mon_2 (polar cen (* pi 1.5) (/ rr 3)))
  (setq mon_3 (polar cen (* pi 1.75) rr))
  (command "arc" mon_1 mon_2 mon_3)
  )
(defun lsp_21c()
  (setq eye_1 (polar cen (/ pi 2.5) (/ rr 2)))
  (setq eye_2 (polar eye_1 (/ pi 4) (/ rr 4)))
  (setq eye_3 (polar eye_1 (- (/ pi 4)) (/ rr 4)))
  (command "pline" eye_2 eye_1 eye_3 "")
  (setq en1 (entlast))
  (command "line" eye_1 (polar eye_1 0 (/ rr 3)) "")
  (setq en2 (entlast))
  (command "circle" (polar eye_3 (- (/ pi 4)) (/ rr 6)) (/ rr 12))
  (setq mon_1 (polar cen (* pi 1.5) (/ rr 2)))
  (setq mon_2 (polar cen (* pi 1.25) rr))
  (setq mon_3 (polar cen (* pi 1.75) rr))
  (command "mirror" en1 en2 "" cen (polar cen (/ pi 2) rr) "")
  (command "pline" mon_2 "a" "a" -120 mon_1 "a" -120 mon_3 "")
  (setvar "circlerad" rr)
  )
(defun lsp_21d()
  (setq eye_1 (polar cen (/ pi 2.5) (/ rr 2)))
  (setq eye_2 (polar eye_1 (/ pi 4) (/ rr 4)))
  (setq eye_3 (polar eye_1 (- (/ pi 4)) (/ rr 4)))
  (command "pline" eye_2 eye_1 eye_3 "")
  (setq en1(entlast))
  (command "line" eye_1 (polar eye_1 0 (/ rr 3)) "")
  (setq en2 (entlast))
  (setq mon_1 (polar cen 0 rr))
  (setq mon_5 (polar cen pi rr))
  (setq s_dd (/ rr 2))
  (setq mon_4a (polar mon_5 0 s_dd))
  (setq mon_4b (polar mon_4a (* pi 1.5) rr))
  (setq mon_3a (polar mon_4a 0 s_dd))
  (setq mon_3b (polar mon_3a (* pi 1.5) rr))
  (setq mon_2a (polar mon_3a 0 s_dd))
  (setq mon_2b (polar mon_2a (* pi 1.5) rr))
  (command "line" mon_1 mon_5 "")
  (command "line" mon_3a mon_3b "")
  (command "line" mon_2a mon_2b "")
  (setq en3 (entlast))
  (command "trim" en "" (list en3 mon_2b) "")
  (command "mirror" en1 en2 en3 "" cen (polar cen (/ pi 2) rr) "")
  )
(princ "\n------>>TEST<<------")
(prin1)

代码完。

C表情缺少左边眼睛,D调情直接没反应。