;;;Snowflake ;;;SNOWFLAKE.LSP ;;; ;;; ;;; Originally created by Takaya Iwamoto, March 15, 1997 ;;; updated by Takaya Iwamoto, May 5, 2003 ;;; koch_1 Creates snowflake pattern ;;; koch_2 Creates Anti-snowflake pattern ;;; There are 4 ways to make snowflake pattern ;;; snowflake_block using block definition---faster. but the same color ;;; snowflake_lineset each step is displayed in different color ;;; fract_1_int interactively--first draw an equilateral triangle ;;; fract_2_int "" Anti-snowflake ;;; ;;;*************************************************************** ;;; Snowflake_main ;;;*************************************************************** ;;; (defun c:Snowflake_main() (setq dcl_id (load_dialog "snowflake.dcl")) (if (not (new_dialog "snowflake" dcl_id)) (exit) ) (setq tile_list '("koch_1" "koch_2" "lineset" "blockset" "A1" "A2" "A3" "A4" "A5" "A6") ) (foreach sld_name tile_list (start_image sld_name) (slide_image 0 0 (- (dimx_tile sld_name) 1) (- (dimy_tile sld_name) 1) (strcat "snowflake" "(" sld_name ")") ) (end_image) );;;end of foreach loop (setq sel_key "koch_2") (mode_tile sel_key 4) (foreach pd0 tile_list (action_tile pd0 "(mode_tile sel_key 4) (setq sel_key $key)(mode_tile sel_key 4)" ) ) ;(action_tile "help" "(help \"\" \"ddptype\")") ;;help index (start_dialog) ;;;execute the selected program (cond ((= sel_key "koch_1") (c:koch_1) ) ((= sel_key "koch_2") (c:koch_2) ) ((= sel_key "lineset") (c:snowflake_lineset) ) ((= sel_key "blockset") (c:snowflake_block) ) (t nil) );;;end of cond (princ "sel_key")(terpri)(princ sel_key) );;;SNOWFLAKE_MAIN ;;; ;;; (defun c:snowflake_block() (setup_snowflake) (alert "\nBasic Snowflake pattern") (setq cur_layer "layer1" step 1) (command "_.layer" "_set" cur_layer "") (command "_.color" 3) (fract_1_ent base_line ) (while (= (Yes_or_No "Go to next step ?") "_Y") (setq cur_blk_name (strcat "blk_" cur_layer)) (setq sel_set (ssget "X" (list (cons 8 cur_layer) ) ));;collect layern entity (setq step (1+ step)) (setq cur_layer (strcat "layer" (itoa step))) (princ (strcat "\nCurrent layer name is: " cur_layer))(terpri) (command "_.layer" "_set" cur_layer "") (make_snowflake) );;;end of while loop (reset_sysvar) );;;SNOWFLAKE_BLOCK ;;; (defun c:snowflake_lineset() (setup_snowflake) (alert "\nBasic Snowflake pattern") (setq cur_layer "layer1" step 1) (command "_.color" "BYLAYER") (command "_.layer" "_set" cur_layer "") (fract_1_ent base_line ) (while (= (Yes_or_No "Go to next step ?") "_Y") (setq sel_set (ssget "X" (list (cons 0 "LINE") (cons 8 cur_layer) ) ));;collect layern entity (setq step (1+ step)) (setq cur_layer (strcat "layer" (itoa step))) (command "_.layer" "set" cur_layer "") (princ (strcat "\nCurrent layer name is: " cur_layer))(terpri) (fract_1_sset sel_set) );;;end of while loop (reset_sysvar) );;SNOWFLAKE_LINESET ;;; ;;; (defun c:Koch_base() (setup_snowflake) (alert "\nBasic Snowflake pattern") (setq cur_layer "layer1" step 1) (command "_.color" "BYLAYER") (command "_.layer" "_set" cur_layer "") (fract_1_ent base_line ) (make_jpg) (make_jpg) (while (= (Yes_or_No "Go to next step ?") "_Y") (setq sel_set (ssget "X" (list (cons 0 "LINE") (cons 8 cur_layer) ) ));;collect layern entity (setq step (1+ step)) (setq cur_layer (strcat "layer" (itoa step))) (command "_.layer" "set" cur_layer "") (princ (strcat "\nCurrent layer name is: " cur_layer))(terpri) (fract_1_sset sel_set) (make_jpg) (make_jpg) );;;end of while loop (make_jpg) (make_jpg) (make_jpg) (reset_sysvar) );;SNOWFLAKE_LINESET ;;; (defun setup_snowflake() (setup_sysvar) (setq third (/ 1. 3.) half 0.5 sqrt_3 (sqrt 3.) pnt_1 '(0 0) pnt_2 (list third 0.) pnt_3 (list half (/ sqrt_3 6.)) pnt_4 (list (/ 2. 3.) 0.) pnt_5 '(1. 0) lower_left '(-0.02 -0.03) upper_right '(1.01 0.33) ) (setvar "OSMODE" 0) ;;;no snap mode (make_line_1 "0" 8 pnt_1 pnt_5) (command "_.zoom" "_W" lower_left upper_right) (setq base_line (entlast)) ) ;; (defun make_snowflake() ;define a new block for this layern (my_block_def cur_blk_name pnt_1 sel_set ) ;;;insert block name test_n (MY_BLOCK_INSERT2 cur_blk_name pnt_1 third 0.) (MY_BLOCK_INSERT2 cur_blk_name pnt_2 third 60.) (MY_BLOCK_INSERT2 cur_blk_name pnt_3 third -60.) (MY_BLOCK_INSERT2 cur_blk_name pnt_4 third 0.) ) ;;; ;fractal function1 fract_1 interactive selection version (defun c:fract_1_int(/ line_set pnt1 pnt2 x1 x2 y1 y2 ) (while (= (Yes_or_No "Go to next step ?") "_Y") (prompt "Select entities to be changed:") (terpri) (setq line_set (ssget) n (sslength line_set) index 0) (repeat n ; loop for all line entities (setq ent_list (entget (ssname line_set index)) pnt1 (cdr (assoc 10 ent_list)) pnt2 (cdr (assoc 11 ent_list)) x1 (car pnt1) y1 (cadr pnt1) x2 (car pnt2) y2 (cadr pnt2) base_angle (angle pnt1 pnt2) theta (+ base_angle (dtr 60.)) delta_x (/ (- x2 x1) 3.) delta_y (/ (- y2 y1) 3.) unit_length (/ (distance pnt1 pnt2) 3) new_pnt2 (list (+ x1 delta_x) (+ y1 delta_y)) new_pnt3 (polar new_pnt2 theta unit_length) new_pnt4 (list (+ x1 (* 2 delta_x)) (+ y1 (* 2 delta_y))) ) (command "_.line" pnt1 new_pnt2 new_pnt3 new_pnt4 pnt2 "") (entdel (ssname line_set index)) (setq index (1+ index)) ) );;;while loop ) ;;; ;fractal function1 fract_1 selection set version (defun fract_1_sset(line_set / pnt1 pnt2 x1 x2 y1 y2 index n) (setq n (sslength line_set) index 0) (repeat n ; loop for all line entities (setq ent_list (entget (ssname line_set index)) pnt1 (cdr (assoc 10 ent_list)) pnt2 (cdr (assoc 11 ent_list)) x1 (car pnt1) y1 (cadr pnt1) x2 (car pnt2) y2 (cadr pnt2) base_angle (angle pnt1 pnt2) theta (+ base_angle (dtr 60.)) delta_x (/ (- x2 x1) 3.) delta_y (/ (- y2 y1) 3.) unit_length (/ (distance pnt1 pnt2) 3) new_pnt2 (list (+ x1 delta_x) (+ y1 delta_y)) new_pnt3 (polar new_pnt2 theta unit_length) new_pnt4 (list (+ x1 (* 2 delta_x)) (+ y1 (* 2 delta_y))) ) (command "_.line" pnt1 new_pnt2 new_pnt3 new_pnt4 pnt2 "") (entdel (ssname line_set index)) (setq index (1+ index)) );;;repeat loop ) ;;; ;;; ;fractal function1 fract_1 individual entity version (defun fract_1_ent(base_line / pnt1 pnt2 x1 x2 y1 y2 base_angle theta delta_x delta_y unit_lenght new_pnt2 new_pnt3 new_pnt4 ) (setq ent_list (entget base_line) pnt1 (cdr (assoc 10 ent_list)) pnt2 (cdr (assoc 11 ent_list)) x1 (car pnt1) y1 (cadr pnt1) x2 (car pnt2) y2 (cadr pnt2) base_angle (angle pnt1 pnt2) theta (+ base_angle (dtr 60.)) delta_x (/ (- x2 x1) 3.) delta_y (/ (- y2 y1) 3.) unit_length (/ (distance pnt1 pnt2) 3) new_pnt2 (list (+ x1 delta_x) (+ y1 delta_y)) new_pnt3 (polar new_pnt2 theta unit_length) new_pnt4 (list (+ x1 (* 2 delta_x)) (+ y1 (* 2 delta_y))) ) (command "_.line" pnt1 new_pnt2 new_pnt3 new_pnt4 pnt2 "") );;; ;fractal function #2 fract_2 (defun c:fract_2_int(/ line_set pnt1 pnt2 x1 x2 y1 y2 index n) (prompt "Select entities to be changed:") (terpri) (setq line_set (ssget) n (sslength line_set) index 0) (repeat n ; loop for all line entities (setq ent_list (entget (ssname line_set index)) pnt1 (cdr (assoc 10 ent_list)) pnt2 (cdr (assoc 11 ent_list)) x1 (car pnt1) y1 (cadr pnt1) x2 (car pnt2) y2 (cadr pnt2) base_angle (angle pnt1 pnt2) theta (- base_angle (dtr 60.)) delta_x (/ (- x2 x1) 3.) delta_y (/ (- y2 y1) 3.) unit_length (/ (distance pnt1 pnt2) 3) new_pnt2 (list (+ x1 delta_x) (+ y1 delta_y)) new_pnt3 (polar new_pnt2 theta unit_length) new_pnt4 (list (+ x1 (* 2 delta_x)) (+ y1 (* 2 delta_y)) ) ) (command "_.line" pnt1 new_pnt2 new_pnt3 new_pnt4 pnt2 "") (entdel (ssname line_set index)) (setq index (1+ index)) );;;repeat loop );;;FRACT_2_INT ;;; ;;; (defun c:Koch_1() (setup_Koch) (alert "\nKoch's Snowflake pattern") (make_jpg) (make_jpg) (while (= (Yes_or_No "Go to next step ?") "_Y") (setq line_set (ssget "X" (list (cons 0 "LINE") ) );;collect all line entities n (sslength line_set) index 0) (setq color_id (rem nstep 7)) (if (= color_id 0) (setq color_id "BYLAYER")) (command "_.color" color_id) (repeat n ; loop for all line entities (setq ent_list (entget (ssname line_set index)) pnt1 (cdr (assoc 10 ent_list)) pnt2 (cdr (assoc 11 ent_list)) x1 (car pnt1) y1 (cadr pnt1) x2 (car pnt2) y2 (cadr pnt2) base_angle (angle pnt1 pnt2) theta (- base_angle (dtr 60.)) delta_x (/ (- x2 x1) 3.) delta_y (/ (- y2 y1) 3.) unit_length (/ (distance pnt1 pnt2) 3) new_pnt2 (list (+ x1 delta_x) (+ y1 delta_y)) new_pnt3 (polar new_pnt2 theta unit_length) new_pnt4 (list (+ x1 (* 2 delta_x)) (+ y1 (* 2 delta_y)) ) ) (command "_.line" pnt1 new_pnt2 new_pnt3 new_pnt4 pnt2 "") (entdel (ssname line_set index)) (setq index (1+ index)) );;;repeat loop (command "_.color" "BYLAYER") (setq nstep (1+ nstep)) (make_jpg) (command "_.delay" 500) );;;end of while loop (make_jpg) (make_jpg) (make_jpg) (reset_sysvar) );;KOCH_1 Koch's snowflake pattern starts with a triangle ;;; ;;; (defun c:Koch_2() (setup_Koch) (command "_.zoom" "_E") (alert "\nKoch's Anti-Snowflake pattern") ;(make_jpg) (make_jpg) (while (= (Yes_or_No "Go to next step ?") "_Y") (setq line_set (ssget "X" (list (cons 0 "LINE") ) );;collect all line entities n (sslength line_set) index 0) (setq color_id (rem nstep 7)) (if (= color_id 0) (setq color_id "BYLAYER")) (command "_.color" color_id) (repeat n ; loop for all line entities (setq ent_list (entget (ssname line_set index)) pnt1 (cdr (assoc 10 ent_list)) pnt2 (cdr (assoc 11 ent_list)) x1 (car pnt1) y1 (cadr pnt1) x2 (car pnt2) y2 (cadr pnt2) base_angle (angle pnt1 pnt2) theta (+ base_angle (dtr 60.)) delta_x (/ (- x2 x1) 3.) delta_y (/ (- y2 y1) 3.) unit_length (/ (distance pnt1 pnt2) 3) new_pnt2 (list (+ x1 delta_x) (+ y1 delta_y)) new_pnt3 (polar new_pnt2 theta unit_length) new_pnt4 (list (+ x1 (* 2 delta_x)) (+ y1 (* 2 delta_y))) ) (command "_.line" pnt1 new_pnt2 new_pnt3 new_pnt4 pnt2 "") (entdel (ssname line_set index)) (setq index (1+ index)) );;;repeat loop (command "_.color" "BYLAYER") (setq nstep (1+ nstep)) (make_jpg) (command "_.delay" 500) );;;end of while loop (make_jpg) ;(make_jpg) ;(make_jpg) (reset_sysvar) );;KOCH_2 Koch's anti-snowflake pattern starts with a triangle ;;; ;;; (defun setup_Koch() (setup_sysvar) (setq pnt_1 '(0 0) pnt_2 '(2 0) pnt_3 (list 1 (sqrt 3.)) lower_left '(-0.23 -0.61) upper_right '(2.25 1.8) nstep 1 ) (setvar "OSMODE" 0) ;;;no snap mode (command "_.line" pnt_1 pnt_2 pnt_3 "_c") (command "_.zoom" "_W" lower_left upper_right) ) ;;SETUP_KOCH