[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error in my tiny test program

>From: cchien@gmuvax2.gmu.edu (Chang-Hong Chien)
>Message-Id: <9207250911.AA14774@gmuvax2.gmu.edu>
>To: info-mcl@cambridge.apple.com
>Subject: Error in my tiny test program
>Hi, Do anyone can help me to figure out what's wrong in my program.
>The program use the trap _paintroundrect. 
>I try to pass three variables, *height*, *v* and *h* to trap.
>Is there something I miss in this program ?
>The source code is :
>;;; "Drop a ball"
>(defparameter *w* (make-instance 'window))
>(defvar *v* 1)(defvar *h* 1)(defvar *height* 20)
>(defun visiable() (set-fore-color *w* *red-color*))
>(defun invisiable() (set-fore-color *w* *blue-color*))
>(while (not(< *height* 120))
>(If (oddp *h*) (visiable) (invisiable))
>(rlet((r :rect :top (+ 20 *V*) :left (+ 20 *h*):bottom (+ 30 *V*) :right (+ 30 *h*)))
>          (with-focused-view *w*
>            (#_paintroundrect r 130 130)))
>(setf *v* (+ *v* 31) *h* (+ *h* 51) init-height (+ init-height *v*)))
>(setf init-height 20)
>Ps. IN last 5th line at the end is ":right (+ 30 *h*)))
>Thanks advance for helping.
>							-Chien

Here's some code that does what I think you were trying to do...
Some tips:
 1) Try to use local variable (using LET) instead of lots of
    global variables.
 2) Create a function (DROP-BALL) that you can debug, instead 
    of trying to write your code at top level.
 3) I think the NOT in your WHILE test was the culprit here.
 4) You can also use (INCF var amount) instead of
    (SETF var (+ var amount))
 5) Use the indenting features of FRED to make your code more
    readable (use the Tab key and ctrl-option-q)
 6) Use comments to make your code more understandable.

(defparameter *window* (make-instance 'window))

(defun visible (window)
  (set-fore-color window *red-color*))

(defun invisible (window)
  (set-fore-color window *blue-color*))

(defun drop-ball (&optional (window *window*))
  (let ((v 1)               ; vertical position
        (h 1)               ; horizontal position
        (size 10)           ; size of ball
        (height 20))        ; initial height of ball
    (while (< height 120)
      (if (oddp h) 
        (visible window)
        (invisible window))
      (paint-oval window h v (+ h size) (+ v size))
      (setf v (+ v 3) 
            h (+ h 5)
            height (+ height v)))))