[pal-cvs] CVS pal/examples

tneste tneste at common-lisp.net
Sat Jul 21 16:34:16 UTC 2007


Update of /project/pal/cvsroot/pal/examples
In directory clnet:/tmp/cvs-serv30525/examples

Modified Files:
	hares.lisp hello.lisp images.lisp polygons.lisp swarm.lisp 
	teddy.lisp 
Log Message:
Added automatic coercion of numerical arguments.

--- /project/pal/cvsroot/pal/examples/hares.lisp	2007/07/18 19:27:22	1.3
+++ /project/pal/cvsroot/pal/examples/hares.lisp	2007/07/21 16:34:16	1.4
@@ -17,11 +17,11 @@
   ((pos :accessor pos-of :initarg :pos :initform (v 0 0))
    (vel :accessor vel-of :initarg :vel :initform (v 0 0))
    (image :accessor image-of :initarg :image)
-   (angle :accessor angle-of :initarg :angle :initform 0f0)
+   (angle :accessor angle-of :initarg :angle :initform 0)
    (r :accessor r-of :initarg :r)
    (g :accessor g-of :initarg :g)
    (b :accessor b-of :initarg :b)
-   (scale :accessor scale-of :initform 1.0f0 :initarg :scale)
+   (scale :accessor scale-of :initform 1 :initarg :scale)
    (scaled :accessor scaled-of :initarg :scaled)))
 
 (defmethod initialize-instance :after ((sprite sprite) &key &allow-other-keys)
@@ -37,14 +37,14 @@
               :scale (scale-of s)))
 
 (defmethod act ((s sprite))
-  (setf (angle-of s) (mod (+ (angle-of s) 1f0) 360))
+  (setf (angle-of s) (mod (+ (angle-of s) 1) 360))
   (when (or (< (vx (pos-of s)) 0) (> (vx (pos-of s)) (get-screen-width)))
     (setf (vel-of s) (v (- (vx (vel-of s)))
                         (vy (vel-of s)))))
   (when (or (< (vy (pos-of s)) 0) (> (vy (pos-of s)) (get-screen-height)))
     (setf (vel-of s) (v (vx (vel-of s))
                         (- (vy (vel-of s))))))
-  (when (or (> (scale-of s) 2) (< (scale-of s) .5))
+  (when (or (> (scale-of s) 2) (< (scale-of s) 1/2))
     (setf (scaled-of s) (- (scaled-of s))))
   (incf (scale-of s) (scaled-of s))
   (v+! (pos-of s) (vel-of s)))
@@ -53,22 +53,21 @@
 
 
 (defun example ()
-  (with-pal (:width 800 :height 600 :fullscreenp t :fps 6000 :paths (merge-pathnames "examples/" pal::*pal-directory*))
+  (with-pal (:width 800 :height 600 :fullscreenp nil :fps 6000 :paths (merge-pathnames "examples/" pal::*pal-directory*))
     (setf *sprites* nil)
     (set-cursor nil)
-
     (dotimes (i 500)
       (make-instance 'sprite
                      :image (tag 'hare)
-                     :scaled (- (random .2f0) .1f0)
-                     :scale (+ (random 1.5f0) .5f0)
+                     :scaled (- (random .2) .1)
+                     :scale (+ (random 1.5) .5)
                      :r (random 255)
                      :g (random 255)
                      :b (random 255)
                      :pos (v (random (get-screen-width))
                              (random (get-screen-height)))
-                     :vel (v-random 3f0)
-                     :angle (random 360f0)))
+                     :vel (v-random 3.0)
+                     :angle (random 360.0)))
 
     (event-loop ()
 
--- /project/pal/cvsroot/pal/examples/hello.lisp	2007/07/18 21:29:55	1.7
+++ /project/pal/cvsroot/pal/examples/hello.lisp	2007/07/21 16:34:16	1.8
@@ -33,7 +33,7 @@
         (pal:draw-rectangle (pal:v 0 0)
                             (pal:get-screen-width) (pal:get-screen-height)
                             0 0 0 10)
-        (pal:with-transformation (:pos (pal:v 400 300) :angle (incf angle 1f0) :scale 3f0)
+        (pal:with-transformation (:pos (pal:v 400 300) :angle (incf angle 1) :scale 3)
           (pal:draw-text "Hello from PAL" (pal:v 0 0)))))))
 
 ;; (hello-2)
\ No newline at end of file
--- /project/pal/cvsroot/pal/examples/images.lisp	2007/07/19 18:51:37	1.4
+++ /project/pal/cvsroot/pal/examples/images.lisp	2007/07/21 16:34:16	1.5
@@ -30,7 +30,7 @@
 
 (with-pal (:paths (merge-pathnames "examples/" pal::*pal-directory*))
   (set-cursor (tag 'image-3)) ;; sets image-3 as a mouse cursor image
-  (let ((a 0f0))
+  (let ((a 0))
     (event-loop ()
       (draw-polygon* (list (v 0 0)
                            (v 800 0)
@@ -50,7 +50,7 @@
                     (v 0 0)
                     :valign :middle
                     :halign :middle
-                    :angle (incf a .1f0)))
+                    :angle (incf a .1)))
 
       ;; Press left mousebutton to capture part of the screen as a new cursor
       (when (key-pressed-p :key-mouse-1)
--- /project/pal/cvsroot/pal/examples/polygons.lisp	2007/07/18 21:29:56	1.5
+++ /project/pal/cvsroot/pal/examples/polygons.lisp	2007/07/21 16:34:16	1.6
@@ -4,7 +4,7 @@
 
 
 (with-pal (:paths (merge-pathnames "examples/" pal::*pal-directory*))
-  (let ((angle 0f0)
+  (let ((angle 0)
         (grid (load-image "bg2.png"))
         (plane (load-image "lego-plane.png" t))
         (slad (load-image "save_lisp.gif" t))
@@ -20,15 +20,15 @@
       ;; DRAW-IMAGE draw the whole image at given position. Keyword arguments can be given to define the
       ;; scale, angle and horizontal and vertical alignment ("hotspot")
 
-      (draw-arrow (v 700 500) (get-mouse-pos) 255 255 0 255 :size 5f0 :smoothp t)
+      (draw-arrow (v 700 500) (get-mouse-pos) 255 255 0 255 :size 5 :smoothp t)
       (draw-image plane
                   (v 700 500)
                   :halign :middle ;; Possible options are :left, :right and :middle. :left is the default.
                   :valign :bottom ;; -''- :top, :bottom, :middle. :top is the default.
                   :angle (v-angle (v-direction (v 700 500) (get-mouse-pos))) ;; angle in degrees
-                  :scale (* (v-distance (v 700 500) (get-mouse-pos)) .01f0))
+                  :scale (* (v-distance (v 700 500) (get-mouse-pos)) .01))
 
-      (draw-point (v 700 500) 255 0 0 255 :size 10f0 :smoothp t) ;; Draw a red point at the hotspot of previous image.
+      (draw-point (v 700 500) 255 0 0 255 :size 10 :smoothp t) ;; Draw a red point at the hotspot of previous image.
 
       ;; DRAW-POLYGON draw a polygon which vertexes are given as a list of VECs.
       ;; FILL is either nil, t or image that is used as a pattern.
@@ -51,7 +51,7 @@
                             )
                       255 0 0 255
                       :fill nil
-                      :size 5f0
+                      :size 5
                       :smoothp t
                       :absolutep nil))
 
@@ -83,7 +83,7 @@
       ;; DRAW-POLYGON* takes a list of vertex coordinates and as keyword arguments a list of texture coordinates(in pixels) for each vertex,
       ;; an image, and a list of lists of rgba values to use for each vertex.
 
-      (with-transformation (:pos (v 600 100) :angle (incf angle .5f0))
+      (with-transformation (:pos (v 600 100) :angle (incf angle .5))
         (draw-polygon* (list (v 00 10)
                              (v 100 200)
                              (v -100 200))
--- /project/pal/cvsroot/pal/examples/swarm.lisp	2007/07/16 20:46:24	1.4
+++ /project/pal/cvsroot/pal/examples/swarm.lisp	2007/07/21 16:34:16	1.5
@@ -1,4 +1,4 @@
-
+;; NOTE: the following example is intentionally slow and somewhat obfuscated
 
 (defun swarm ()
   (let ((vectors nil))
@@ -7,30 +7,30 @@
                                       (pal:message key)
                                       (when (eq key :key-mouse-1)
                                         (setf vectors (append vectors (loop repeat 50 collecting (cons (pal:get-mouse-pos)
-                                                                                                       (pal:v-random 5f0))))))))
+                                                                                                       (pal:v-random 5.0))))))))
         (pal:draw-rectangle (pal:v 0 0) 1024 768 0 0 0 128)
         (pal:with-blend (:color '(255 128 128 255))
           (pal:draw-text "Use left mousekey to add particles." (pal:v 0 0)))
 
         (let ((midpoint (pal:v/ (reduce 'pal:v+ vectors :initial-value (pal:v 0 0) :key 'car)
-                                (max 1f0
+                                (max 1
                                      (coerce (length vectors) 'single-float)))))
-          (pal:draw-point midpoint 255 0 0 255 :size 10f0 :smoothp t)
+          (pal:draw-point midpoint 255 0 0 255 :size 10 :smoothp t)
           (setf vectors (mapcar (lambda (v)
                                   (cons (pal:v+ (car v) (cdr v))
                                         (pal:v* (pal:v+ (cdr v)
                                                         (pal:v+ (pal:v/ (pal:v-direction midpoint (car v))
-                                                                        (max 1f0
+                                                                        (max 1
                                                                              (sqrt (pal:v-distance midpoint (car v)))))
                                                                 (pal:v-direction (car v) (pal:get-mouse-pos))
                                                                 ))
-                                                .90f0)))
+                                                .9)))
                                 vectors)))
         (pal:with-blend (:mode :additive)
           (dolist (v vectors)
             (pal:draw-arrow (car v)
                             (pal:v+ (car v) (cdr v))
                             10 7 0 255
-                            :size 10f0)))))))
+                            :size 10)))))))
 
 ;; (swarm)
