;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; ;;;; Copyright (c) Jan. 1997 by Takehiko Nagakura. ;;;; ;;;; All rights reserved. ;;;; ;;;; ;;;; ;;;; Do not copy, use, modify or distribute this software ;;;; ;;;; without written permission by Nagakura. Nagakura will ;;;; ;;;; not be responsible for any consequence of its use. ;;;; ;;;; ;;;; ;;;; Takehiko Nagakura (e-mail: takehiko@mit.edu) ;;;; ;;;; Massachusetts Institute of Technology ;;;; ;;;; 77 Massachusetts Ave. 10-472M, Cambridge, MA 02139 ;;;; ;;;; ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Last updated Jan 12, 1997 by TN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; This program illustrates different ways of making repetitive structures ; using AutoLISP commands, while, repeat, if, and, or. ; ; use of functions ; ; (c:demo) ; ; (loop1 num) ; (loop2 num) ; (loop3 x y radius num_bay xinc) ; (loop4 x y radius xinc yinc num_column num_row) ; ; The above functions use the following functions to generate ; two types of shapes. ; ; ( circle xpos ypos radius) ; ( pentagon xpos ypos radius) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; First, I set up 2 layers I need. ; This has to be processed only at once when this file is loaded. (command "layer" "new" "circle_layer" "color" "cyan" "circle_layer" "") (command "layer" "new" "pentagon_layer" "color" "yellow" "pentagon_layer" "") ; my debugging utility ; (defun c:rr () (load "test")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 2 simple shapes each on a colored layer (defun circle (xpos ypos radius) (command "layer" "set" "circle_layer" "") (command "circle" (list xpos ypos) radius) ) (defun pentagon (xpos ypos radius) (command "layer" "set" "pentagon_layer" "") (command "polygon" 5 (list xpos ypos) "I" (list xpos (+ ypos radius))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; a simple loop using REPEAT ; (defun loop1 ( num ) (setq x 0) (repeat num (circle x 0 1) (setq x (+ x 3)) (print x) ) ;end repeat ) ;(loop1 5) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; a simple loop using WHILE ; (defun loop2 ( num / count ) (setq count 0) (while (< count num) (setq x (* count 3)) (pentagon x 5 1) (setq count (+ count 1)) ) ; while ) ;(loop2 5) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; a simple conditional using IF ; (defun loop3 (x y radius num_bay xinc / count) (setq count 1) (while (<= count num_bay) (if (= 0 (rem count 2)) (circle x y radius) ; count is an even number (pentagon x y radius) ; count is an odd number ) ; close if (setq x (+ x xinc)) (setq count (+ count 1)) ) ; close while ) ; close defun ;(loop3 0 10 1 5 3) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; a simple 2-dimensional array ; (defun loop4 (x y radius xinc yinc num_row num_column / first_x) (setq first_x x) (repeat num_column (repeat num_row (pentagon x y radius) (setq x (+ x xinc)) ) ; num_row (setq y (+ y yinc)) (setq x first_x) ) ; num_column ) ; close defun ;(loop4 0 15 1 3 3 5 5) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; a demo (defun c:demo () (command "cmdecho" 0) (command "ucsicon" "off") (command "vpoint" (list 0 0 1)) (command "zoom" "window" (list -4 -4) (list 16 32)) (command "regen") (loop1 5) (loop2 5) (loop3 0 10 1 5 3) (loop4 0 15 1 3 3 5 5) (command "regen") (command "comdecho" 1) )