1 (in-package :avm2-compiler
)
2 ;;; sample from old version. works but needs more refactoring
4 (with-open-file (s "/tmp/roots.swf"
6 :element-type
'(unsigned-byte 8)
8 (with-compilation-to-stream s
("frame1" `((0 "testClass")))
10 (def-swf-class :test-class
"test-class" %flash.display
::sprite
(text)
14 (swf-defmemfun random-range
(a b
)
15 (+ a
(floor (random (- b a
)))))
17 (swf-defmemfun radians
(a)
18 (/ (* a %flash
:+pi
+) 180.0))
20 (swf-defmemfun i255
(a)
21 (max (min (floor (* a
256)) 255) 0))
23 (swf-defmemfun rgb
(r g b
)
24 (+ (* (i255 r
) 65536) (* (i255 g
) 256) (i255 b
)))
26 (swf-defmemfun rgba
(r g b a
)
27 (+ (* (i255 a
) 65536 256) (rgb r g b
)))
29 (swf-defmemfun main
(arg)
30 (let ((foo (%new %flash.text
:text-Field
0))
31 (canvas (%new %flash.display
:sprite
0)))
32 (setf (%flash.display
:width foo
) 200)
33 (setf (%flash.text
:auto-size foo
) "left")
34 (setf (%flash.text
:text-color foo
) (rgb 0.2 0.9 0.2 ))
35 (setf (%flash.text
:word-wrap foo
) t
)
36 (setf (%flash.text
:background foo
) t
)
37 (setf (%flash.text
:background-color foo
) (rgba 0.1 0.1 0.1 0.1))
39 (setf (%flash.text
:text foo
) (+ str
(%flash
:to-string
(vector 1 2 3)))))
40 (%flash.display
:add-child arg canvas
)
41 (%flash.display
:add-child arg foo
)
42 (%set-property this
:tc arg
)
43 (%set-property this
:canvas canvas
)
46 #+nil
(%flash.display
:add-event-listener arg
"enterFrame" (%asm
(:get-lex frame
)))
47 (%flash.display
:add-event-listener canvas
"click" (%asm
(:get-lex frame
)))))
49 (swf-defmacro with-fill
(gfx (color alpha
&key line-style
) &body body
)
52 `((%flash.display
:line-style
,gfx
,@line-style
)))
53 (%flash.display
:begin-fill
,gfx
,color
,alpha
)
55 (%flash.display
:end-fill
,gfx
)))
57 (swf-defmemfun frame
(evt)
58 (let* ((canvas (%get-property this
:canvas
))
59 (gfx (slot-value canvas
'%flash.display
:graphics
))
60 (matrix (%new %flash.geom
:Matrix
0)))
62 (setf (%flash.display
:opaque-background canvas
) #x0d0f00
)
63 (%flash.display
:clear gfx
)
64 (with-fill gfx
(#x202600
0.5)
65 (%flash.display
:draw-rect gfx
0 0 400 300 ))
66 (%flash.geom
:create-gradient-box matrix
68 (%flash.display
:begin-gradient-fill gfx
"radial"
69 (vector #x202600
#x0d0f00
) ;; colors
71 (vector 0 255) ;; ratios
73 (%flash.display
:draw-rect gfx
0 0 400 300 )
74 (%flash.display
:end-fill gfx
)
75 (%flash
:trace
"click")
76 (setf (%flash.text
:text
(text (%get-property this
:tc
)))
77 (+ "==" (root canvas
200 150 (random 360) 7 1.0 0.005 0)))
78 (%flash
:trace
"frame done")))
80 (swf-defmemfun root
(canvas x y angle depth alpha decay count
)
81 (let* ((s (* depth
0.5))
84 (gfx (slot-value canvas
'%flash.display
:graphics
)))
85 (dotimes (i (* depth
(random-range 10 20)))
86 (let* ((v (/ depth
5.0))
87 (color (rgb (- 0.8 (* v
0.25))
90 (setf alpha
(max 0.0 (- alpha
(* i decay
))))
92 ;; stop if alpha gets below 1/256 or so
94 (setf angle
(+ angle
(random-range -
60 60)))
95 (let ((dx (+ x
(* (cos (radians angle
)) w
)))
96 (dy (+ y
(* (sin (radians angle
)) w
))))
99 (with-fill gfx
(0 (* alpha
0.6) :line-style
(%flash
:+nan
+ 0 alpha
))
100 (%flash.display
:draw-circle gfx
(+ x s
1) (1- (+ y s
)) (/ w
3)))
102 ;; line segment to next position:
103 (with-fill gfx
(color (* alpha
0.6)
104 :line-style
(line-size color alpha
))
105 (%flash.display
:move-to gfx x y
)
106 (%flash.display
:line-to gfx dx dy
))
109 (with-fill gfx
(color (* alpha
0.5)
110 :line-style
((* 0.5 line-size
)
112 (%flash.display
:draw-circle gfx x y
(/ w
4)))
114 (when (and (> depth
0) (> (random 1.0) 0.85))
116 (root canvas x y
(+ angle
(random-range -
60 60))
117 (1- depth
) alpha decay
(1+ count
))))
121 (when (and (> depth
0) (> (random 1.0) 0.7))
122 (setf count
(root canvas x y angle
(1- depth
) alpha decay
(1+ count
)))))