;;; ;;;STRING_EPICYCLOID.LSP (prompt "\nCurve-Stitching by AutoCAD - Epicycloid.LSP") (prompt "\nCommands: string_epicycloid test1 test2 ") (prompt "\n ") ;;;Ref. Jon Millington ;;; ;;;Takaya Iwamoto Dec 31, 2003 initial run ;;; Nov 21,2006 added multi-color feature ;;; July 3,2007 modified for final release ;;; July 28,2007 renamed as string_epicycloid.lsp ;;; Aug 10,2008 added test_epicycloid for multi colored string ;;; (defun C:string_epicycloid() (setup_epicycloid) (make_jpg) ;(setq num_cusp (getint "\nNumber of cusp ? (def = 1)")) ;(if (= num_cusp nil) (setq num_cusp 1)) ;(setq delay_time (getint "\ndelay time between display(def = 100 ms)")) ;(if (= delay_time nil) (setq delay_time 100)) ;;;execute the selected program (cond ((= num_cusp 1) (C:cardioid) ) ((= num_cusp 2) (C:nephroid) ) ((= num_cusp 3) (C:cremona) ) ((> num_cusp 3) (C:test1) ) (t nil) );;;end of cond (make_jpg) (make_jpg) (reset_sysvar) ) ;;; (defun C:test_epicycloid() (setup_epicycloid) (make_jpg) ;(setq num_cusp (getint "\nNumber of cusp ? (def = 1)")) ;(if (= num_cusp nil) (setq num_cusp 1)) ;(setq delay_time (getint "\ndelay time between display(def = 100 ms)")) ;(if (= delay_time nil) (setq delay_time 100)) ;;;execute the selected program (cond ((= num_cusp 1) (C:test_cardioid) ) ((= num_cusp 2) (C:test_nephroid) ) ((= num_cusp 3) (C:test_cremona) ) ((> num_cusp 3) (C:test_test1) ) (t nil) );;;end of cond (make_jpg) (make_jpg) (reset_sysvar) ) ;;; (defun C:test1() ;(setq num_sec (getint "\nNumber of section (def=72)")) ;(if (= num_sec nil) (setq num_sec 72)) (setq del_theta (/ (* 2 pi) num_sec) nstep 0 n_section 50 color_id 2 ) ;(setq num_cusp (getint "\nNumber of cusp ? (def = 1)")) ;(if (= num_cusp nil) (setq num_cusp 1)) (setq ref_num (/ num_sec (1+ num_cusp)) sec_unit (fix (/ num_sec num_cusp)) ) (repeat num_sec (setq start_angle (* nstep del_theta) p_start (polar pnt_org start_angle ref_rad) end_angle (* (1+ num_cusp) del_theta (rem nstep ref_num)) p_end (polar pnt_org end_angle ref_rad) ) (setq color_id (1+ (fix (/ nstep sec_unit))) ) (slow_line n_section "0" color_id p_start p_end) (setq nstep (1+ nstep) ) (make_jpg) (command "_.delay" delay_time) );;;outer loop );;;TEST1 ;;; ;;;TEST_TEST1 ;;; (defun C:test_test1() ;(setq num_sec (getint "\nNumber of section (def=72)")) ;(if (= num_sec nil) (setq num_sec 72)) (setq string_type (getstring "\nSelect string type (def=string_36)")) (if (= string_type nil) (setq string_type "string_36")) (setq del_theta (/ (* 2 pi) num_sec) nstep 0 n_section 50 color_id 2 ) ;(setq num_cusp (getint "\nNumber of cusp ? (def = 1)")) ;(if (= num_cusp nil) (setq num_cusp 1)) (setq ref_num (/ num_sec (1+ num_cusp)) sec_unit (fix (/ num_sec num_cusp)) ) (repeat num_sec (setq start_angle (* nstep del_theta) p_start (polar pnt_org start_angle ref_rad) end_angle (* (1+ num_cusp) del_theta (rem nstep ref_num)) p_end (polar pnt_org end_angle ref_rad) line_angle (rtd (angle p_start p_end)) line_scale (distance p_start p_end) ) (if (> line_scale 0.01) ;(make_line_1 "0" color_id p_start p_end) (command "_.insert" string_type p_start line_scale line_scale line_angle) ) (setq nstep (1+ nstep) ) (make_jpg) (command "_.delay" delay_time) );;;outer loop );;;test_TEST1 ;;; ;;; (defun setup_epicycloid() (setup_sysvar) (setq ref_rad 1.0 pnt_org '(0 0) ) (make_circle_1 "0" 8 pnt_org ref_rad) (setq num_cusp (getint "\nNumber of cusp ? (def = 1)")) (if (= num_cusp nil) (setq num_cusp 1)) (setq num_sec (getint "\nNumber of section (def=72)")) (if (= num_sec nil) (setq num_sec 72)) (setq delay_time (fix (/ 7200 num_sec))) (command "_.zoom" "E") (command "_.regen") );;;SETUP_EPICYCLOID ;;; (defun C:test2() (setup_epicycloid) ;(setq num_sec (getint "\nNumber of section (def=72)")) ;(if (= num_sec nil) (setq num_sec 72)) (setq del_theta (/ (* 2 pi) num_sec) nstep 0 n_section 50 ) ;(setq num_cusp (getint "\nNumber of cusp ? (def = 1)")) ;(if (= num_cusp nil) (setq num_cusp 1)) (setq ref_num (/ num_sec (1+ num_cusp)) ) (repeat num_sec (setq start_angle (* nstep del_theta) p_start (polar pnt_org start_angle ref_rad) end_angle (* (1+ num_cusp) del_theta (rem nstep ref_num)) p_end (polar pnt_org end_angle ref_rad) ) (make_line_1 "0" color_id p_start p_end) (setq nstep (1+ nstep) ) );;;outer loop (reset_sysvar) );;;TEST2 ;;; ;;; (defun C:cardioid() (alert "\nMake background color to color code 84\nfor a better effect") ;(setq num_sec (getint "\nNumber of section (def=72)")) ;(if (= num_sec nil) (setq num_sec 72)) (setq del_theta (/ (* 2 pi) num_sec) nstep 0 color_id 255 num_cusp 1 ref_num (/ num_sec (1+ num_cusp) ) ) (repeat num_sec (setq start_angle (* nstep del_theta) p_start (polar pnt_org start_angle ref_rad) end_angle (* (1+ num_cusp) del_theta (rem nstep ref_num)) p_end (polar pnt_org end_angle ref_rad) ) (make_line_1 "0" color_id p_start p_end) (setq nstep (1+ nstep) ) (make_jpg) (command "_.delay" delay_time) );;;outer loop );;;cardioid ;;; ;;; (defun C:test_cardioid() ;(alert "\nMake background color to color code 84\nfor a better effect") (setq string_type (getstring "\nSelect string type (def=string_36)")) (if (= string_type nil) (setq string_type "string_36")) ;(setq num_sec (getint "\nNumber of section (36,72,144,288,576,864,.. def=72)")) ;(if (= num_sec nil) (setq num_sec 72)) (setq del_theta (/ (* 2 pi) num_sec) nstep 1 color_id 255 num_cusp 1 ref_num (/ num_sec (1+ num_cusp) ) ref_rad 1.0 pnt_org '(0 0) ) (repeat num_sec (setq start_angle (* nstep del_theta) p_start (polar pnt_org start_angle ref_rad) end_angle (* (1+ num_cusp) del_theta (rem nstep ref_num)) p_end (polar pnt_org end_angle ref_rad) line_angle (rtd (angle p_start p_end)) line_scale (distance p_start p_end) ) (if (> line_scale 0.01) ;(make_line_1 "0" color_id p_start p_end) (command "_.insert" string_type p_start line_scale line_scale line_angle) ) (setq nstep (1+ nstep) ) (make_jpg) (command "_.delay" delay_time) );;;outer loop );;;test_cardioid ;;; ;;; ;;; (defun C:nephroid() (alert "\nMake background color to color code 144\nfor a better effect") ;(setq num_sec (getint "\nNumber of section (def=72)")) ;(if (= num_sec nil) (setq num_sec 72)) (setq del_theta (/ (* 2 pi) num_sec) nstep 0 color_id 2 num_cusp 2 ref_num (/ num_sec (1+ num_cusp) ) ) (repeat num_sec (setq start_angle (* nstep del_theta) p_start (polar pnt_org start_angle ref_rad) end_angle (* (1+ num_cusp) del_theta (rem nstep ref_num)) p_end (polar pnt_org end_angle ref_rad) ) (if (<= nstep (/ num_sec 2)) (setq color_id 10) (setq color_id 40)) (make_line_1 "0" color_id p_start p_end) (setq nstep (1+ nstep) ) (make_jpg) (command "_.delay" delay_time) );;;outer loop );;;nephroid ;;; ;;; ;;; (defun C:test_nephroid() ;(alert "\nMake background color to color code 144\nfor a better effect") (setq string_type (getstring "\nSelect string type (def=string_36)")) (if (= string_type nil) (setq string_type "string_36")) ;(setq num_sec (getint "\nNumber of section (def=72)")) ;(if (= num_sec nil) (setq num_sec 72)) (setq del_theta (/ (* 2 pi) num_sec) nstep 0 color_id 2 num_cusp 2 ref_num (/ num_sec (1+ num_cusp) ) ) (repeat num_sec (setq start_angle (* nstep del_theta) p_start (polar pnt_org start_angle ref_rad) end_angle (* (1+ num_cusp) del_theta (rem nstep ref_num)) p_end (polar pnt_org end_angle ref_rad) line_angle (rtd (angle p_start p_end)) line_scale (distance p_start p_end) ) (if (> line_scale 0.01) ;(make_line_1 "0" color_id p_start p_end) (command "_.insert" string_type p_start line_scale line_scale line_angle) ) (setq nstep (1+ nstep) ) (make_jpg) (command "_.delay" delay_time) );;;outer loop );;;test_nephroid ;;; ;;; (defun C:Cremona() (alert "\nMake background color to color code 41\nfor a better effect") ;(setq num_sec (getint "\nNumber of section (def=72)")) ;(if (= num_sec nil) (setq num_sec 72)) (setq del_theta (/ (* 2 pi) num_sec) nstep 0 color_id 10 num_cusp 3 ref_num (/ num_sec (1+ num_cusp) ) sec_unit (fix (/ num_sec 3)) ) (repeat num_sec (setq start_angle (* nstep del_theta) p_start (polar pnt_org start_angle ref_rad) end_angle (* (1+ num_cusp) del_theta (rem nstep ref_num)) p_end (polar pnt_org end_angle ref_rad) ) (setq color_id (1+ (fix (/ nstep sec_unit))) ) (make_line_1 "0" 3 p_start p_end) (setq nstep (1+ nstep) ) (make_jpg) (command "_.delay" delay_time) );;;outer loop );;;Cremona ;;; ;;; (defun C:test_Cremona() ;(alert "\nMake background color to color code 41\nfor a better effect") (setq string_type (getstring "\nSelect string type (def=string_36)")) (if (= string_type nil) (setq string_type "string_36")) ;(setq num_sec (getint "\nNumber of section (def=72)")) ;(if (= num_sec nil) (setq num_sec 72)) (setq del_theta (/ (* 2 pi) num_sec) nstep 0 color_id 10 num_cusp 3 ref_num (/ num_sec (1+ num_cusp) ) sec_unit (fix (/ num_sec 3)) ) (repeat num_sec (setq start_angle (* nstep del_theta) p_start (polar pnt_org start_angle ref_rad) end_angle (* (1+ num_cusp) del_theta (rem nstep ref_num)) p_end (polar pnt_org end_angle ref_rad) line_angle (rtd (angle p_start p_end)) line_scale (distance p_start p_end) ) (if (> line_scale 0.01) ;(make_line_1 "0" color_id p_start p_end) (command "_.insert" string_type p_start line_scale line_scale line_angle) ) ;(setq color_id (1+ (fix (/ nstep sec_unit))) ) ;(make_line_1 "0" 3 p_start p_end) (setq nstep (1+ nstep) ) (make_jpg) (command "_.delay" delay_time) );;;outer loop );;;test_Cremona ;;; ;;; ;;;multi_color_line multi colored line ;;; (defun c:basic_color_line() (setq pnt_0 '(0 0) pnt_1 '(1 0) ) (setq ncolor (getint "\nNumber of colors (def = 8)")) (if (= ncolor nil) (setq ncolor 8)) ;;divide line into ncolor sections and assign color to each. (setq cnt 0 del (/ 1. ncolor)) (repeat ncolor (setq pnt_s (plt pnt_0 pnt_1 (* del cnt)) pnt_e (plt pnt_0 pnt_1 (* del (1+ cnt))) layer_name (strcat "layer" (itoa (1+ cnt))) ) (make_line_1 layer_name 256 pnt_s pnt_e) (setq cnt (1+ cnt)) );;end of repeat );;;end of basic_color_line ;;; ;;; (defun c:sym_color_line1() (setq pnt_0 '(0 0) pnt_1 '(0.5 0) pnt_2 '(1 0) ) (setq ncolor (getint "\nNumber of colors (def = 36)")) (if (= ncolor nil) (setq ncolor 36)) ;;divide line into ncolor sections and assign color to each. (setq cnt 0 del (/ 1. ncolor)) (repeat ncolor (setq pnt_s (plt pnt_0 pnt_1 (* del cnt)) pnt_e (plt pnt_0 pnt_1 (* del (1+ cnt))) layer_name (strcat "layer" (itoa (1+ cnt))) ) (make_line_1 layer_name 256 pnt_s pnt_e) (setq cnt (1+ cnt)) );;end of repeat (setq cnt 0 ) (repeat ncolor (setq pnt_s (plt pnt_2 pnt_1 (* del cnt)) pnt_e (plt pnt_2 pnt_1 (* del (1+ cnt))) layer_name (strcat "layer" (itoa (1+ cnt))) ) (make_line_1 layer_name 256 pnt_s pnt_e) (setq cnt (1+ cnt)) );;end of repeat );;;end of sym_color_line1 ;;; ;;; (defun c:sym_color_line2() (setq pnt_0 '(0 0) pnt_1 '(0.5 0) pnt_2 '(1 0) ) (setq ncolor (getint "\nNumber of colors (def = 36)")) (if (= ncolor nil) (setq ncolor 36)) ;;divide line into ncolor sections and assign color to each. (setq cnt 0 del (/ 1. ncolor)) (repeat ncolor (setq pnt_s (plt pnt_0 pnt_1 (* del cnt)) pnt_e (plt pnt_0 pnt_1 (* del (1+ cnt))) layer_name (strcat "layer" (itoa (1+ cnt))) ) (make_line_1 layer_name 256 pnt_s pnt_e) (setq cnt (1+ cnt)) );;end of repeat ;;cotinue counter (setq lcnt cnt cnt 0) (repeat ncolor (setq pnt_s (plt pnt_2 pnt_1 (* del cnt)) pnt_e (plt pnt_2 pnt_1 (* del (1+ cnt))) layer_name (strcat "layer" (itoa (1+ lcnt))) ) (make_line_1 layer_name 256 pnt_s pnt_e) (setq cnt (1+ cnt) lcnt (1+ lcnt) ) );;end of repeat );;;end of sym_color_line2 ;;; ;;; ;;; ;;;MAKE_WIDE_LINE make lines into polylines with a given width ;;; (defun c:make_wide_line() (setq line_width (getreal "\nSpecify line width (def = 0.01)")) (if (= line_width nil) (setq line_width 0.01)) (setq line_set (ssget "X" (list (cons 0 "LINE")))) (setq nsize (sslength line_set)) (setq index 0) (repeat nsize (setq test_ent (ssname line_set index)) (command "_.pedit" test_ent "Y" "W" line_width "") (entdel test_ent) (setq index (1+ index)) ) );;; ;;; ;;; ;;;color code conversion HSL to RGB ;;;HSL example (35,50,75) ;;;range H (0-360), S & L (0-100) ;;;RGB example (223,197,159) ;;;range R,G,B (0 - 255) ;;;HSL_2_RGB ;;; (defun hsl_2_rgb(hue sat lum / hu sa lu one_third one_sixth two_third half p q tr tg tb ind_r ind_g ind_b ) ;;noramlize HSL values (setq hu (/ hue 360.) sa (/ sat 100.) lu (/ lum 100.) one_third (/ 1. 3.) one_sixth (/ 1. 6.) two_third (/ 2. 3.) half 0.5 ) ;;define p,q parameters depening on the lum value (if (< lu 0.5) (setq q (* lu (+ 1. sa))) (setq q (+ lu sa (- (* lu sa)))) );;end if (setq p (- (* 2 lu) q)) ;;temp values for TR,TG,TB (setq tr (+ hu one_third) tg hu tb (- hu one_third) ) ;;modify TR,TG,TB depending on its value (if (< tr 0.) (setq tr (1+ tr))) (if (> tr 1.) (setq tr (1- tr))) (if (< tg 0.) (setq tg (1+ tg))) (if (> tg 1.) (setq tg (1- tg))) (if (< tb 0.) (setq tb (1+ tb))) (if (> tb 1.) (setq tb (1- tb))) ;;final adjustment for TR (cond ((< tr one_sixth) (setq tr (+ p (* 6 tr (- q p)) )) ) ((and (>= tr one_sixth) (< tr half)) (setq tr q)) ((and (>= tr half) (< tr two_third)) (setq tr (+ p (* (- q p) 6 (- two_third tr))))) ( (>= tr two_third) (setq tr p)) (t nil) );;;end of cond ;;final adjustment for TG (cond ((< tg one_sixth) (setq tg (+ p (* 6 tg (- q p)) )) ) ((and (>= tg one_sixth) (< tg half)) (setq tg q)) ((and (>= tg half) (< tg two_third)) (setq tg (+ p (* (- q p) 6 (- two_third tg))))) ( (>= tg two_third) (setq tg p)) (t nil) );;;end of cond ;;final adjustment for TB (cond ((< tb one_sixth) (setq tb (+ p (* 6 tb (- q p)) )) ) ((and (>= tb one_sixth) (< tb half)) (setq tb q)) ((and (>= tb half) (< tb two_third)) (setq tb (+ p (* (- q p) 6 (- two_third tb))))) ( (>= tb two_third) (setq tb p)) (t nil) );;;end of cond ;;convert tr,tg,tb back to RGB index (setq ind_r (fix (* 255 tr)) ind_g (fix (* 255 tg)) ind_b (fix (* 255 tb)) ) ;(setq output (list ind_r ind_g ind_b)) (setq rgb_index (strcat (itoa ind_r) "," (itoa ind_g) "," (itoa ind_b))) );;; ;;; ;;; ;;; Function: SET_FRACTAL_LAYER_COLOR ;;; ;;; define layer name from layer1 up to layer500 ;;; and assign color by RGB color code ;;; (defun C:SET_LAYER_COLOR (/ layer_cnt layer_name rgb_code) (setup_sysvar) (setq max_layer_num (getint "\nMax Layer number ?(def=100)")) (if (= max_layer_num nil) (setq max_layer_num 100)) (setq ratio (/ 360. max_layer_num) layer_cnt 1 ) (repeat max_layer_num (setq layer_name (strcat "layer" (itoa layer_cnt)) hue_ind (fix (* ratio (1- layer_cnt))) rgb_code (hsl_2_rgb hue_ind 100 60) ) (princ "rgb code = ")(princ rgb_code)(terpri) (command "_.layer" "_new" layer_name "_color" "_T" rgb_code layer_name "") (setq layer_cnt (1+ layer_cnt)) ) (reset_sysvar) );;;SET_LAYER_COLOR ;;; ;;; ;;; Function: SET_LAYER_COLOR2 ;;; ;;; define layer name from layer1 up to layer500 ;;; and assign color by RGB color code ;;; (defun C:SET_LAYER_COLOR2 (/ layer_cnt layer_name rgb_code) (setup_sysvar) (setq max_layer_num (getint "\nMax Layer number ?(def=100)")) (if (= max_layer_num nil) (setq max_layer_num 100)) (setq ratio (/ 360. max_layer_num) layer_cnt 1 ) (repeat max_layer_num (setq layer_name (strcat "layer" (itoa layer_cnt)) hue_ind (fix (* ratio (1- layer_cnt))) lum (+ 40 (* 20 (rem (1- layer_cnt) 2))) rgb_code (hsl_2_rgb hue_ind 70 lum) ) (princ "rgb code = ")(princ rgb_code)(terpri) (command "_.layer" "_new" layer_name "_color" "_T" rgb_code layer_name "") (setq layer_cnt (1+ layer_cnt)) ) (reset_sysvar) );;;SET_LAYER_COLOR2 ;;; ;;; ;;; Function: SET_FRACTAL_LAYER ;;; ;;; define layer name from layer1 up to layer500 ;;; and assign color by RGB color code ;;; (defun SET_FRACTAL_LAYER (/ layer_cnt layer_name rgb_code) (setup_sysvar) (setq layer_cnt 1) (repeat 500 (setq layer_name (strcat "layer" (itoa layer_cnt)) rgb_code (hsl_2_rgb (rem layer_cnt 360) 70 40) ) (princ "rgb code = ")(princ rgb_code)(terpri) (command "_.layer" "_new" layer_name "_color" "_T" rgb_code layer_name "") (setq layer_cnt (1+ layer_cnt)) ) (reset_sysvar) ) ;SET_FRACTAL_LAYER ;;; ;;; Function: SET_FRACTAL_LAYER2 ;;; ;;; define layer name from layer1 up to layer999 ;;; and assign color by RGB color code ;;; (defun SET_FRACTAL_LAYER2 (/ layer_cnt layer_name rgb_code) (setup_sysvar) (setq layer_cnt 1) (repeat 999 (setq layer_name (strcat "layer" (itoa layer_cnt)) rgb_code (hsl_2_rgb (rem layer_cnt 360) 70 40) ) (princ "rgb code = ")(princ rgb_code)(terpri) (command "_.layer" "_new" layer_name "_color" "_T" rgb_code layer_name "") (setq layer_cnt (1+ layer_cnt)) ) (reset_sysvar) ) ;SET_FRACTAL_LAYER2 ;;;************************************************************************ ;;; ;;; Function: SET_LAYER_BASIC ;;; ;;; define layer name according to the color(1 - 8). ;;; (defun SET_LAYER_BASIC (/ ncolor layer_name) (setup_sysvar) (setq ncolor 1) (repeat 255 (setq layer_name (strcat "layer" (itoa ncolor))) (command "_.layer" "_new" layer_name "_color" ncolor layer_name "") (setq ncolor (1+ ncolor)) ) (reset_sysvar) ) ;SET_LAYER_BASIC ;;;; ;;; ;;;Enhance_boundary ;;;number of cusp is inherited from the previous run. ;;;The layer to be enhanced is 1/(n+2) , where n is the no. of cusp. ;;;For example , take 36 color and cardioid case, 36/(1+ 2) = 12---> layer12 ;;; (defun c:enhance_boundary() (setq str_col (getint "\nNumber of string's color") n0 (fix (/ str_col (+ num_cusp 2))) nprev (1- n0) npost (1+ n0) center_lay (strcat "layer" (itoa n0)) prev_lay (strcat "layer" (itoa nprev)) post_lay (strcat "layer" (itoa npost)) ) (setq ss_center (ssget "X" (list (cons 8 center_lay))) ss_prev (ssget "X" (list (cons 8 prev_lay))) ss_post (ssget "X" (list (cons 8 post_lay))) ) ;;;draworder (command "_.draworder" ss_prev ss_post "" "F") (command "_.draworder" ss_center "" "F") (princ "central layer name: ")(princ center_lay)(terpri) );;; ;;; ;;; ;;;TEST_LAYER ;;; ;;; (defun c:test_layer() (setq test1 (ssget "X" (list (cons 8 "layer1")))) (setq test2 (ssget "X" (list (cons 8 "layer2")))) (setq test3 (ssget "X" (list (cons 8 "layer3")))) (setq test4 (ssget "X" (list (cons 8 "layer4")))) (setq test5 (ssget "X" (list (cons 8 "layer5")))) (setq test6 (ssget "X" (list (cons 8 "layer6")))) (setq test7 (ssget "X" (list (cons 8 "layer7")))) (setq test8 (ssget "X" (list (cons 8 "layer8")))) (setq test9 (ssget "X" (list (cons 8 "layer9")))) (setq test10 (ssget "X" (list (cons 8 "layer10")))) (command "_.draworder" test1 "" "F") (command "_.draworder" test2 "" "F") (command "_.draworder" test3 "" "F") (command "_.draworder" test4 "" "F") (command "_.draworder" test5 "" "F") (command "_.draworder" test6 "" "F") (command "_.draworder" test7 "" "F") (command "_.draworder" test8 "" "F") (command "_.draworder" test9 "" "F") (command "_.draworder" test10 "" "F") )