;;; ;;;SIERPINSKI_GASKET.LSP---Template for fractal like Sierpinski Gasket ;;; by Takaya Iwamoto June 23, 2008 ;;; added cube_gasket ,tetra_gasket July 16,2008 ;;; ;;;Executables list ;;; 1. sierpinski_gasket ;;; 2. sierpinski_arrowhead ;;; 3. sierpinski_maze ;;; 4. square_gasket ;;; 5. square_gasket2 ;;; 6. cube_gasket ;;; 7. tetra_gasket ;;; ;;;***Basic main*********************************************************** ;;; ;;; temp_main (defun c:temp_main() ;;This will define parameters used in the program ;; Draw the first picture or reference lines ;; define windows range, ;; ;(setup_temp) ;;This is the main loop (while (= (Yes_or_No "Go to next step ?") "_Y") ;; This is the body of operation ;; (repeat_copy) );;;end of while loop (reset_sysvar) );;;temp_main ;;; ;;;*************************Sierpinski_gasket********************************* ;;; ;;; temp_main (defun c:sierpinski_gasket() ;;This will define parameters used in the program ;; Draw the first picture or reference lines ;; define windows range, ;; (setup_sier_gasket) (make_jpg) ;;This is the main loop (while (= (Yes_or_No "Go to next step ?") "_Y") ;; define a new block & block name (setq new_block (strcat "test_" (itoa step))) (command "_.block" new_block pnt_0 "all" "" ) ;; then erase the current image (command "_.erase" "all" "") ;; insert the new block at 3 positions pnt_0,1 & 2 (command "_.insert" new_block pnt_0 0.5 "" "") (command "_.insert" new_block pnt_1 0.5 "" "") (command "_.insert" new_block pnt_2 0.5 "" "") ;; increment the step ID (setq step (1+ step)) (make_jpg) );;;end of while loop (make_jpg) (make_jpg) (reset_sysvar) );;;temp_main ;;; ;;; (defun setup_sier_gasket() (setup_sysvar) (setq sqrt_3 (sqrt 3.) pnt_0 '(0 0) pnt_1 '(0.5 0) pnt_2 (list 0.25 (* 0.25 sqrt_3)) step 0 low_left '(-0.1 -0.1) up_right '(1.1 1.1) ) (command "_.zoom" "_W" low_left up_right) (make_trig_block "trig_base" 1.0) );;; ;;; ;;;MAKE_TRIG_BLOCK make a solid filled equi-lateral triangle ;;; trig_name block name to be defined ;;; base_len base length = 1.0 ;;; ;;; (defun make_trig_block (trig_name base_len / pnt_a pnt_b pnt_c height trig) (setq height (* 0.5 (sqrt 3.)) pnt_a '(0 0) pnt_b '(1 0) pnt_c (list 0.5 height) ) (command "_.pline" pnt_a pnt_b pnt_c "cl") (command "_.hatch" "_solid" (entlast) "") (setq trig (entlast)) (my_block_def trig_name '(0 0) trig) (command "oops") ) ;;; ;;;*************************sierpinski_arrowhead********************************* ;;; ;;; temp_main (defun c:sierpinski_arrowhead() ;;This will define parameters used in the program ;; Draw the first picture or reference lines ;; define windows range, ;; (setup_sier_arrowhead) (make_jpg) ;;This is the main loop (while (= (Yes_or_No "Go to next step ?") "_Y") ;; define a new block & block name (setq new_block1 (strcat "base_" (itoa step))) (command "_.block" new_block1 pnt_0 "all" "" ) (command "oops") ;redisplay the image (setq new_block2 (strcat "flip_" (itoa step))) ;; make a mirror image with respect to y=0 line (command "_.mirror" "all" "" pnt_0 pnt_3 "Y") (command "_.block" new_block2 pnt_0 "all" "" ) ;; then erase the current image (command "_.erase" "all" "") ;; insert the new block at 3 positions pnt_0,1 & 2 (command "_.insert" new_block2 pnt_0 0.5 "" 60. ) (command "_.insert" new_block1 pnt_1 0.5 "" 0. ) (command "_.insert" new_block2 pnt_2 0.5 "" -60.) ;; increment the step ID (setq step (1+ step)) (make_jpg) );;;end of while loop (make_jpg) (make_jpg) (reset_sysvar) );;;temp_main ;;; ;;; (defun setup_sier_arrowhead() (setup_sysvar) (setq sqrt_3 (sqrt 3.) pnt_0 '(0 0) pnt_1 (list 0.25 (* 0.25 sqrt_3)) pnt_2 (list 0.75 (* 0.25 sqrt_3)) pnt_3 '(1 0) step 0 low_left '(-0.1 -0.1) up_right '(1.1 1.1) ) (command "_.zoom" "_W" low_left up_right) (command "_.pline" pnt_0 pnt_1 pnt_2 pnt_3 "") );;; ;;; ;;; ;;;********************************************************************* ;;;*************************sierpinski_maze********************************* ;;; ;;; temp_main (defun c:sierpinski_maze() ;;This will define parameters used in the program ;; Draw the first picture or reference lines ;; define windows range, ;; (setup_sier_maze) (make_jpg) ;;This is the main loop (while (= (Yes_or_No "Go to next step ?") "_Y") ;; define a new block & block name (setq new_block1 (strcat "base_" (itoa step))) (command "_.block" new_block1 pnt_0 "all" "" ) (command "oops") ;redisplay the image (setq new_block2 (strcat "flip_" (itoa step))) ;; make a mirror image with respect to y=0 line (command "_.mirror" "all" "" pnt_0 pnt_4 "Y") (command "_.block" new_block2 pnt_0 "all" "" ) ;; then erase the current image (command "_.erase" "all" "") ;; insert the new block at 3 positions pnt_0,1 & 2 (command "_.insert" new_block2 pnt_0 0.5 "" 60. ) (command "_.insert" new_block1 pnt_1 0.5 "" 0. ) (command "_.insert" new_block2 pnt_3 0.5 "" -60.) ;; increment the step ID (setq step (1+ step)) (make_jpg) );;;end of while loop (make_jpg) (make_jpg) (reset_sysvar) );;;temp_main ;;; ;;; (defun setup_sier_maze() (setup_sysvar) (setq sqrt_3 (sqrt 3.) pnt_0 '(0 0) pnt_1 (list 0.25 (* 0.25 sqrt_3)) pnt_2 (list 0.50 (* 0.50 sqrt_3)) pnt_3 (list 0.75 (* 0.25 sqrt_3)) pnt_4 '(0.50 0) step 0 low_left '(-0.1 -0.1) up_right '(1.1 1.1) ) (command "_.zoom" "_W" low_left up_right) (command "_.pline" pnt_0 pnt_4 pnt_3 "") (command "_.line" pnt_1 pnt_2 "") );;; ;;; ;;; ;;;********************************************************************* ;;; ;;;*************************Square_gasket********************************* ;;; ;;; temp_main (defun c:square_gasket() ;;This will define parameters used in the program ;; Draw the first picture or reference lines ;; define windows range, ;; (setup_sqr_gasket) (make_jpg) ;;This is the main loop (while (= (Yes_or_No "Go to next step ?") "_Y") ;; define a new block & block name (setq new_block (strcat "test_" (itoa step))) (command "_.block" new_block pnt_0 "all" "" ) ;; then erase the current image (command "_.erase" "all" "") ;; insert the new block at 5 positions pnt_0,1,2,3,& 4 (command "_.insert" new_block pnt_0 one_third "" "") (command "_.insert" new_block pnt_1 one_third "" "") (command "_.insert" new_block pnt_2 one_third "" "") (command "_.insert" new_block pnt_3 one_third "" "") (command "_.insert" new_block pnt_4 one_third "" "") (make_jpg) ;; increment the step ID (setq step (1+ step)) );;;end of while loop (make_jpg) (make_jpg) (reset_sysvar) );;;temp_main ;;; ;;; (defun setup_sqr_gasket() (setup_sysvar) (setq one_third (/ 1. 3.) two_third (* 2 one_third) pnt_0 '(0 0) pnt_1 (list two_third 0) pnt_2 (list one_third one_third) pnt_3 (list 0 two_third) pnt_4 (list two_third two_third) step 0 low_left '(-0.01 -0.01) up_right '(1.01 1.01) ) (make_sqr_block "sqr_base" 1.0) (command "_.zoom" "_W" low_left up_right) );;; ;;; ;;; ;;;MAKE_SQUARE_BLOCK make a square ;;; square_name block name to be defined ;;; base_len base length ;;; ;;; (defun make_sqr_block (square_name base_len / pnt_a pnt_b pnt_c pnt_d square) (setq pnt_a '(0 0) pnt_b '(1 0) pnt_c '(1 1) pnt_d '(0 1) ) (command "_.pline" pnt_a pnt_b pnt_c pnt_d "cl") (command "_.hatch" "_solid" (entlast) "") (setq square (entlast)) (my_block_def square_name '(0 0) square) (command "oops") ) ;;; ;;;********************************************************************* ;;;*************************Square_gasket2********************************* ;;; ;;; temp_main (defun c:square_gasket2() ;;This will define parameters used in the program ;; Draw the first picture or reference lines ;; define windows range, ;; (setup_sqr_gasket2) (make_jpg) (make_dwg) ;;This is the main loop (while (= (Yes_or_No "Go to next step ?") "_Y") ;; define a new block & block name (setq new_block (strcat "test_" (itoa step))) (command "_.block" new_block pnt_0 "all" "" ) ;; then erase the current image (command "_.erase" "all" "") ;; insert the new block at 5 positions pnt_0,1,2,4,6,7,8,& 9 (command "_.insert" new_block pnt_0 one_third "" "") (command "_.insert" new_block pnt_1 one_third "" "") (command "_.insert" new_block pnt_2 one_third "" "") (command "_.insert" new_block pnt_4 one_third "" "") (command "_.insert" new_block pnt_6 one_third "" "") (command "_.insert" new_block pnt_7 one_third "" "") (command "_.insert" new_block pnt_8 one_third "" "") (command "_.insert" new_block pnt_9 one_third "" "") (make_jpg) (make_dwg) ;; increment the step ID (setq step (1+ step)) );;;end of while loop (make_jpg) (make_jpg) (reset_sysvar) );;;temp_main ;;; ;;; (defun setup_sqr_gasket2() (setup_sysvar) (setq one_third (/ 1. 3.) two_third (* 2 one_third) pnt_0 '(0 0) pnt_1 (list one_third 0) pnt_2 (list two_third 0) pnt_3 (list 1.0 0) pnt_4 (list 0 one_third) pnt_5 (list one_third one_third) pnt_6 (list two_third one_third) pnt_7 (list 0 two_third) pnt_8 (list one_third two_third) pnt_9 (list two_third two_third) pnt_ref '(0.2 0.2) step 0 low_left '(-0.01 -0.01) up_right '(1.01 1.01) ) (make_sqr_block2 "sqr_base2" 1.0) (command "_.zoom" "_W" low_left up_right) );;; ;;; ;;;MAKE_SQUARE_BLOCK2 make a square ;;; square_name block name to be defined ;;; base_len base length ;;; ;;; (defun make_sqr_block2 (square_name base_len / square) (command "_.polygon" 4 "E" pnt_0 pnt_3) (command "_.polygon" 4 "E" pnt_5 pnt_6) (command "_.bhatch" "P" "S" pnt_ref "") (setq square (entlast)) (my_block_def square_name '(0 0) square) (command "oops") ) ;;;************************************************************************************** ;;; ;;;*************************Cube_gasket********************************* ;;; ;;; main (defun c:cube_gasket() ;;This will define parameters used in the program ;; Draw the first picture or reference lines ;; define windows range, ;; (setup_cube_gasket) (make_jpg) (make_dwg) ;;This is the main loop (while (= (Yes_or_No "Go to next step ?") "_Y") ;; define a new block & block name (setq new_block (strcat "test_" (itoa step))) (command "_.block" new_block pnt_org "all" "" ) ;; then erase the current image (command "_.erase" "all" "") ;; insert the new block at 5 positions pnt_0,1,2,4,6,7,8,& 9 (command "_.insert" new_block pnt_00 one_third "" "") (command "_.insert" new_block pnt_01 one_third "" "") (command "_.insert" new_block pnt_02 one_third "" "") ;(command "_.insert" new_block pnt_03 one_third "" "") (command "_.insert" new_block pnt_04 one_third "" "") (command "_.insert" new_block pnt_05 one_third "" "") (command "_.insert" new_block pnt_10 one_third "" 90.) (command "_.insert" new_block pnt_11 one_third "" 90.) (command "_.insert" new_block pnt_12 one_third "" 90.) ;(command "_.insert" new_block pnt_13 one_third "" 90.) (command "_.insert" new_block pnt_14 one_third "" 90.) (command "_.insert" new_block pnt_15 one_third "" 90.) (command "_.insert" new_block pnt_20 one_third "" 180.) (command "_.insert" new_block pnt_21 one_third "" 180) (command "_.insert" new_block pnt_22 one_third "" 180) ;(command "_.insert" new_block pnt_23 one_third "" 180) (command "_.insert" new_block pnt_24 one_third "" 180) (command "_.insert" new_block pnt_25 one_third "" 180) (command "_.insert" new_block pnt_30 one_third "" -90) (command "_.insert" new_block pnt_31 one_third "" -90) (command "_.insert" new_block pnt_32 one_third "" -90) ;(command "_.insert" new_block pnt_33 one_third "" -90) (command "_.insert" new_block pnt_34 one_third "" -90) (command "_.insert" new_block pnt_35 one_third "" -90) (make_jpg) (make_dwg) ;; increment the step ID (setq step (1+ step)) );;;end of while loop (make_jpg) (make_jpg) (reset_sysvar) );;;temp_main ;;; ;;; (defun setup_cube_gasket() (setup_sysvar) (setq one_third (/ 1. 3.) two_third (* 2 one_third) view_dir '(-1.2204 0.8726 2.1731) pnt_org '(0 0 0) ;;y=0 plane pnt_00 (list 0 0 0 ) pnt_01 (list one_third 0 0 ) pnt_02 (list 0 0 one_third) pnt_03 (list two_third 0 one_third) pnt_04 (list 0 0 two_third) pnt_05 (list one_third 0 two_third) ;;x=1 plane pnt_10 (list 1 0 0) pnt_11 (list 1 one_third 0) pnt_12 (list 1 0 one_third) pnt_13 (list 1 two_third one_third) pnt_14 (list 1 0 two_third) pnt_15 (list 1 one_third two_third) ;;y=1 plane pnt_20 (list 1 1 0) pnt_21 (list two_third 1 0) pnt_22 (list 1 1 one_third) pnt_23 (list one_third 1 one_third) pnt_24 (list 1 1 two_third) pnt_25 (list two_third 1 two_third) ;;x=0 plane pnt_30 (list 0 1 0) pnt_31 (list 0 two_third 0) pnt_32 (list 0 1 one_third) pnt_33 (list 0 one_third one_third) pnt_34 (list 0 1 two_third) pnt_35 (list 0 two_third two_third) pnt_ref '(0.2 0.2) step 0 low_left '(-0.01 -0.01) up_right '(1.01 1.01) ) (command "_.vpoint" view_dir) (make_cube_block "cube_base" 1.0) (command "_.zoom" "E") );;; ;;; ;;;MAKE_CUBE_BLOCK make a unit cube ;;; cube_name block name to be defined ;;; base_len base length ;;; ;;; (defun make_cube_block (cube_name base_len / square) (command "_.box" pnt_org "cube" 1.) (setq unit_cube (entlast)) (my_block_def cube_name pnt_org unit_cube) (command "oops") ) ;;;************************************************************************************** ;;; '(-1.2204 0.8726 2.1731) ;;; ;;;*************************Tetra_gasket********************************* ;;; ;;; main (defun c:tetra_gasket() ;;This will define parameters used in the program ;; Draw the first picture or reference lines ;; define windows range, ;; (setup_tetra_gasket) (make_jpg) (make_dwg) ;;This is the main loop (while (= (Yes_or_No "Go to next step ?") "_Y") ;; define a new block & block name (setq new_block (strcat "test_" (itoa step))) (command "_.block" new_block pnt_org "all" "" ) ;; then erase the current image (command "_.erase" "all" "") ;; insert the new block at 4 positions pnt_00, 10, 20 & 4 (command "_.insert" new_block pnt_00 0.5 "" 0.) (command "_.insert" new_block pnt_10 0.5 "" 120.) (command "_.insert" new_block pnt_20 0.5 "" -120.) (command "_.insert" new_block pnt_4 0.5 "" 0.) (make_jpg) (make_dwg) ;; increment the step ID (setq step (1+ step)) );;;end of while loop (make_jpg) (make_jpg) (reset_sysvar) );;;temp_main ;;; ;;; (defun setup_tetra_gasket() (setup_sysvar) (setq sqrt_3 (sqrt 3.) one_third (/ 1. 3.) two_third (/ 2. 3.) one_sixth (/ 1. 6.) height (sqrt two_third) view_dir '(-1.3602 -0.9988 -0.2352) pnt_org '(0 0 0) pnt_00 (list 0 0 0) pnt_10 (list 1 0 0) pnt_20 (list 0.5 (* 0.5 sqrt_3) 0) pnt_3 (list 0.5 (* one_sixth sqrt_3) height) pnt_4 (list 0.25 0.144338 (* 0.5 height)) step 0 low_left '(-4.3171 -3.9091 0.0000) up_right '(0.6424 0.9833 0.0000) ) (command "_.vpoint" view_dir) (command "_.color" "3") (make_tetra_block "tetra_base" 1.0) (command "_.zoom" "_w" low_left up_right) );;; ;;; ;;;MAKE_Tetra_BLOCK make a unit cube ;;; cube_name block name to be defined ;;; base_len base length ;;; ;;; (defun make_tetra_block (tetra_name base_len / square) (command "_.3dface" pnt_00 pnt_10 pnt_20 "" "") (setq face1 (entlast)) (command "_.3dface" pnt_10 pnt_20 pnt_3 "" "") (setq face2 (entlast)) (command "_.3dface" pnt_00 pnt_10 pnt_3 "" "") (setq face3 (entlast)) (command "_.3dface" pnt_20 pnt_00 pnt_3 "" "") (setq face4 (entlast)) (command "_.block" tetra_name pnt_org face1 face2 face3 face4 "") (command "oops") ) ;;;************************************************************************************** ;;; '(-1.2204 0.8726 2.1731) ;;; ;;;