;;; ;;; ;;;HILBERT4.LSP ;;; ;;; July 01,2003 Takaya Iwamoto ;Hilbert's Space-Filling Curve ;Modified pattern ---called Leitmotiv ; semi-circle case ;Basic algorithm is the same as Hilbert.lsp ;The only difference is MAKE_ALL_BLOCKS function ;directions indices ; 0---up ; 1---right ; 2---down ; 3---left ;starting configuration ;(80 21 32 90) ;;; ;;;Hilbert main ;;; (defun c:hilbert4() (setup_hilbert) ;;parse the box_list and pnt_list (while (= (Yes_or_No "Go to next step ?") "_Y") (setq c_pos 0) ;;;c_pos current position index (setq t_plist nil t_blist nil t_elist nil ) (princ "\nlist_size =")(princ list_size)(princ "; box_scale = ")(princ box_scale)(terpri) ;;;inner loop (repeat list_size (setq box_id (nth c_pos box_list ) box_pt (nth c_pos pnt_list ) ent_id (nth c_pos ent_list ) ) ;;;call pattern to replace the current box by 4 boxes (hilbert_pattern) (setq c_pos (1+ c_pos)) ) (alert "\nErase the previous pattern") (erase_elist) ;;;copy t_plist,t_blist,t_elist to pnt_list,box_list & ent_list (setq pnt_list t_plist box_list t_blist ent_list t_elist list_size (* list_size 4) box_scale (* box_scale 0.5) ) );;;end of while loop (reset_sysvar) );;;HILBERT ;;; ;;; ;;;setup_hilbert ;;; (defun setup_hilbert() (setup_sysvar) (setvar "PDMODE" 32) (setq pnt_1 '(-0.25 -0.25) pnt_2 '(-0.25 0.25) pnt_3 '(0.25 0.25) pnt_4 '(0.25 -0.25) pnt_5 '(0 -0.5) pnt_6 '(0 0.5) pnt_7 '(-0.5 0) pnt_8 '(0.5 0) pnt_01 '(-0.5 -0.5) pnt_02 '(0.5 -0.5) pnt_03 '(0.5 0.5) pnt_04 '(-0.5 0.5) pnt_list (list pnt_1 pnt_2 pnt_3 pnt_4) box_list (list 14 12 12 32) lower_left '(-0.5 -0.5) upper_right '(0.5 0.5) list_size 4 box_scale 0.5 pnt_51 '(-0.25 -0.5) pnt_52 '(0.25 -0.5) pnt_ctr '(0 0) ) (command "_.zoom" "W" lower_left upper_right) ;;;make an entity list ent_list (command "_.pline" pnt_01 "Arc" "Se" pnt_1 pnt_7 "") (setq ent_1 (entlast)) (command "_.pline" pnt_7 "Arc" "Se" pnt_2 pnt_ctr "") (setq ent_2 (entlast)) (command "_.pline" pnt_ctr "Arc" "Se" pnt_3 pnt_8 "") (setq ent_3 (entlast)) (command "_.pline" pnt_8 "Arc" "Se" pnt_4 pnt_02 "") (setq ent_4 (entlast)) (setq ent_list (list ent_1 ent_2 ent_3 ent_4)) ;;;make all the basic patterns as block entities (make_all_blocks) );;;SETUP_HILBERT ;;; ;;;HILBERT_PATTERN ;;; (defun hilbert_pattern() (if (= box_id 12) (pattern "block_12" box_list_12 pnt_list_12)) (if (= box_id 14) (pattern "block_14" box_list_14 pnt_list_14)) (if (= box_id 21) (pattern "block_21" box_list_21 pnt_list_21)) (if (= box_id 23) (pattern "block_23" box_list_23 pnt_list_23)) (if (= box_id 32) (pattern "block_32" box_list_32 pnt_list_32)) (if (= box_id 34) (pattern "block_34" box_list_34 pnt_list_34)) (if (= box_id 41) (pattern "block_41" box_list_41 pnt_list_41)) (if (= box_id 43) (pattern "block_43" box_list_43 pnt_list_43)) );;;HILBERT_PATTERN There are 12 patterns plus 4(end & start) ;;; ;;;Pattern ;;;;PATTERN_ 12,14 21,23, 32,34 ,41,43 ;;; (defun pattern( blk_name boxlist pntlist) ;;;insert the given block_name at box_pnt, with scale box_scale (my_block_insert blk_name box_pt box_scale) (setq new_ent_id (entlast) t_elist (append t_elist (list new_ent_id)) ) ;;;add boxlist to temp box list t_blist (setq t_blist (append t_blist boxlist)) ;;;convert pntlist to global data,then add to temp_plist (setq npos 0 newplist nil) (repeat 4 (setq pnt_data (nth npos pntlist) x (car pnt_data) y (cadr pnt_data) x_box (car box_pt) y_box (cadr box_pt) new_x (+ (* x box_scale) x_box) new_y (+ (* y box_scale) y_box) newpnt (list new_x new_y) newplist (append newplist (list newpnt)) npos (1+ npos) ) );end of repeat loop ;;;then add newplist to t_plist (setq t_plist (append t_plist newplist)) );;;PATTERN ;;;MAKE_ALL_BLOCKS ;;;make block_12,21,,31,23,32, ;;; (defun make_all_blocks() (setq pnt_list_12 (list pnt_1 pnt_2 pnt_3 pnt_4) box_list_12 (list 14 12 12 32) pnt_list_14 (list pnt_1 pnt_4 pnt_3 pnt_2) box_list_14 (list 12 14 14 34) pnt_list_21 (list pnt_4 pnt_3 pnt_2 pnt_1) box_list_21 (list 23 21 21 41) pnt_list_23 (list pnt_4 pnt_1 pnt_2 pnt_3) box_list_23 (list 21 23 23 43) pnt_list_32 (list pnt_3 pnt_2 pnt_1 pnt_4) box_list_32 (list 34 32 32 12) pnt_list_34 (list pnt_3 pnt_4 pnt_1 pnt_2) box_list_34 (list 32 34 34 14) pnt_list_41 (list pnt_2 pnt_3 pnt_4 pnt_1) box_list_41 (list 43 41 41 21) pnt_list_43 (list pnt_2 pnt_1 pnt_4 pnt_3); box_list_43 (list 41 43 43 23) ) (command "_.pline" pnt_01 "Arc" "Se" pnt_1 pnt_7 "Se" pnt_2 pnt_ctr "Se" pnt_3 pnt_8 "Se" pnt_4 pnt_02 "") (my_block_def "block_12" pnt_ctr (entlast)) (command "_.pline" pnt_01 "Arc" "Se" pnt_1 pnt_5 "Se" pnt_4 pnt_ctr "Se" pnt_3 pnt_6 "Se" pnt_2 pnt_04 "") (my_block_def "block_14" pnt_ctr (entlast)) (command "_.pline" pnt_02 "Arc" "Se" pnt_4 pnt_8 "Se" pnt_3 pnt_ctr "Se" pnt_2 pnt_7 "Se" pnt_1 pnt_01 "") (my_block_def "block_21" pnt_ctr (entlast)) (command "_.pline" pnt_02 "Arc" "Se" pnt_4 pnt_5 "Se" pnt_1 pnt_ctr "Se" pnt_2 pnt_6 "Se" pnt_3 pnt_03 "") (my_block_def "block_23" pnt_ctr (entlast)) (command "_.pline" pnt_03 "Arc" "Se" pnt_3 pnt_6 "Se" pnt_2 pnt_ctr "Se" pnt_1 pnt_5 "Se" pnt_4 pnt_02 "") (my_block_def "block_32" pnt_ctr (entlast)) (command "_.pline" pnt_03 "Arc" "Se" pnt_3 pnt_8 "Se" pnt_4 pnt_ctr "Se" pnt_1 pnt_7 "Se" pnt_2 pnt_04 "") (my_block_def "block_34" pnt_ctr (entlast)) (command "_.pline" pnt_04 "Arc" "Se" pnt_2 pnt_6 "Se" pnt_3 pnt_ctr "Se" pnt_4 pnt_5 "Se" pnt_1 pnt_01 "") (my_block_def "block_41" pnt_ctr (entlast)) (command "_.pline" pnt_04 "Arc" "Se" pnt_2 pnt_7 "Se" pnt_1 pnt_ctr "Se" pnt_4 pnt_8 "Se" pnt_3 pnt_03 "") (my_block_def "block_43" pnt_ctr (entlast)) );;;MAKE_ALL_BLOCKs ;;; ;;; ;;;Erase all the entity in ent_list ;;; (defun erase_elist( / e_pos t_ent) (setq e_pos 0) (while (setq t_ent (nth e_pos ent_list)) (entdel t_ent) (setq e_pos (1+ e_pos)) );;;end of while loop );;;ERASE_ELIST