AutoCAD visual lisp实例:函数绘制
 1 (defun c:mysin ()
(defun c:mysin ()
2 (setq    x  0
  (setq    x  0
3 dx (/ pi 100)
    dx (/ pi 100)
4 )
  )
5 (setq y 0)
  (setq y 0)
6 (command "line")
  (command "line")
7
8 (while (<= x (* 2 pi))
  (while (<= x (* 2 pi))
9 (setq y (sin x))
    (setq y (sin x))
10 (command (list x y))
    (command (list x y))
11
12 (setq x (+ x dx))
    (setq x (+ x dx))
13 )
  )
14
15 (command "")
  (command "")
16 (command "line"
  (command "line"
17 (list 0 0)
       (list 0 0)
18 (list (* 2 pi) 0)
       (list (* 2 pi) 0)
19 ""
       ""
20 )
  )
21 (command "line"
  (command "line"
22 (list 0 -1)
       (list 0 -1)
23 (list 0 1)
       (list 0 1)
24 ""
       ""
25 )
  )
26 (command "zoom" "e")
  (command "zoom" "e")
27 )
)
28
 (defun c:mysin ()
(defun c:mysin ()2
 (setq    x  0
  (setq    x  03
 dx (/ pi 100)
    dx (/ pi 100)4
 )
  )5
 (setq y 0)
  (setq y 0)6
 (command "line")
  (command "line")7

8
 (while (<= x (* 2 pi))
  (while (<= x (* 2 pi))9
 (setq y (sin x))
    (setq y (sin x))10
 (command (list x y))
    (command (list x y))11

12
 (setq x (+ x dx))
    (setq x (+ x dx))13
 )
  )14

15
 (command "")
  (command "")16
 (command "line"
  (command "line"17
 (list 0 0)
       (list 0 0)18
 (list (* 2 pi) 0)
       (list (* 2 pi) 0)19
 ""
       ""20
 )
  )21
 (command "line"
  (command "line"22
 (list 0 -1)
       (list 0 -1)23
 (list 0 1)
       (list 0 1)24
 ""
       ""25
 )
  )26
 (command "zoom" "e")
  (command "zoom" "e")27
 )
)28

 
                    
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号