; The Codewriting Workbook ; Creating Computational Architecture in AutoLISP ; by Robert J. Krawczyk ; Princeton Architectural Press, 2008 ; -------------------------------------------------------------------------- ; CH06C.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:")) (setq cradmin (getdist "\nEnter min radius: ")) (setq cradmax (getdist "\nEnter max radius: ")) ; start y location (setq yloc (nth 0 pnt0)) (repeat ytimes ; start x location (setq xloc (nth 1 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) (command ".ZOOM" "e") ; convert to region (command ".REGION" "last" "") ; inc x location (setq xloc (+ xloc xyside)) ) ; inc y location (setq yloc (+ yloc xyside)) (command ".ZOOM" "e") ) ; surface to be perforated (setq xmax (* xyside xtimes)) (setq ymax (* xyside ytimes)) (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") ; convert to region (command ".REGION" "last" "") ; subtract openings (command ".SUBTRACT" "last" "" "all" "") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog02 () (graphscr) ; random sticks (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq xmin (getdist pnt0 "\nEnter X min rectangle:")) (setq xmax (getdist pnt0 "\nEnter X max rectangle:")) (setq ymin (getdist pnt0 "\nEnter Y min rectangle:")) (setq ymax (getdist pnt0 "\nEnter Y max rectangle:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (setq rotang (getreal "\nEnter rotation angle:")) (command ".ERASE" "all" "") ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random stick size, offset, and rotation (setq xrside (+ xmin (* (rn) (- xmax xmin)))) (setq yrside (+ ymin (* (rn) (- ymax ymin)))) (setq xoff (* (rn) xyoff)) (setq yoff (* (rn) xyoff)) (setq rang (* (rn) rotang)) ; center pt (setq pntc (list (+ (- xpos (/ xyoff 2)) xoff) (+ (- ypos (/ xyoff 2)) yoff) 0.0)) ; stick (setq pnt1 (list (- (nth 0 pntc) (/ xrside 2)) (- (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt2 (list (+ (nth 0 pntc) (/ xrside 2)) (- (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt3 (list (+ (nth 0 pntc) (/ xrside 2)) (+ (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt4 (list (- (nth 0 pntc) (/ xrside 2)) (+ (nth 1 pntc) (/ yrside 2)) 0.0)) (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") (command ".ZOOM" "e") (command ".REGION" "last" "") (command ".ROTATE" "last" "" pntc rang) ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") ; border (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- (defun prog02a () (graphscr) ; random sticks (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq xmin (getdist pnt0 "\nEnter X min rectangle:")) (setq xmax (getdist pnt0 "\nEnter X max rectangle:")) (setq ymin (getdist pnt0 "\nEnter Y min rectangle:")) (setq ymax (getdist pnt0 "\nEnter Y max rectangle:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (setq rotang (getreal "\nEnter rotation angle:")) (command ".ERASE" "all" "") ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random stick size, offset, and rotation (setq xrside (+ xmin (* (rn) (- xmax xmin)))) (setq yrside (+ ymin (* (rn) (- ymax ymin)))) (setq xoff (* (rn) xyoff)) (setq yoff (* (rn) xyoff)) (setq rang (* (rn) rotang)) ; center pt (setq pntc (list (+ (- xpos (/ xyoff 2)) xoff) (+ (- ypos (/ xyoff 2)) yoff) 0.0)) ; stick (setq pnt1 (list (- (nth 0 pntc) (/ xrside 2)) (- (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt2 (list (+ (nth 0 pntc) (/ xrside 2)) (- (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt3 (list (+ (nth 0 pntc) (/ xrside 2)) (+ (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt4 (list (- (nth 0 pntc) (/ xrside 2)) (+ (nth 1 pntc) (/ yrside 2)) 0.0)) (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") (command ".ZOOM" "e") (command ".REGION" "last" "") (command ".ROTATE" "last" "" pntc rang) ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- (defun prog02b () (graphscr) ; random sticks (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq xmin (getdist pnt0 "\nEnter X min rectangle:")) (setq xmax (getdist pnt0 "\nEnter X max rectangle:")) (setq ymin (getdist pnt0 "\nEnter Y min rectangle:")) (setq ymax (getdist pnt0 "\nEnter Y max rectangle:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (setq rotang (getreal "\nEnter rotation angle:")) (command ".ERASE" "all" "") ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random stick size, offset, and rotation (setq xrside (+ xmin (* (rn) (- xmax xmin)))) (setq yrside (+ ymin (* (rn) (- ymax ymin)))) (setq xoff (* (rn) xyoff)) (setq yoff (* (rn) xyoff)) (setq rang (* (rn) rotang)) ; center pt (setq pntc (list (+ (- xpos (/ xyoff 2)) xoff) (+ (- ypos (/ xyoff 2)) yoff) 0.0)) ; stick (setq pnt1 (list (- (nth 0 pntc) (/ xrside 2)) (- (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt2 (list (+ (nth 0 pntc) (/ xrside 2)) (- (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt3 (list (+ (nth 0 pntc) (/ xrside 2)) (+ (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt4 (list (- (nth 0 pntc) (/ xrside 2)) (+ (nth 1 pntc) (/ yrside 2)) 0.0)) (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") (command ".ZOOM" "e") (command ".REGION" "last" "") (command ".ROTATE" "last" "" pntc rang) ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (setq obj1 (ssadd (entlast))) ; make frame at border ; inside border (setq pnt1 (list xmax ymax)) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) 1) (- (nth 1 pnt0) 1))) (setq pnt3 (list (+ (nth 0 pnt1) 1) (+ (nth 1 pnt1) 1))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make frame (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; add to panel (command ".UNION" "all" "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- (defun prog02c () (graphscr) ; random sticks (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq xmin (getdist pnt0 "\nEnter X min rectangle:")) (setq xmax (getdist pnt0 "\nEnter X max rectangle:")) (setq ymin (getdist pnt0 "\nEnter Y min rectangle:")) (setq ymax (getdist pnt0 "\nEnter Y max rectangle:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (setq rotang (getreal "\nEnter rotation angle:")) (command ".ERASE" "all" "") ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random stick size, offset, and rotation (setq xrside (+ xmin (* (rn) (- xmax xmin)))) (setq yrside (+ ymin (* (rn) (- ymax ymin)))) (setq xoff (* (rn) xyoff)) (setq yoff (* (rn) xyoff)) (setq rang (* (rn) rotang)) ; center pt (setq pntc (list (+ (- xpos (/ xyoff 2)) xoff) (+ (- ypos (/ xyoff 2)) yoff) 0.0)) ; stick (setq pnt1 (list (- (nth 0 pntc) (/ xrside 2)) (- (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt2 (list (+ (nth 0 pntc) (/ xrside 2)) (- (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt3 (list (+ (nth 0 pntc) (/ xrside 2)) (+ (nth 1 pntc) (/ yrside 2)) 0.0)) (setq pnt4 (list (- (nth 0 pntc) (/ xrside 2)) (+ (nth 1 pntc) (/ yrside 2)) 0.0)) (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") (command ".ZOOM" "e") (command ".REGION" "last" "") (command ".ROTATE" "last" "" pntc rang) ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") ; make frame at border ; inside border (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) 1) (- (nth 1 pnt0) 1))) (setq pnt3 (list (+ (nth 0 pnt1) 1) (+ (nth 1 pnt1) 1))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make frame (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; add to panel (command ".UNION" "all" "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- (defun prog03 () (graphscr) ; ring relief 2D version (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq romin (getdist pnt0 "\nEnter ring radius outside min:")) (setq romax (getdist pnt0 "\nEnter ring radius outside max:")) (setq rsmin (getdist pnt0 "\nEnter ring size min:")) (setq rsmax (getdist pnt0 "\nEnter ring size max:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (command ".ERASE" "all" "") ; rectangles panels ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random ring size and offset (setq rorad (+ romin (* (rn) (- romax romin)))) (setq risize (+ rsmin (* (rn) (- rsmax rsmin)))) (setq xoff (* (rn) xyoff)) (setq yoff (* (rn) xyoff)) ; center pt (setq pntc (list (+ (- xpos (/ xyoff 2)) xoff) (+ (- ypos (/ xyoff 2)) yoff) 0.0)) ; make ring (command ".CIRCLE" pntc rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".CIRCLE" pntc (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- (defun prog03a () (graphscr) ; ring relief 2D version (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq romin (getdist pnt0 "\nEnter ring radius outside min:")) (setq romax (getdist pnt0 "\nEnter ring radius outside max:")) (setq rsmin (getdist pnt0 "\nEnter ring size min:")) (setq rsmax (getdist pnt0 "\nEnter ring size max:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (command ".ERASE" "all" "") ;panel size (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random ring size and offset (setq rorad (+ romin (* (rn) (- romax romin)))) (setq risize (+ rsmin (* (rn) (- rsmax rsmin)))) ; center of panel (setq cpt (list (+ (nth 0 pnt0) (/ xmax 2.0)) (+ (nth 1 pnt0) (/ ymax 2.0)) (nth 2 pnt0))) ; center pt (setq pntc (list xpos ypos (nth 2 pnt0))) ; distance to center determines amount of offset (setq xdist (abs (- (nth 0 pntc) (nth 0 cpt)))) (setq ydist (abs (- (nth 1 pntc) (nth 1 cpt)))) (setq xprct (- 1.0 (/ xdist (/ (- xmax xside) 2.0)))) (setq yprct (- 1.0 (/ ydist (/ (- ymax yside) 2.0)))) (setq xoff (* (rn) (* xprct xyoff))) (setq yoff (* (rn) (* yprct xyoff))) ; redefine center pt (setq pntc (list (+ (- xpos (/ (* xyoff xprct) 2)) xoff) (+ (- ypos (/ (* xyoff yprct) 2)) yoff) (nth 2 pnt0))) ; make ring (command ".CIRCLE" pntc rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".CIRCLE" pntc (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- (defun prog03b () (graphscr) ; ring relief 2D version (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq romin (getdist pnt0 "\nEnter ring radius outside min:")) (setq romax (getdist pnt0 "\nEnter ring radius outside max:")) (setq rsmin (getdist pnt0 "\nEnter ring size min:")) (setq rsmax (getdist pnt0 "\nEnter ring size max:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (setq dfact (getreal "\nEnter distance factor:")) (command ".ERASE" "all" "") ;panel size (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random ring size and offset (setq rorad (+ romin (* (rn) (- romax romin)))) (setq risize (+ rsmin (* (rn) (- rsmax rsmin)))) ; center of panel (setq cpt (list (+ (nth 0 pnt0) (/ xmax 2.0)) (+ (nth 1 pnt0) (/ ymax 2.0)) (nth 2 pnt0))) ; center pt (setq pntc (list xpos ypos (nth 2 pnt0))) ; distance to center determines amount of offset (setq xdist (abs (- (nth 0 pntc) (nth 0 cpt)))) (setq ydist (abs (- (nth 1 pntc) (nth 1 cpt)))) (setq xprct (- 1.0 (/ xdist (/ (- xmax xside) 2.0)))) (setq yprct (- 1.0 (/ ydist (/ (- ymax yside) 2.0)))) (setq xoff (* (rn) (* xprct xyoff))) (setq yoff (* (rn) (* yprct xyoff))) ; redefine center pt (if (and (>= xprct dfact) (>= yprct dfact)) (setq pntc (list (+ (- xpos (/ (* xyoff xprct) 2)) xoff) (+ (- ypos (/ (* xyoff yprct) 2)) yoff) (nth 2 pnt0))) ) ; make ring (command ".CIRCLE" pntc rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".CIRCLE" pntc (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- (defun prog03c () (graphscr) ; ring relief 2D version (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq romin (getdist pnt0 "\nEnter ring radius outside min:")) (setq romax (getdist pnt0 "\nEnter ring radius outside max:")) (setq rsmin (getdist pnt0 "\nEnter ring size min:")) (setq rsmax (getdist pnt0 "\nEnter ring size max:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (setq dfact (getreal "\nEnter distance factor:")) (command ".ERASE" "all" "") ;panel size (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random ring size and offset (setq rorad (+ romin (* (rn) (- romax romin)))) (setq risize (+ rsmin (* (rn) (- rsmax rsmin)))) ; right edge of panel (setq cpt (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) (/ ymax 2.0)) (nth 2 pnt0))) ; center pt (setq pntc (list xpos ypos (nth 2 pnt0))) ; distance to center determines amount of offset (setq xdist (abs (- (nth 0 pntc) (nth 0 cpt)))) (setq xprct (- 1.0 (/ xdist (- xmax xside)))) (setq xoff (* (rn) (* xprct xyoff))) (setq yoff (* (rn) (* xprct xyoff))) ; redefine center pt (if (>= xprct dfact) (setq pntc (list (+ (- xpos (/ (* xyoff xprct) 2)) xoff) (+ (- ypos (/ (* xyoff xprct) 2)) yoff) (nth 2 pnt0))) ) ; make ring (command ".CIRCLE" pntc rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".CIRCLE" pntc (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog04 () (graphscr) ; random sticks (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq nsides (getint "\nEnter number of sides for polygon:")) (setq romin (getdist pnt0 "\nEnter ring radius outside min:")) (setq romax (getdist pnt0 "\nEnter ring radius outside max:")) (setq rsmin (getdist pnt0 "\nEnter ring size min:")) (setq rsmax (getdist pnt0 "\nEnter ring size max:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (setq rotang (getreal "\nEnter rotation angle:")) (command ".ERASE" "all" "") ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random polygon size, offset, and rotation (setq rorad (+ romin (* (rn) (- romax romin)))) (setq risize (+ rsmin (* (rn) (- rsmax rsmin)))) (setq xoff (* (rn) xyoff)) (setq yoff (* (rn) xyoff)) (setq rang (* (fix (* (rn) 360)) rotang)) ; center pt (setq pntc (list (+ (- xpos (/ xyoff 2)) xoff) (+ (- ypos (/ xyoff 2)) yoff) 0.0)) ; make ring (command ".POLYGON" nsides pntc "C" rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".POLYGON" nsides pntc "C" (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") (command ".ROTATE" "last" "" pntc rang) ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (setq obj1 (ssadd (entlast))) ; make frame at border ; inside border (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) 1) (- (nth 1 pnt0) 1))) (setq pnt3 (list (+ (nth 0 pnt1) 1) (+ (nth 1 pnt1) 1))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make frame (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; add to panel (command ".UNION" "all" "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- (defun dotrim () ; inside border (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog05 () (graphscr) ; ring relief 2D version (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq romin (getdist pnt0 "\nEnter ring radius outside min:")) (setq romax (getdist pnt0 "\nEnter ring radius outside max:")) (setq rsmin (getdist pnt0 "\nEnter ring size min:")) (setq rsmax (getdist pnt0 "\nEnter ring size max:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (setq nlayers (getint "\nEnter number of layers, 1 to 4:")) (command ".ERASE" "all" "") ; selection lists ;(setq layer01 (ssadd) layer02 (ssadd) layer03 (ssadd) layer04 (ssadd)) (setq layer01 (ssadd)) (setq layer02 (ssadd)) (setq layer03 (ssadd)) (setq layer04 (ssadd)) ; panel dims (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random ring size and offset (setq rorad (+ romin (* (rn) (- romax romin)))) (setq risize (+ rsmin (* (rn) (- rsmax rsmin)))) (setq xoff (* (rn) xyoff)) (setq yoff (* (rn) xyoff)) (setq nlayer (+ (fix (* (rn) (- nlayers 0.1))) 1)) ; center pt (setq pntc (list (+ (- xpos (/ xyoff 2)) xoff) (+ (- ypos (/ xyoff 2)) yoff) 0.0)) ; make ring (command ".CIRCLE" pntc rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".CIRCLE" pntc (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") (setq layer01 (ssadd (entlast) layer01)) (if (>= nlayer 2) (progn (command ".COPY" "last" "" pntc pntc ) (setq layer02 (ssadd (entlast) layer02)) )) (if (>= nlayer 3) (progn (command ".COPY" "last" "" pntc pntc ) (setq layer03 (ssadd (entlast) layer03)) )) (if (>= nlayer 4) (progn (command ".COPY" "last" "" pntc pntc ) (setq layer04 (ssadd (entlast) layer04)) )) ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union and trim each layer (command ".ZOOM" "e") (setq obj1 layer01) (dotrim) (setq layers (ssadd (entlast))) (if (> nlayers 1) (progn (setq obj1 layer02) (dotrim) (setq layers (ssadd (entlast) layers)) )) (if (> nlayers 2) (progn (setq obj1 layer03) (dotrim) )) (if (> nlayers 3) (progn (setq obj1 layer04) (dotrim) )) ; separate layers (setq layers (ssget "a")) (setq cnt 0) (repeat (sslength layers) (setq obj (ssname layers cnt)) (setq pnt1 (list (- (nth 0 pnt0) (* (+ xmax xside) (+ cnt 1))) (nth 1 pnt0) (nth 2 pnt0))) (command ".MOVE" obj "" pnt0 pnt1) (command ".ZOOM" "e") (setq cnt (+ cnt 1)) ) (princ) ) ;-------------------------------------------------------------------------- (defun prog06 () (graphscr) ; ring relief 2D version (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq romin (getdist pnt0 "\nEnter ring radius outside min:")) (setq romax (getdist pnt0 "\nEnter ring radius outside max:")) (setq rsmin (getdist pnt0 "\nEnter ring size min:")) (setq rsmax (getdist pnt0 "\nEnter ring size max:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (command ".ERASE" "all" "") ;panel size (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random ring size and offset (setq rorad (+ romin (* (rn) (- romax romin)))) (setq risize (+ rsmin (* (rn) (- rsmax rsmin)))) (setq xoff (* (rn) xyoff)) (setq yoff (* (rn) xyoff)) ; center pt (setq pntc (list (+ (- xpos (/ xyoff 2)) xoff) (+ (- ypos (/ xyoff 2)) yoff) 0.0)) ; select type of ring (setq rtype (+ (fix (* (rn) 4.99)) 1)) (if (= rtype 1) (progn (command ".CIRCLE" pntc rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".CIRCLE" pntc (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") )) (if (= rtype 2) (progn (command ".POLYGON" "3" pntc "C" rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".POLYGON" "3" pntc "C" (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") )) (if (= rtype 3) (progn (command ".POLYGON" "4" pntc "C" rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".POLYGON" "4" pntc "C" (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") )) (if (= rtype 4) (progn (command ".POLYGON" "5" pntc "C" rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".POLYGON" "5" pntc "C" (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") )) (if (= rtype 5) (progn (command ".POLYGON" "6" pntc "C" rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".POLYGON" "6" pntc "C" (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") )) ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog06a () (graphscr) ; ring relief 2D version (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq romin (getdist pnt0 "\nEnter ring radius outside min:")) (setq romax (getdist pnt0 "\nEnter ring radius outside max:")) (setq rsmin (getdist pnt0 "\nEnter ring size min:")) (setq rsmax (getdist pnt0 "\nEnter ring size max:")) (setq xyoff (getdist pnt0 "\nEnter XY offset:")) (setq plist (read (getstring "\nEnter random list of selections:"))) (command ".ERASE" "all" "") ;panel size (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random ring size and offset (setq rorad (+ romin (* (rn) (- romax romin)))) (setq risize (+ rsmin (* (rn) (- rsmax rsmin)))) (setq xoff (* (rn) xyoff)) (setq yoff (* (rn) xyoff)) ; center pt (setq pntc (list (+ (- xpos (/ xyoff 2)) xoff) (+ (- ypos (/ xyoff 2)) yoff) 0.0)) ; select type of ring (setq nlist (fix (* (rn) (- (length plist) 0.1)))) (setq rtype (nth nlist plist)) (if (= rtype 1) (progn (command ".CIRCLE" pntc rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".CIRCLE" pntc (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") )) (if (= rtype 2) (progn (command ".POLYGON" "3" pntc "C" rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".POLYGON" "3" pntc "C" (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") )) (if (= rtype 3) (progn (command ".POLYGON" "4" pntc "C" rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".POLYGON" "4" pntc "C" (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") )) (if (= rtype 4) (progn (command ".POLYGON" "5" pntc "C" rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".POLYGON" "5" pntc "C" (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") )) (if (= rtype 5) (progn (command ".POLYGON" "6" pntc "C" rorad) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj1 (ssadd (entlast))) (command ".POLYGON" "6" pntc "C" (- rorad risize)) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) (command ".SUBTRACT" obj1 "" obj2 "") )) ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog06b () (graphscr) ; ring relief 2D version (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq blist (read (getstring "\nEnter random list of selections:"))) (command ".ERASE" "all" "") ;panel size (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) ; start y location (setq ypos (+ (nth 1 pnt0) (/ yside 2))) (repeat ytimes ; start x location (setq xpos (+ (nth 0 pnt0) (/ xside 2))) (repeat xtimes ; random rotation (setq rang (* (fix (* (rn) 3.99)) 90)) ; center pt (setq pntc (list xpos ypos (nth 2 pnt0))) ; select type of ring (setq nlist (fix (* (rn) (- (length blist) 0.1)))) (setq nblock (nth nlist blist)) ; get block (command ".INSERT" nblock "s" xside pntc rang) (command ".ZOOM" "e") (command ".EXPLODE" "last") ; inc x (setq xpos (+ xpos xside)) ) ; inc y (setq ypos (+ ypos yside)) ) ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------- (defun prog07 () (graphscr) ; packed circles ; random circle size (setq pnt0 (list 0 0 0)) (setq xside (getdist pnt0 "\nEnter X side panel:")) (setq yside (getdist pnt0 "\nEnter Y side panel:")) (setq xtimes (getint "\nEnter number of X panels:")) (setq ytimes (getint "\nEnter number of Y panels:")) (setq rmin (getdist pnt0 "\nEnter min radius:")) (setq rmax (getdist pnt0 "\nEnter max radius:")) ; count number of failures to stop at (setq nfails 2000) ; count of circles drawn (setq ncircles 0) ; list of placed circles (setq clist (list )) ; panel (setq xmax (* xside xtimes)) (setq ymax (* yside ytimes)) (command ".RECTANGLE" pnt0 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".ZOOM" "e") ; packed circles (setq ido 1) (while (= ido 1) ; random circle size and location (setq rad (+ rmin (* (rn) (- rmax rmin)))) (setq xpos (* (rn) xmax)) (setq ypos (* (rn) ymax)) ; center pt (setq pntc (list (+ (nth 0 pnt0) xpos) (+ (nth 1 pnt0) ypos) (nth 2 pnt0))) ; check prevision locations (setq idraw 1) (if (> ncircles 0) (progn (setq ic 0) (repeat ncircles (setq pntp (nth 0 (nth ic clist))) (setq radp (nth 1 (nth ic clist))) (setq cdist (distance pntp pntc)) ; spacing of 10 percent (if (< (- cdist (* rmin 1.10)) (+ rad radp)) (progn (setq idraw 0) )) (setq ic (+ ic 1)) ) )) ; failed (if (= idraw 0) (progn (setq ifail (+ ifail 1)) (princ "\nFailed=") (princ ifail) )) ; draw circle (if (= idraw 1) (progn (command ".CIRCLE" pntc rad) (command ".REGION" "last" "") ; add to list: location and radius (setq clist (append (list (list pntc rad)) clist)) (setq ncircles (+ ncircles 1)) (setq ifail 0) )) ; check if to stop (if (> ifail nfails) (setq ido 0)) ) (command ".ZOOM" "e") ; union regions (command ".UNION" "all" "") (setq obj1 (ssadd (entlast))) ; inside border (setq pnt1 (list (+ (nth 0 pnt0) xmax) (+ (nth 1 pnt0) ymax))) (command ".RECTANGLE" pnt0 pnt1) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj2 (ssadd (entlast))) ; outside border (setq pnt2 (list (- (nth 0 pnt0) xmax) (- (nth 1 pnt0) ymax))) (setq pnt3 (list (+ (nth 0 pnt1) xmax) (+ (nth 1 pnt1) ymax))) (command ".RECTANGLE" pnt2 pnt3) (command ".ZOOM" "e") (command ".REGION" "last" "") (setq obj3 (ssadd (entlast))) ; make border (command ".SUBTRACT" obj3 "" obj2 "") (setq obj2 (ssadd (entlast))) ; subtract border from panel (command ".SUBTRACT" obj1 "" obj2 "") (command ".ZOOM" "e") (princ) ) ;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------