1 (in-package :avm2-compiler
)
2 ;;; sample from old version. works but needs more refactoring
4 (define-special %to-double
(a)
9 (define-special %to-integer
(a)
14 (with-open-file (s "/tmp/roots.swf"
16 :element-type
'(unsigned-byte 8)
17 :if-exists
:supersede
)
18 (with-compilation-to-stream s
("frame1" `((0 "testClass")))
20 (def-swf-class :test-class
"test-class" flash.display
::sprite
()
24 (swf-defmemfun random-range
(a b
)
25 (+ a
(floor (random (- b a
)))))
27 #+nil
(swf-defmemfun radians
(a)
28 (/ (* a flash
::math.PI
) 180.0))
29 (swf-defmemfun radians
(a)
32 (swf-defmemfun i255
(a)
33 (flash::Math.max
(flash::Math.min
(floor (* a
256)) 255) 0))
35 (swf-defmemfun rgb
(r g b
)
36 (+ (* (i255 r
) 65536) (* (i255 g
) 256) (i255 b
)))
38 (swf-defmemfun rgba
(r g b a
)
39 (+ (* (i255 a
) 65536 256) (rgb r g b
)))
41 (swf-defmemfun main
(arg)
42 (let ((foo (%new flash.text
::Text-Field
0))
43 (canvas (%new flash.display
::Sprite
0)))
44 (%set-property foo
:width
200)
45 (%set-property foo
:auto-size
"left")
46 (%set-property foo
:text-color
(rgb 0.2 0.9 0.2 ))
47 (%set-property foo
:word-wrap
:true
)
48 (%set-property foo
:background
:true
)
49 (%set-property foo
:background-color
(rgba 0.1 0.1 0.1 0.1))
51 (%set-property foo
:text
(+ str
(%call-property
(%array
1 2 3) :to-string
))))
52 (:add-child arg canvas
)
54 (%set-property this
:canvas canvas
)
56 #+nil
(:add-event-listener arg
"enterFrame" (%get-lex
:frame
))
57 (:add-event-listener canvas
"click" (%asm
(:get-lex frame
)))))
59 (swf-defmacro with-fill
(gfx (color alpha
&key line-style
) &body body
)
62 `((:line-style
,gfx
,@line-style
)))
63 (:begin-fill
,gfx
,color
,alpha
)
67 (swf-defmemfun frame
(evt)
68 (let* ((canvas (%get-property this
:canvas
))
69 (gfx (:graphics canvas
))
70 (matrix (%new flash.geom
::Matrix
0)))
72 (%set-property canvas
:opaque-background
#x0d0f00
)
74 (with-fill gfx
(#x202600
0.5)
75 (:draw-rect gfx
0 0 400 300 ))
76 (:create-gradient-box matrix
78 (:begin-gradient-fill gfx
"radial"
79 (%array
#x202600
#x0d0f00
) ;; colors
81 (%array
0 255) ;; ratios
83 (:draw-rect gfx
0 0 400 300 )
85 (root canvas
200 150 (random 360) 7 1.0 0.005 )))
87 (swf-defmemfun root
(canvas x y angle depth alpha decay
)
88 (%set-local alpha
(%to-double alpha
))
89 (%set-local x
(%to-double x
))
90 (%set-local y
(%to-double y
))
91 (let* ((s (* depth
0.5))
94 (gfx (:graphics canvas
)))
95 (dotimes (i (%to-integer
(* depth
(random-range 10 20))))
96 (let* ((v (/ depth
5.0))
97 (color (rgb (- 0.8 (* v
0.25))
100 (%set-local alpha
(max 0.0 (- alpha
(* i decay
))))
102 ;; stop if alpha gets below 1/256 or so
103 (when (> alpha
0.004)
104 (%set-local angle
(+ angle
(random-range -
60 60)))
105 (let ((dx (+ x
(* (cos (radians angle
)) w
)))
106 (dy (+ y
(* (sin (radians angle
)) w
))))
109 (with-fill gfx
(0 (* alpha
0.6) :line-style
(:nan
0 alpha
))
110 (:draw-circle gfx
(+ x s
1) (1- (+ y s
)) (/ w
3)))
112 ;; line segment to next position:
113 (with-fill gfx
(color (* alpha
0.6)
114 :line-style
(line-size color alpha
))
116 (:line-to gfx dx dy
))
119 (with-fill gfx
(color (* alpha
0.5)
120 :line-style
((* 0.5 line-size
)
122 (:draw-circle gfx x y
(/ w
4)))
124 (when (and (> depth
0) (> (random 1.0) 0.85))
125 (root canvas x y
(+ angle
(random-range -
60 60))
126 (1- depth
) alpha decay
))
128 (%set-local y dy
)))))
130 (when (and (> depth
0) (> (random 1.0) 0.7))
131 (root canvas x y angle
(1- depth
) alpha decay
))))))