[pal-cvs] CVS pal/examples

tneste tneste at common-lisp.net
Mon Jul 16 14:44:12 UTC 2007


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

Added Files:
	images.lisp utils.lisp 
Log Message:
Added image-from-array and image-from-fn


--- /project/pal/cvsroot/pal/examples/images.lisp	2007/07/16 14:44:12	NONE
+++ /project/pal/cvsroot/pal/examples/images.lisp	2007/07/16 14:44:12	1.1
(defpackage :image-tests
  (:use :cl :pal))
(in-package :image-tests)


(define-tags image-1 (image-from-fn 255 255 t
                                    (lambda (x y)
                                      (values x 0 x y)))
             image-2 (image-from-array nil #2A(((255 255 255 128) (0 0 0) (255 255 255))
                                               ((255 255 255) (255 255 0) (255 255 255))
                                               ((255 255 255) (0 0 0) (255 255 255 128)))))



(with-pal ()
  (set-cursor (tag 'image-1))
  (event-loop ()
    (clear-screen 50 100 255)
    (with-transformation (:scale 100f0)
      (draw-image (tag 'image-2) (v 0 0)))))--- /project/pal/cvsroot/pal/examples/utils.lisp	2007/07/16 14:44:12	NONE
+++ /project/pal/cvsroot/pal/examples/utils.lisp	2007/07/16 14:44:12	1.1

;; Some examples of the misc macros and utility functions in PAL


;; Get path to applications user specific data directory. Application name is taken from the :title argument
;; to OPEN/WITH-PAL so be careful to set it to something sensible.
;; If the directory doesn't exists it is created, the exact location of the files is OS dependant.

(pal:get-application-folder)
(pal:get-application-file "saved_game.data")


;; DO-N is like DO-TIMES but it iterates over the cartesian product of its arguments. Handy when working with tilemaps etc.

(pal:do-n (i 3 j 3 k 3)
  (format t "~a ~a ~a~%" i j k))


;; RANDOMLY evaluates its body, umm, randomly.

(pal:randomly 10
  (print "I'm a lucky s-expression!")) ;; has a 1/10 chance to get evaluated


;; CURRY, your average currying macro

(mapcar (pal:curry '* 2 2) '(1 2 3 4 5))


;; RELT returns a random element in a sequence

(pal:relt (mapcar (pal:curry '* 2 2) '(1 2 3 4 5)))


;; CLAMPs a value between min and max

(pal:clamp 10 (random 30) 20)


;; DATA-PATH searches for a file from the PATHS given to PAL and returns the first match

(pal:data-path "foo.png")




More information about the Pal-cvs mailing list