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
()
14 (swf-defmemfun random-range
(a b
)
15 (+ a
(floor (random (- b a
)))))
17 #+nil
(swf-defmemfun radians
(a)
18 (/ (* a flash
::math.PI
) 180.0))
19 (swf-defmemfun radians
(a)
22 (swf-defmemfun i255
(a)
23 (max (min (floor (* a
256)) 255) 0))
25 (swf-defmemfun rgb
(r g b
)
26 (+ (* (i255 r
) 65536) (* (i255 g
) 256) (i255 b
)))
28 (swf-defmemfun rgba
(r g b a
)
29 (+ (* (i255 a
) 65536 256) (rgb r g b
)))
31 (swf-defmemfun main
(arg)
32 (let ((foo (%new flash.text
::Text-Field
0))
33 (canvas (%new flash.display
::Sprite
0)))
34 (%set-property foo
:width
200)
35 (%set-property foo
:auto-size
"left")
36 (%set-property foo
:text-color
(rgb 0.2 0.9 0.2 ))
37 (%set-property foo
:word-wrap
:true
)
38 (%set-property foo
:background
:true
)
39 (%set-property foo
:background-color
(rgba 0.1 0.1 0.1 0.1))
41 (%set-property foo
:text
(+ str
(:to-string
(vector 1 2 3)))))
42 (:add-child arg canvas
)
44 (%set-property this
:canvas canvas
)
46 #+nil
(:add-event-listener arg
"enterFrame" (%get-lex
:frame
))
47 (:add-event-listener canvas
"click" (%asm
(:get-lex frame
)))))
49 (swf-defmacro with-fill
(gfx (color alpha
&key line-style
) &body body
)
52 `((:line-style
,gfx
,@line-style
)))
53 (:begin-fill
,gfx
,color
,alpha
)
57 (swf-defmemfun frame
(evt)
58 (let* ((canvas (%get-property this
:canvas
))
59 (gfx (:graphics canvas
))
60 (matrix (%new flash.geom
::Matrix
0)))
62 (%set-property canvas
:opaque-background
#x0d0f00
)
64 (with-fill gfx
(#x202600
0.5)
65 (:draw-rect gfx
0 0 400 300 ))
66 (:create-gradient-box matrix
68 (:begin-gradient-fill gfx
"radial"
69 (vector #x202600
#x0d0f00
) ;; colors
71 (vector 0 255) ;; ratios
73 (:draw-rect gfx
0 0 400 300 )
75 (root canvas
200 150 (random 360) 7 1.0 0.005 )))
77 (swf-defmemfun root
(canvas x y angle depth alpha decay
)
78 (let* ((s (* depth
0.5))
81 (gfx (:graphics canvas
)))
82 (dotimes (i (* depth
(random-range 10 20)))
83 (let* ((v (/ depth
5.0))
84 (color (rgb (- 0.8 (* v
0.25))
87 (setf alpha
(max 0.0 (- alpha
(* i decay
))))
89 ;; stop if alpha gets below 1/256 or so
91 (setf angle
(+ angle
(random-range -
60 60)))
92 (let ((dx (+ x
(* (cos (radians angle
)) w
)))
93 (dy (+ y
(* (sin (radians angle
)) w
))))
96 (with-fill gfx
(0 (* alpha
0.6) :line-style
(:nan
0 alpha
))
97 (:draw-circle gfx
(+ x s
1) (1- (+ y s
)) (/ w
3)))
99 ;; line segment to next position:
100 (with-fill gfx
(color (* alpha
0.6)
101 :line-style
(line-size color alpha
))
103 (:line-to gfx dx dy
))
106 (with-fill gfx
(color (* alpha
0.5)
107 :line-style
((* 0.5 line-size
)
109 (:draw-circle gfx x y
(/ w
4)))
111 (when (and (> depth
0) (> (random 1.0) 0.85))
112 (root canvas x y
(+ angle
(random-range -
60 60))
113 (1- depth
) alpha decay
))
117 (when (and (> depth
0) (> (random 1.0) 0.7))
118 (root canvas x y angle
(1- depth
) alpha decay
))))))