;;;Summation of N equally spaced integers ;;;sumint_3 ;;;used sumint_1.lsp as a template ;;; Sept 19,2003--Sept 22,2003 ;;; Copyright 2006 Takaya Iwamoto ;;; (defun c:sumint_3 () (setq nstep 1) (setup_sumint) (while (= (Yes_or_No "Go to next step ?") "_Y") (draw_ball nstep col_id) (draw_text nstep) (IF (= JPG_Yes 1) (make_jpg) ) (setq nstep (1+ nstep)) ) (setq pnt_end w_loc) ;;call draw_text_1 (draw_text_1) (IF (= JPG_YES 1) (make_jpg) ) ;;;end of while loop ;;Make a copy to the right and change its color to red. (copy_to_right) ;;Rotate red balls 180. degrees CCW around its center (rotate_180) ;;Move red ball group on top of white balls (move_to_left) ;;draw line and text (draw_text_2) (IF (= JPG_YES 1) (make_jpg) ) (reset_sysvar) ) ;;; (defun setup_sumint (/ py pxy px lower_left upper_right y_text3) (setup_sysvar) (if (= ICAD 0) (command "shademode" "G")) ;;;draw the first dot and lines (setq py (list nstep nstep) pxy (list nstep 0) px (list 0 0) lower_left '(-2 -2.25) upper_right '(18 18) dot_rad 0.35 x_text1 -1.3 y_text2 -1.0 y_text3 -2.0 nstep (1+ nstep) pnt_start '(1.5 0.5) ss1 nil ) (setq a1 (getint "\nFirst number (def = 1): ") delta (getint "\nIncrement (def = 1): ") ) (if (= a1 nil) (setq a1 1) ) (if (= delta nil) (setq delta 1) ) ;;;draw a ball (draw_ball 1 0) ;;;draw a fence (textdisplay "N" (list x_text1 y_text2) 0.4 0.) (textdisplay "1" (list 1.3 y_text2) 0.4 0.) (command "_.zoom" "W" lower_left upper_right) (IF (= JPG_YES 1) (make_jpg) ) ) ;; ;;; ;;;DRAW_BALL draw balls (2n-1) = (n-1) + (n-1) + 1 ;;; (n-1) each horizontally & vertically at x & y = (n-0.5) ;;; remaining one at x = y = (n-0.5) ;;; (defun draw_ball (num col_id / ns step w_xs) (setq ns (+ a1 (* (- num 1) delta)) step 0 w_xs (+ num 0.5) ) ;;;loop for repeat (repeat ns (setq w_loc (list w_xs (+ step 0.5))) (my_block_insert "white_ball" w_loc dot_rad) (setq step (1+ step)) ) ;;;loop for repeat ) ;;; ;;;DRAW_TEXT ;;; (defun draw_text (num / loc1 loc2 loc2 w_ys r_xs) (setq w_ys (- num 0.5) r_xs (+ num 0.5) loc1 (list x_text1 w_ys) loc2 (list r_xs y_text2) ) (textdisplay (itoa num) loc2 0.4 0.) ) ;;;draw_text ;;; ;; (defun draw_text_1 () (setq An (+ A1 (* (- nstep 2) delta)) p1 (list 1.0 0) pn (list nstep 0) p1_up (list 1.0 A1) pn_up (list nstep An) p1_left (shift_pnt p1 (list -0.5 0)) p1_up_left (shift_pnt p1_up (list -0.5 0)) pn_right (shift_pnt pn (list 0.5 0)) pn_up_right (shift_pnt pn_up (list 0.5 0)) p1_mid (shift_pnt (mid_point p1_left p1_up_left) '(-0.9 -0.3)) pn_mid (shift_pnt (mid_point pn_right pn_up_right) '(0.2 0)) p1_top (list 1 (+ A1 An)) p1_top_left (shift_pnt p1_top '(-0.5 0)) pn_top (list nstep (+ A1 An)) pn_top_right (shift_pnt pn_top '(0.5 0)) ) (make_line_1 "0" 8 p1 p1_left) (make_line_1 "0" 8 p1_up p1_up_left) (make_line_1 "0" 8 pn pn_right) (make_line_1 "0" 8 pn_up pn_up_right) (make_line_1 "0" 8 p1_left p1_up_left) (make_line_1 "0" 8 pn_right pn_up_right) (textdisplay "A1" p1_mid 0.5 0.) (textdisplay "An" pn_mid 0.5 0.) ) ;;; ;;;Draw_text_2 ;; (defun draw_text_2 () (setq p1_top (list 1 (+ A1 An)) p1_top_left (shift_pnt p1_top '(-0.5 0)) pn_top (list nstep (+ A1 An)) pn_top_right (shift_pnt pn_top '(0.5 0)) p1_up_mid (shift_pnt (mid_point p1_up_left p1_top_left) '(-1 0.0)) pn_up_mid (shift_pnt (mid_point pn_top_right pn_up_right) '(0.1 0)) ) (make_line_1 "0" 8 p1_top p1_top_left) (make_line_1 "0" 8 p1_top_left p1_up_left) (make_line_1 "0" 8 pn_top pn_top_right) (make_line_1 "0" 8 pn_top_right pn_up_right) (textdisplay "A1" pn_up_mid 0.5 0.) (textdisplay "An" p1_up_mid 0.5 0.) ;;;Result (textdisplay "Sum of" '(11.27 11.80) 1.46 0.) (textdisplay "Equally Spaced Integers" '(7.92 9.27) 0.86 0.) (textdisplay "= (1/2) N (A1 + An)" '(8.68 5.72) 1.0 0.) ) ;;; ;;;Copy_to_right ;;; (defun copy_to_right () (command "_.delay" 500) (alert "\nCopy this to the right\nand change its color to red." ) ;make a selection list of all white balls (setq all_balls (ssget "C" pnt_start pnt_end)) ;copy this to right hand side (setq pstart2 (shift_pnt pnt_start (list (1+ nstep) 0)) pend2 (shift_pnt pnt_end (list (1+ nstep) 0)) ) (command "_.copy" all_balls "" pnt_start pstart2) (IF (= JPG_Yes 1) (make_jpg) ) (setq all_balls (ssget "C" pstart2 pend2)) (command "_.explode" all_balls) (command "_.delay" 500) (setq all_balls (ssget "C" pstart2 pend2)) (command "_.chprop" all_balls "" "LA" "layer1" "") (command "_.layer" "_set" "0" "") (IF (= JPG_Yes 1) (make_jpg) ) ) ;;; ;;;Rotate_180 ;;; (defun rotate_180 (/ step step_deg red_center) (command "_.delay" 500) ;;rotate red balls 180 degrees (Alert "\nRotate red balls 180. degrees CCW around its center" ) (setq red_center (mid_point pstart2 pend2) step 3 step_deg (/ 180. (float step)) ) (repeat step (command "_.rotate" all_balls "" red_center step_deg) (IF (= JPG_Yes 1) (make_jpg) ) (command "_.delay" 1000) ) ) ;;; ;;;Move_to_left ;;; (defun move_to_left (/ step inc n_step pnt_1 pnt_2 pdest) ;;move this red ball group on the top of white balls (alert "\nMove red ball group on top of white balls") (setq pdest (list 1.5 (+ 0.5 a1)) step 4 inc (/ 1. (float step)) n_step 1 ) (repeat step (setq pnt_1 (plt pstart2 pdest (* inc (- n_step 1))) pnt_2 (plt pstart2 pdest (* inc n_step)) ) (command "_.move" all_balls "" pnt_1 pnt_2) (IF (= JPG_YES 1) (make_jpg) ) (setq n_step (1+ n_step)) (command "_.delay" 1000) ) ) ;;;