Menu

[r760]: / trunk / lispbuilder-sdl / examples / pixels.lisp  Maximize  Restore  History

Download this file

100 lines (78 with data), 3.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;;;; Demonstration/Test of using SDL (Simple Media Layer) library
;;;; using CFFI for foreign function interfacing...
;;;; (C)2006 Justin Heyes-Jones
;;;; see COPYING for license
(in-package #:sdl-examples)
(defun pixels-1 ()
(sdl:with-init ()
(sdl:window 640 480)
(setf (sdl:frame-rate) 0)
(sdl:with-events ()
(:quit-event () t)
(:idle ()
(sdl:draw-pixel-* (random 640) (random 480)
:color (sdl:color :r (random 255)
:g (random 255)
:b (random 255))
:surface sdl:*default-display*)
(sdl:update-display)))))
(defun pixels-2 ()
(let ((width 640) (height 480))
(sdl:with-init ()
(sdl:window width height)
(setf (sdl:frame-rate) 0)
(sdl:with-color (color (sdl:color))
(sdl:with-events ()
(:quit-event () t)
(:idle ()
(sdl-base::with-pixel (disp (sdl:fp sdl:*default-display*))
(sdl-base::write-pixel disp (random width) (random height)
(sdl:map-color (sdl:set-color-* color :r (random 255)
:g (random 255)
:b (random 255))
sdl:*default-display*)))
(sdl:update-display)))))))
(defun pixels-3 ()
(let ((width 640) (height 480))
(sdl:with-init ()
(sdl:window width height)
(setf (sdl:frame-rate) 0)
(sdl:with-rectangle (template (sdl:rectangle :w 1 :h 1))
(sdl:with-color (color (sdl:color))
(sdl:with-events ()
(:quit-event () t)
(:idle ()
(sdl:fill-surface (sdl:set-color-* color :r (random 255) :g (random 255) :b (random 255))
:template (sdl:set-rectangle-* template :x (random width) :y (random height))
:update t
:surface sdl:*default-display*))))))))
(defun pixels-4 ()
(let ((width 640) (height 480))
(sdl:with-init ()
(sdl:window width height)
(setf (sdl:frame-rate) 0)
(let ((color (sdl:color))
(template (sdl:rectangle :w 1 :h 1)))
(sdl:with-events ()
(:quit-event () t)
(:idle ()
(sdl:fill-surface (sdl:set-color-* color :r (random 255) :g (random 255) :b (random 255))
:template (sdl:set-rectangle-* template :x (random width) :y (random height))
:update t
:surface sdl:*default-display*)))))))
(defun pixels-5 ()
(sdl:with-init ()
(sdl:window 200 100)
(setf (sdl:frame-rate) 0)
;; Read the pixel at 0,0 and print the rgba value
(let ((col (sdl:read-pixel (sdl:point :x 0 :y 0) :surface sdl:*default-display*)))
(format t "READ: ~A, ~A, ~A, ~A~%" (sdl:r col) (sdl:g col) (sdl:b col) (sdl:a col)))
;; Write r,g,b to 0,0 and then read and print the rgba value
(sdl:draw-pixel (sdl:point)
:surface sdl:*default-display*
:color (sdl:color :r 255 :g 255 :b 255))
(let ((col (sdl:read-pixel (sdl:point :x 0 :y 0) :surface sdl:*default-display*)))
(format t "READ: ~A, ~A, ~A, ~A~%" (sdl:r col) (sdl:g col) (sdl:b col) (sdl:a col)))
(sdl:with-events ()
(:quit-event () t)
(:idle () (sdl:update-display)))))
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.