\ No newline at end of file
--- /project/pal/cvsroot/pal/examples/teddy.lisp	2007/07/13 21:30:58	1.3
+++ /project/pal/cvsroot/pal/examples/teddy.lisp	2007/07/21 16:34:16	1.4
@@ -24,7 +24,7 @@
    (vel :accessor vel-of :initarg :vel :initform (v 0 0))
    (alt :accessor alt-of :initarg :alt :initform 10)
    (image :accessor image-of :initarg :image)
-   (angle :accessor angle-of :initarg :angle :initform 0f0)))
+   (angle :accessor angle-of :initarg :angle :initform 0)))
 
 (defmethod initialize-instance :after ((sprite sprite) &key &allow-other-keys)
   (push sprite *sprites*))
@@ -50,7 +50,7 @@
 
 (defmethod act ((s plane))
   (v+! (vel-of s)
-       (v* (v-direction (pos-of s) (get-mouse-pos)) .3f0))
+       (v* (v-direction (pos-of s) (get-mouse-pos)) .3))
   (setf (angle-of s) (v-angle (vel-of s)))
   (call-next-method))
 
@@ -61,13 +61,13 @@
   (:default-initargs :image (tag 'teddy)))
 
 (defmethod act ((s mutant-teddy))
-  (setf (angle-of s) (mod (+ (angle-of s) 1f0) 360))
+  (setf (angle-of s) (mod (+ (angle-of s) 1) 360))
   (call-next-method))
 
 
 
 (defun example ()
-  (with-pal (:width 800 :height 600 :fullscreenp nil :fps 60 :paths (merge-pathnames "examples/" pal::*pal-directory*))
+  (with-pal (:fullscreenp nil :width 800 :height 600 :fullscreenp nil :fps 60 :paths (merge-pathnames "examples/" pal::*pal-directory*))
     ;; inits PAL, the args used are the default values.
     ;; PATHS is a pathname or list of pathnames that PAL uses to find the resource files loaded with LOAD-* functions.
     ;; By default PATHS contains the PAL source directory and value of *default-pathname-defaults*
@@ -84,8 +84,8 @@
       (make-instance 'mutant-teddy
                      :pos (v (random (get-screen-width))
                              (random (get-screen-height)))
-                     :vel (v-random 3f0)
-                     :angle (random 360f0)))
+                     :vel (v-random 3.0)
+                     :angle (random 360.0)))
 
     (event-loop ()
       ;; simple event loop, no mouse-move, key-down etc. handlers defined, we'll handle input explicitly with TEST-KEYS.




More information about the Pal-cvs mailing list