; The Codewriting Workbook ; Creating Computational Architecture in AutoLISP ; by Robert J. Krawczyk ; Princeton Architectural Press, 2008 ; -------------------------------------------------------------------------- ; CH06A.LSP ; -------------------------------------------------------------------------- ; Disclaimer: The information contained in this file is distributed on an ; "as is" basis, without warranty. Although every precaution has been taken ; in the preparation of this work, the author and publisher shall not have ; any liability to any person or entity with respect to any loss or damage ; caused or alleged to be caused directly or indirectly by the information ; contained in this work. ; -------------------------------------------------------------------------- (defun dtr (a) (* pi (/ a 180.0))) (defun rtd (a) (/ (* a 180.0) pi)) ; -------------------------------------------------------------------------- (defun sign (a) (if (< a 0.0) (- 0 1.0) (+ 0 1.0))) ; -------------------------------------------------------------------------- (defun rn (/ modulus multiplier increment random) (if (not rnseed) (setq rnseed (getvar "DATE"))) (setq modulus 65536 multiplier 25173 increment 13849 rnseed (rem (+ (* multiplier rnseed) increment) modulus) random (/ rnseed modulus) ) ) ;--------------------------------------------------------------------------- ; -------------------------------------------------------------------------- (defun rotate2d ( pt ptc ang / pt1 pt2 ) ; rotate pt ang degrees (setq pt1 (list (+ (nth 0 pt) (- 0 (nth 0 ptc))) (+ (nth 1 pt) (- 0 (nth 1 ptc))) (nth 2 pt))) (setq pt2 (list (- (* (nth 0 pt1) (cos (dtr ang))) (* (nth 1 pt1) (sin (dtr ang)))) (+ (* (nth 0 pt1) (sin (dtr ang))) (* (nth 1 pt1) (cos (dtr ang)))) (nth 2 pt))) (list (+ (nth 0 pt2) (+ 0 (nth 0 ptc))) (+ (nth 1 pt2) (+ 0 (nth 1 ptc))) (nth 2 pt)) ) ;--------------------------------------------------------------------------- ;--------------------------------------------------------------------------- ; ZW - zoom window (defun c:zw () (command "zoom" "w") ) ; ZP - zoom previous (defun c:zp () (command "zoom" "p") ) ; ZE - zoom extents (defun c:ze () (command "zoom" "e" "zoom" ".9x") ) ; ZX - zoom .9x (defun c:zx () (command "zoom" ".9x") ) ;--------------------------------------------------------------------------- ; VT - top view (defun c:vt () (command "vpoint" "r" 270 90) (command "zoom" "e" "ucs" "v" "zoom" ".9x") (princ) ) ; VL - left view (defun c:vl () (command "vpoint" "r" 180 0) (command "zoom" "e" "ucs" "v" "zoom" ".9x") (princ) ) ; VR - right view (defun c:vr () (command "vpoint" "r" 0 0) (command "zoom" "e" "ucs" "v" "zoom" ".9x") (princ) ) ; VF - front view (defun c:vf () (command "vpoint" "r" 270 0) (command "zoom" "e" "ucs" "v" "zoom" ".9x") (princ) ) ; VB - back view (defun c:vb () (command "vpoint" "r" 90 0) (command "zoom" "e" "ucs" "v" "zoom" ".9x") (princ) ) ; VSW - SW view (defun c:vsw () (command "vpoint" "r" 270 90) (command "ucs" "v") (command "vpoint" "r" 225 45) (command "zoom" "e" "zoom" ".9x") (princ) ) ; VSE - SE view (defun c:vse () (command "vpoint" "r" 270 90) (command "ucs" "v") (command "vpoint" "r" 315 45) (command "zoom" "e" "zoom" ".9x") (princ) ) ; VNE - NE view (defun c:vne () (command "vpoint" "r" 270 90) (command "ucs" "v") (command "vpoint" "r" 45 45) (command "zoom" "e" "zoom" ".9x") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog01 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) ; draw rectangle (command ".RECTANGLE" pnt1 pnt2) ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) (princ) ) ;-------------------------------------------------------------------------- (defun prog02 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) ; draw rectangle (command ".RECTANGLE" pnt1 pnt2) ; compute height (setq zheight (+ zmin (* (rn) (- zmax zmin)))) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- (defun prog03 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) (setq crad (getdist "\nEnter circle radius: ")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; center of square (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; draw circle (command ".CIRCLE" pnt2 crad) ; compute height (setq zheight (+ zmin (* (rn) (- zmax zmin)))) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; base, upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" (/ zmin 2)) ; versions prior to 2007 require teh taper parameter ;(command ".EXTRUDE" "last" "" (/ zmin 2) "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- (defun prog04 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) (setq nsides (getint "\nEnter polygon sides:")) (setq crad (getdist "\nEnter polygon radius: ")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; center of square (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; draw polygon (command ".POLYGON" nsides pnt2 "I" crad) ; comoute height (setq zheight (+ zmin (* (rn) (- zmax zmin)))) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" (/ zmin 2) "") ; base, upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" (/ zmin 2)) ; versions prior to 2007 require teh taper parameter ;(command ".EXTRUDE" "last" "" (/ zmin 2) "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") ; trim edges ; center of boundary (setq pntc (list (+ (nth 0 pnt0) (* (/ xtimes 2.0) xyside)) (+ (nth 1 pnt0) (* (/ ytimes 2.0) xyside)) (nth 2 pnt0))) ; bottom edge (setq pnt1 pnt0) (setq pnt2 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; top edge (setq pnt1 (list (nth 0 pnt0) (+ (nth 1 pnt0) (* ytimes xyside)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; left edge (setq pnt1 pnt0) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; right edge (setq pnt1 (list (+ (nth 0 pnt0) (* xtimes xyside)) (nth 1 pnt0) (nth 2 pnt0))) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) (princ) ) ;-------------------------------------------------------------------------- (defun prog05 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq hlist (read (getstring "\nEnter height list:"))) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; upper corner of square (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) ; draw rectangle (command ".RECTANGLE" pnt1 pnt2) ; compute height (setq n (fix (* (rn) (- (length hlist) 0.1)))) (setq zheight (nth n hlist)) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add height to model (command ".TEXT" (list (+ (nth 0 pnt1) (/ xyside 10)) (+ (nth 1 pnt1) (/ xyside 10)) (nth 2 pnt1)) (/ xyside 10) "0" (rtos zheight 2 2)) ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- (defun prog06 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) (setq angx (getreal "\nEnter angle multiple: ")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) ; draw rectangle (command ".RECTANGLE" pnt1 pnt2) ; center of square (setq pnt3 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) 0)) ; rotate (setq rotang (* (fix (* (rn) 10.0)) angx)) (command ".ROTATE" "last" "" pnt3 rotang) ; compute height (setq zheight (+ zmin (* (rn) (- zmax zmin)))) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; base (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" (/ zmin 2)) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" (/ zmin 2) "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") ; trim edges ; center of boundary (setq pntc (list (+ (nth 0 pnt0) (* (/ xtimes 2.0) xyside)) (+ (nth 1 pnt0) (* (/ ytimes 2.0) xyside)) (nth 2 pnt0))) ; bottom edge (setq pnt1 pnt0) (setq pnt2 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; top edge (setq pnt1 (list (nth 0 pnt0) (+ (nth 1 pnt0) (* ytimes xyside)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; left edge (setq pnt1 pnt0) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; right edge (setq pnt1 (list (+ (nth 0 pnt0) (* xtimes xyside)) (nth 1 pnt0) (nth 2 pnt0))) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog06a () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq hlist (read (getstring "\nEnter height list:"))) (setq angx (getreal "\nEnter angle multiple: ")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) ; draw rectangle (command ".RECTANGLE" pnt1 pnt2) ; center of square (setq pnt3 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) 0)) ; rotate (setq rotang (* (fix (* (rn) 10.0)) angx)) (command ".ROTATE" "last" "" pnt3 rotang) ; compute height (setq n (fix (* (rn) (- (length hlist) 0.1)))) (setq zheight (nth n hlist)) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; base (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" (/ zmin 2)) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" (/ zmin 2) "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") ; trim edges ; center of boundary (setq pntc (list (+ (nth 0 pnt0) (* (/ xtimes 2.0) xyside)) (+ (nth 1 pnt0) (* (/ ytimes 2.0) xyside)) (nth 2 pnt0))) ; bottom edge (setq pnt1 pnt0) (setq pnt2 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; top edge (setq pnt1 (list (nth 0 pnt0) (+ (nth 1 pnt0) (* ytimes xyside)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; left edge (setq pnt1 pnt0) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; right edge (setq pnt1 (list (+ (nth 0 pnt0) (* xtimes xyside)) (nth 1 pnt0) (nth 2 pnt0))) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) (princ) ) ;-------------------------------------------------------------------------- (defun prog07 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) ; draw rectangle (command ".RECTANGLE" pnt1 pnt2) ; center of square (setq pnt3 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) 0)) ; rotate (setq rotang (* (fix (* (rn) 4.99)) 45.0)) (command ".ROTATE" "last" "" pnt3 rotang) ; compute height (if (= (rem rotang 90) 0) (setq zheight zmin) (setq zheight zmax) ) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; base (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" zmin) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zmin "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- (defun prog08 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) (setq psides (getint "\nEnter number of polygon sides: ")) (setq prad (getdist "\nEnter polygon radius: ")) (setq pang (getreal "\nEnter rotation angle inc: ")) (setq anghght (getint "\nEnter height angle: ")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; center of square (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; draw polygon (command ".POLYGON" psides pnt2 "I" prad) ; rotate (setq rotang (* (fix (* (rn) 360)) pang)) (command ".ROTATE" "last" "" pnt2 rotang) ; compute height (if (= (rem rotang anghght) 0) (setq zheight zmin) (setq zheight zmax) ) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; base ; upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" zmin) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zmin "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- (defun prog09 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) (setq cradmin (getdist "\nEnter circle min radius: ")) (setq cradmax (getdist "\nEnter circle max radius: ")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; center of square (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; compute radius (setq crad (+ cradmin (* (rn) (- cradmax cradmin)))) ; draw circle (command ".CIRCLE" pnt2 crad) ; compute height (setq zheight (+ zmin (* (rn) (- zmax zmin)))) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; base ; upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" (/ zmin 2)) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" (/ zmin 2) "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- (defun prog10 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq cradmin (getdist "\nEnter circle min radius: ")) (setq cradmax (getdist "\nEnter circle max radius: ")) (setq xoffmax (getdist "\nEnter max X offset: ")) (setq yoffmax (getdist "\nEnter max Y offset: ")) (setq hlist (read (getstring "\nEnter height list:"))) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc 0)) ; center of square (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; X and Y offset (setq xoff (- (* (rn) xoffmax) (/ xoffmax 2))) (setq yoff (- (* (rn) yoffmax) (/ yoffmax 2))) (setq pnt3 (list (+ (nth 0 pnt2) xoff) (+ (nth 1 pnt2) yoff) (nth 2 pnt2))) ; compute radius (setq crad (+ cradmin (* (rn) (- cradmax cradmin)))) ; draw circle (command ".CIRCLE" pnt3 crad) ; compute height (setq n (fix (* (rn) (- (length hlist) 0.1)))) (setq zheight (nth n hlist)) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; base ; upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" (nth 0 hlist)) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" (nth 0 hlist) "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog11 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq cradmin (getdist "\nEnter circle min radius: ")) (setq cradmax (getdist "\nEnter circle max radius: ")) (setq xoffmax (getdist "\nEnter max X offset: ")) (setq yoffmax (getdist "\nEnter max Y offset: ")) (setq hlist (read (getstring "\nEnter height list:"))) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; lower corner pt (setq pnt1 (list xloc yloc (nth 2 pnt0))) ; center of square (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; X and Y offset (setq xoff (- (* (rn) xoffmax) (/ xoffmax 2))) (setq yoff (- (* (rn) yoffmax) (/ yoffmax 2))) (setq pnt3 (list (+ (nth 0 pnt2) xoff) (+ (nth 1 pnt2) yoff) (nth 2 pnt2))) ; compute radius (setq crad (+ cradmin (* (rn) (- cradmax cradmin)))) ; draw circle (command ".CIRCLE" pnt3 crad) ; compute height (setq n (fix (* (rn) (- (length hlist) 0.1)))) (setq zheight (nth n hlist)) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; base ; upper-right corner pt for rectangle (setq pnt2 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" (nth 0 hlist)) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" (nth 0 hlist) "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") ; trim edges ; center of boundary (setq pntc (list (+ (nth 0 pnt0) (* (/ xtimes 2.0) xyside)) (+ (nth 1 pnt0) (* (/ ytimes 2.0) xyside)) (nth 2 pnt0))) ; bottom edge (setq pnt1 pnt0) (setq pnt2 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; top edge (setq pnt1 (list (nth 0 pnt0) (+ (nth 1 pnt0) (* ytimes xyside)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; left edge (setq pnt1 pnt0) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; right edge (setq pnt1 (list (+ (nth 0 pnt0) (* xtimes xyside)) (nth 1 pnt0) (nth 2 pnt0))) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (command ".SLICE" "all" "" pnt1 pnt2 pntc) ; make negative (command ".COPY" "last" "" pnt0 pnt0) (setq obj1 (ssadd (entlast))) (setq pnt1 (list (- (nth 0 pnt0) 1) (- (nth 1 pnt0) 1) (nth 2 pnt0))) (setq pnt2 (list (+ (+ (nth 0 pnt0) (* xtimes xyside)) 1) (+ (+ (nth 1 pnt0) (* ytimes xyside)) 1) (nth 2 pnt0))) (command ".RECTANGLE" pnt1 pnt2) (command ".ZOOM" "e") (command ".EXTRUDE" "last" "" (+ (last hlist) 1)) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" (+ (last hlist) 1) "") (setq obj2 (ssadd (entlast))) ; subtract (command ".SUBTRACT" obj2 "" obj1 "") (command ".ROTATE3D" "last" "" "Y" pnt2 "180") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog12a () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) ; z inc (setq zinc (/ (- zmax zmin) 3.0)) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes (setq zheight zmin) ; first quad (setq pnt1 (list xloc yloc (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; draw rectangle (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to list (setq rlist (ssadd (entlast))) ; inc height (setq zheight (+ zheight zinc)) ; second quad (setq pnt1 (list (+ xloc (/ xyside 2)) yloc (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; draw rectangle (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to list (setq rlist (ssadd (entlast) rlist)) ; inc height (setq zheight (+ zheight zinc)) ; third quad (setq pnt1 (list (+ xloc (/ xyside 2)) (+ yloc (/ xyside 2)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; draw rectangle (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to list (setq rlist (ssadd (entlast) rlist)) ; inc height (setq zheight (+ zheight zinc)) ; fourth quad (setq pnt1 (list xloc (+ yloc (/ xyside 2)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; draw rectangle (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to list (setq rlist (ssadd (entlast) rlist)) ; rotate (setq pnt3 (list (+ xloc (/ xyside 2)) (+ yloc (/ xyside 2)) 0)) (setq rotang (* (fix (* (rn) 4.99)) 90.0)) (command ".ROTATE" rlist "" pnt3 rotang) ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog12h () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) ; z inc (setq zinc (/ (- zmax zmin) 2.0)) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes (setq zheight zmin) ; left trianlge (setq pnt1 (list xloc yloc (nth 2 pnt0))) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (setq pnt3 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) ; draw trianle (command ".PLINE" pnt1 pnt2 pnt3 pnt1 "") (command ".EXTRUDE" "last" "" zmin) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to list (setq rlist (ssadd (entlast))) ; inc height (setq zheight (+ zheight zinc)) ; right triangle (setq pnt4 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (setq pnt5 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) ; draw trianle (command ".PLINE" pnt3 pnt4 pnt5 pnt3 "") (command ".EXTRUDE" "last" "" zmin) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to list (setq rlist (ssadd (entlast) rlist)) ; inc height (setq zheight (+ zheight zinc)) ; middle triangle ; draw triangle (command ".PLINE" pnt1 pnt3 pnt5 pnt1 "") (command ".EXTRUDE" "last" "" zmax) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to list (setq rlist (ssadd (entlast) rlist)) ; rotate (setq pnt6 (list (+ xloc (/ xyside 2)) (+ yloc (/ xyside 2)) 0)) (setq rotang (* (fix (* (rn) 4.99)) 90.0)) (command ".ROTATE" rlist "" pnt6 rotang) ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog12j () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; corner and arc points and center (setq pnt1 (list xloc yloc (nth 2 pnt0))) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (setq pnt3 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (setq pnt4 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (setq pnt5 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) (setq pnt6 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) (setq pnt7 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (nth 2 pnt1))) ; upper right arc (command ".PLINE" pnt5 "a" "d" pnt7 pnt3 "l" pnt4 pnt5 "") (command ".EXTRUDE" "last" "" zmin) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zmin "") ; add to list (setq rlist (ssadd (entlast))) ; middle arc (command ".PLINE" pnt6 "a" "d" pnt1 pnt2 "l" pnt3 "a" "d" pnt7 pnt5 "l" pnt6 "") (command ".EXTRUDE" "last" "" zmax) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zmax "") ; add to list (setq rlist (ssadd (entlast) rlist)) ; inc height (setq zheight (+ zheight zinc)) ; lower left arc (command ".PLINE" pnt6 "a" "d" pnt1 pnt2 "l" pnt1 pnt6 "") (command ".EXTRUDE" "last" "" zmin) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zmin "") ; add to list (setq rlist (ssadd (entlast) rlist)) ; rotate (setq pnt8 (list (+ xloc (/ xyside 2)) (+ yloc (/ xyside 2)) 0)) (setq rotang (* (fix (* (rn) 4.99)) 90.0)) (command ".ROTATE" rlist "" pnt8 rotang) ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog12k () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zmin (getdist "\nEnter min Z height: ")) (setq zmax (getdist "\nEnter max Z height: ")) (setq rdim (getdist "\nEnter random dimension for edge: ")) ; start y location (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 0 pnt0)) (repeat xtimes ; random top edge (setq xtoff (+ (/ (- xyside rdim) 2) (* (rn) rdim))) ; random bottom edge (setq xboff (+ (/ (- xyside rdim) 2) (* (rn) rdim))) ; left segment (setq pnt1 (list xloc yloc (nth 2 pnt0))) (setq pnt2 (list (nth 0 pnt1) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (setq pnt3 (list (+ (nth 0 pnt1) xtoff) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (setq pnt4 (list (+ (nth 0 pnt1) xboff) (nth 1 pnt1) (nth 2 pnt1))) ; draw segment (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") (command ".EXTRUDE" "last" "" zmin) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zmin "") ; add to list (setq rlist (ssadd (entlast))) ; right segment (setq pnt5 (list (+ (nth 0 pnt1) xyside) (+ (nth 1 pnt1) xyside) (nth 2 pnt1))) (setq pnt6 (list (+ (nth 0 pnt1) xyside) (nth 1 pnt1) (nth 2 pnt1))) ; draw segment (command ".PLINE" pnt3 pnt5 pnt6 pnt4 pnt3 "") (command ".EXTRUDE" "last" "" zmax) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zmax "") ; add to list (setq rlist (ssadd (entlast) rlist)) ; rotate (setq pnt7 (list (+ xloc (/ xyside 2)) (+ yloc (/ xyside 2)) 0)) (setq rotang (* (fix (* (rn) 4.99)) 90.0)) (command ".ROTATE" rlist "" pnt7 rotang) ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; union (command ".UNION" "all" "") (princ) ) ;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------