home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / lisp / mcl / 1079 < prev    next >
Encoding:
Text File  |  1992-07-25  |  2.8 KB  |  82 lines

  1. Path: sparky!uunet!olivea!apple!cambridge.apple.com!straz@cambridge.apple.com
  2. From: straz@cambridge.apple.com (Steve Strassmann)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Error in my tiny test program
  5. Message-ID: <9207252142.AA18739@cambridge.apple.com>
  6. Date: 25 Jul 92 23:19:16 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 68
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10. Full-Name: Steve Strassmann
  11. Original-To: cchien@gmuvax2.gmu.edu (Chang-Hong Chien)
  12. Original-Cc: info-mcl
  13.  
  14. >From: cchien@gmuvax2.gmu.edu (Chang-Hong Chien)
  15. >Message-Id: <9207250911.AA14774@gmuvax2.gmu.edu>
  16. >To: info-mcl@cambridge.apple.com
  17. >Subject: Error in my tiny test program
  18. >
  19. >Hi, Do anyone can help me to figure out what's wrong in my program.
  20. >The program use the trap _paintroundrect. 
  21. >I try to pass three variables, *height*, *v* and *h* to trap.
  22. >Is there something I miss in this program ?
  23. >
  24. >The source code is :
  25. >;;; "Drop a ball"
  26. >
  27. >(defparameter *w* (make-instance 'window))
  28. >(defvar *v* 1)(defvar *h* 1)(defvar *height* 20)
  29. >(defun visiable() (set-fore-color *w* *red-color*))
  30. >(defun invisiable() (set-fore-color *w* *blue-color*))
  31. >(while (not(< *height* 120))
  32. >(If (oddp *h*) (visiable) (invisiable))
  33. >(rlet((r :rect :top (+ 20 *V*) :left (+ 20 *h*):bottom (+ 30 *V*) :right (+ 30 *h*)))
  34. >          (with-focused-view *w*
  35. >            (#_paintroundrect r 130 130)))
  36. >(setf *v* (+ *v* 31) *h* (+ *h* 51) init-height (+ init-height *v*)))
  37. >(setf init-height 20)
  38. >
  39. >Ps. IN last 5th line at the end is ":right (+ 30 *h*)))
  40. >
  41. >Thanks advance for helping.
  42. >                            -Chien
  43. >
  44. >
  45.  
  46. Here's some code that does what I think you were trying to do...
  47. Some tips:
  48.  1) Try to use local variable (using LET) instead of lots of
  49.     global variables.
  50.  2) Create a function (DROP-BALL) that you can debug, instead 
  51.     of trying to write your code at top level.
  52.  3) I think the NOT in your WHILE test was the culprit here.
  53.  4) You can also use (INCF var amount) instead of
  54.     (SETF var (+ var amount))
  55.  5) Use the indenting features of FRED to make your code more
  56.     readable (use the Tab key and ctrl-option-q)
  57.  6) Use comments to make your code more understandable.
  58.  
  59.  
  60. ;------------
  61. (defparameter *window* (make-instance 'window))
  62.  
  63. (defun visible (window)
  64.   (set-fore-color window *red-color*))
  65.  
  66. (defun invisible (window)
  67.   (set-fore-color window *blue-color*))
  68.  
  69. (defun drop-ball (&optional (window *window*))
  70.   (let ((v 1)               ; vertical position
  71.         (h 1)               ; horizontal position
  72.         (size 10)           ; size of ball
  73.         (height 20))        ; initial height of ball
  74.     (while (< height 120)
  75.       (if (oddp h) 
  76.         (visible window)
  77.         (invisible window))
  78.       (paint-oval window h v (+ h size) (+ v size))
  79.       (setf v (+ v 3) 
  80.             h (+ h 5)
  81.             height (+ height v)))))
  82.