# Spirala_LISP

Apr 19th, 2020
877
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. ;;; spiral.lsp/c:spiral
2. ;;;
3. ;;; Draws a spiral consisting of points, evenly spaced at a
4. ;;; given distance. The spiral can be clockwise- or
5. ;;; counterclockwise-oriented, starts at a given initial radius
6. ;;; and its radius increases uniformly over rotations with a
7. ;;; specified increment. The spiral winds about a center point
8. ;;; and contains a finite given number of points.
9. (defun C:SPIRAL ( / center radius rinc delta points direction
10.  distprompts distances angoffset FULLCIRCLE
11.  cmdecho_store)
12.  ; init constants
13.  (setq FULLCIRCLE (* 2 pi))
14.
15.  ; retrieve spiral characteristics
16.  ; center point
17.  (setq center (getpoint "Center of spiral: "))
18.
19.  ; since the various various needed distances are similarly
20.  ; obtained, this is done in a loop
21.  (setq distprompts '("\nInitial spiral radius: "
22.  "\nRadius increment per full rotation: "
23.  "\nLinear distance between consecutive
24. points: "
25.  )
26.  distances nil)
27.  (while distprompts ; while we haven't gone thru all the prompts
28.  (initget 7) ; allow only strictly positive values
30.  (setq distances (cons (getdist (car distprompts)) distances)
31.  distprompts (cdr distprompts) ; next
32.  )
33.  )
34. Page 8
35. AutoLISP. Lists Handling
36.  ; the distances list looks now something like:
38.  ; - due to the (cons), values are reversed with respect to prompts
41.  delta (car distances)
42.  )
43.  ; # of points on the spiral
44.  (initget 7)
45.  (setq points (getint "\nNumber of points on the spiral: "))
46.  ; spiral direction
47.  (initget 1 "Clockwise counteRclockwise")
48.  (setq direction (getkword "\nSpiral direction (Clockwise
49. counteRclockwise): "))
50.
51.  ; store and customize environment settings
52.  (setq cmdecho_store (getvar "CMDECHO"))
53.  (setvar "CMDECHO" 0) ; no commands echo
54.  (setvar "PDMODE" 33) ; points represented as circles
55.  ; all set, we are ready to begin drawing
56.  (setq ang 0) ; we start at a horizontal angle
57.  (while (/= points 0)
58.  ; place point at the current orientation and radius with respect
59.  ; to the center
60.  (command "point" (polar center ang radius))
61.  ; linear distance between points (length of arc) must
62.  ; be (more or less) constant; therefore, we must take
63.  ; the radius into consideration when modifying the angle
64.  (setq angoffset (/ delta radius)
65.  ang (if (= direction "Clockwise") (- ang angoffset)
66.  (+ ang angoffset))
67.  )
68.  ; confine within [0, 2pi)
69.  (if (< ang 0) (setq ang (+ ang FULLCIRCLE)))
70.  (if (>= ang FULLCIRCLE) (setq ang (- ang FULLCIRCLE)))
71.  ; increase the radius by a fraction of the radius increment
72.  ; corresponding to the displaced angle