;;;Sum of odd number #2 ;;;SUMODD_2 ;;; Sept 19,2003--Sept 22,2003 ;;; Copyright 2006 Takaya Iwamoto ;;; (defun c:sumodd_2 () (setq nstep 1) (setup_oddsum2) (while (= (Yes_or_No "Go to next step ?") "_Y") (setq col_id (rem nstep 2)) (draw_ball2 nstep col_id) (draw_fence2 nstep) (IF (= JPG_YES 1) (make_jpg) ) (setq nstep (1+ nstep)) ) ;;;end of while loop (alert "\nCopy around the center") (command "_.array" "all" "" "Polar" '(0 0) 4 "" "Y") (IF (= JPG_YES 1) (make_jpg) ) ;(rotate_ent copy_line_ad pnt_a pnt_d 90. 25 25 1) (command "_.delay" 3000) (draw_final_text2) (IF (= JPG_YES 1) (make_jpg) ) (alert "\n****End****\nIt is clear that \nsum of odd integers (2n-1) \nis N squared." ) (reset_sysvar) ) ;;; (defun setup_oddsum2 ( / mn mnp1 p0 p1 p2 lower_left upper_right) (setup_sysvar) (if (= ICAD 0) (command "SHADEMODE" "G")) ;;;draw the first dot and lines (setq mn (- nstep) mnp1 (+ mn 1) p0 (list mnp1 mnp1) p1 (list mn mnp1) p2 (list mn mn) lower_left '(-8 -8) upper_right '(11.5 12) dot_rad 0.35 y_text1 -0.5 y_text2 -1.25 y_text3 -2.0 nstep (1+ nstep) ) ;;;draw a dot ;(circle_dot "0" 1 '(0.5 0.5) dot_rad) (my_block_insert "red_ball" '(-0.5 -0.5) dot_rad) ;;;draw a fence (command "_.pline" p0 p1 p2 "") (command "_.zoom" "W" lower_left upper_right) (IF (= JPG_YES 1) (make_jpg) ) );;SETUP_ODDSUM2 ;; ;;; ;;;DRAW_DOT draw dots (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_dot (num col_id / ns coord x0 y0 delta step x_loc y_loc xy_loc) (setq ns (1- num) coord (- num 0.5) x0 0.5 y0 0.5 xy_loc (list coord coord) delta 1.0 step 0 ) (repeat ns (setq x_loc (list coord (+ y0 (* step delta))) y_loc (list (+ x0 (* step delta)) coord) ) (circle_dot "0" col_id x_loc dot_rad) (circle_dot "0" col_id y_loc dot_rad) (setq step (1+ step)) ) ;;;loop for repeat (circle_dot "0" col_id xy_loc dot_rad) ) ;;;DRAW_DOT ;;; ;;; ;;;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_ball2 (num col_id / ns mn xs coord x0 y0 delta step x_loc y_loc xy_loc) (setq ns (1- (* 2 num)) mn (- num) y_loc (+ mn 0.5) xs (+ mn 0.5) delta 1.0 step 0 ) (setq ball_name (get_ballname col_id)) (repeat ns (setq x_loc (list (+ xs (* step delta)) y_loc)) (my_block_insert ball_name x_loc dot_rad) (setq step (1+ step)) ) ;;;loop for repeat ) ;;;DRAW_DOT ;;; ;;;GET_BALLNAME ;;; (defun get_ballname (colcode) (cond ((= colcode 0) "white_ball") ((= colcode 1) "red_ball") ((= colcode 5) "blue_ball") (t "white_ball") ) ) ;;;GET_BALLNAME ;;; ;;;DRAW_FENCE ;;; (defun draw_fence2 (num / mn mnp1 p0 p1 p2) ;;;draw the first dot and lines (setq mn (- num) mnp1 (+ mn 1) p0 (list mnp1 mnp1) p1 (list mn mnp1) p2 (list mn mn) ) ;;;draw a fence (command "_.pline" p0 p1 p2 "") ) ;;;DRAW_FENCE ;;; ;;; ;;;DRAW_TEXT ;;; (defun draw_text (num / xtext loc1 loc2 loc2 oddnum sum) (setq xtext (- num 0.6) loc1 (list xtext y_text1) loc2 (list xtext y_text2) loc3 (list xtext y_text3) oddnum (1- (* 2 num)) sum (* num num) ) (textdisplay (itoa num) loc1 0.35 0.) (textdisplay (itoa oddnum) loc2 0.35 0.) (textdisplay (itoa sum) loc3 0.35 0.) ) ;;;draw_text ;;; ;;; CIRCLE_DOT colored circle dot display ;;; (defun CIRCLE_DOT (layername color_id center_pt dot_radius) (setq cur_col (getvar "cecolor")) (setvar "cecolor" (itoa color_id)) (make_circle_1 layername color_id center_pt dot_radius) (command "_.hatch" "_solid" (entlast) "") (setvar "cecolor" cur_col) ) ;;;CIRCLE_DOT ;;; ;;;DRAW_FINAL_TEXT ;;; (defun draw_final_text2 ( / final_text1 final_text2 final_text3 final_loc1 final_loc2 final_loc3 xleft yup char_size mnp1 nm1 mnm1 lower_left lower_right upper_right plld plrd plrr purr ) (setq final_text1 "Sum of Odd integers" final_text2 " from 1 to (2N-1)" final_text3 "is (1/4)(2N x 2N) = N x N" xleft (- 2 nstep) yup nstep final_loc1 (list xleft (+ yup 3)) final_loc2 (list xleft (+ yup 2)) final_loc3 (list xleft (+ yup 0.5)) char_size 0.6 mnp1 (+ (- nstep) 1) nm1 (- nstep 1) mnm1 (- (- nstep) 1) lower_left (list mnp1 mnp1) lower_right (list nm1 mnp1) upper_right (list nm1 nm1) plld (list mnp1 mnm1) plrd (list nm1 mnm1) plrr (list (+ nm1 2) mnp1) purr (list (+ nm1 2) nm1) ) (textdisplay final_text1 final_loc1 char_size 0.) (textdisplay final_text2 final_loc2 char_size 0.) (textdisplay final_text3 final_loc3 char_size 0.) (make_line_1 "0" 8 lower_left plld) (make_line_1 "0" 8 lower_right plrd) (make_line_1 "0" 8 lower_right plrr) (make_line_1 "0" 8 upper_right purr) (make_line_1 "0" 8 plld plrd) (make_line_1 "0" 8 plrr purr) (textdisplay "2N" (list 0 mnm1) char_size 0.) (textdisplay "2N" (list (+ nm1 2) 0) char_size 0.) (command "_.zoom" "E") (command "_.regen") ) ;;;draw_final_text2