cg-Cad

Lisp »Tips 'n Tricks »GRASS.LSP

grass
; TIP1039.LSP: GRASS.LSP 
; Realistic Grass for Elevations
; (c)1994,  Watson Kilbourne
; Draws row of grass with random height, 
; spacing and angle in elevation

; Random number generator, from 0.000 to 0.999
(defun rn () 
   (if (not sd) (setq sd (getvar "DATE")))
   (setq md 65536 mx 25173 nc 13849 sd 
     (rem (+ (* mx sd) nc) md)
   )
   (setq nx (/ sd md))
)
(defun c:GRASS (/ ce bm sp ep gh dn 
                  dx an p1 p2 p3 p4 p5)
   (setq ce (getvar "CMDECHO"))
   (setq bm (getvar "BLIPMODE"))
   (defun ne (ne)
      (setvar "CMDECHO" ce)
      (setvar "BLIPMODE" bm)
      (princ "\nFunction cancelled ")
      (princ)
   )
   (setq oe *error* *error* ne)
   (setvar "CMDECHO" 0)
   (while (= sp nil) 
      (setq sp (getpoint "\nStart point of grass: "))
   )
   (while (= ep nil) 
      (setq ep (getpoint "\nEnd point of grass: "))
   )
   (setq gh 
   (getdist "\nApproximate height of grass <Two inches>: ")
   )
   (if (= gh nil) (setq gh 2))
   (setq dn 
   (getint "\nDensity factor from 1 to 6 <3>: ")
   )
   (if (or (= dn nil) (> dn 6)) (setq dn 3))
   (setvar "BLIPMODE" 0)
   (setq dx (distance sp ep))
   (setq an (angle sp ep))
   (setq p1 sp p2 sp)
   (while (< (distance p2 sp) dx)
      (setq p2 (polar p1 an (/ (+ (rn) (/ gh 2)) dn)))
      (setq p3 (polar p2 (* pi 0.5) (* gh (rn))))
      (setq p4 (polar p3 (* pi 0.6) (* gh (rn))))
      (setq p5 (polar p4 (* pi 0.4) (* gh (rn))))
      (command "LINE" p3 p5 "")
      (setq p1 p2)
   )
   (setvar "BLIPMODE" bm)
   (setvar "CMDECHO" ce)
   (setq *error* oe oe nil)
   (princ)
)
; eof

Lisp »Tips 'n Tricks