'Snowflake effect using transparency and rotozoom.
'Dav is trying to speed this up...
flakes = 400 'number of flakes
DIM SHARED flake.x
(flakes
), flake.y
(flakes
), flake.ys
(flakes
) 'x/y values, y speed DIM SHARED flake.r
(flakes
), flake.rs
(flakes
) 'rotation and rotation speed DIM SHARED flake.a
(flakes
), flake.s
(flakes
) 'alpha value & flake size
'generate random snowflake vaues
flake.x
(f
) = RND * _WIDTH + 30 'make randowm starting x position
CASE 2: flake.ys
(f
) = 1.5 CASE 4: flake.ys
(f
) = 2.5
flake.r
(f
) = RND * 360 'make random rotation sstarting value
flake.a
(f
) = 25 + (RND * 60) 'random alpha value
flake.s
(f
) = RND * 1.75 + .1 'randomw snowflake size
RotoZoom3 flake.x
(f
), flake.y
(f
), snow&
, flake.s
(f
), flake.s
(f
), _D2R(flake.r
(f
))
flake.r(f) = flake.r(f) + flake.rs(f) 'increase rotation
IF flake.r
(f
) > 360 THEN flake.r
(f
) = 1
flake.y(f) = flake.y(f) + flake.ys(f) 'lower y position
'if flake goes off screen, make a new flake above
' This assumes you have set your drawing location with _DEST or default to screen.
' X, Y - is where you want to put the middle of the image
' Image - is the handle assigned with _LOADIMAGE
' xScale, yScale - are shrinkage < 1 or magnification > 1 on the given axis, 1 just uses image size.
' These are multipliers so .5 will create image .5 size on given axis and 2 for twice image size.
' radianRotation is the Angle in Radian units to rotate the image
' note: Radian units for rotation because it matches angle units of other Basic Trig functions
' and saves a little time converting from degree.
' Use the _D2R() function if you prefer to work in degree units for angles.
DIM W&
, H&
, sinr!
, cosr!
, i&
, x2&
, y2&
' variables for image manipulation px(0) = -W& / 2: py(0) = -H& / 2 'left top corner
px(1) = -W& / 2: py(1) = H& / 2 ' left bottom corner
px(2) = W& / 2: py(2) = H& / 2 ' right bottom
px(3) = W& / 2: py(3) = -H& / 2 ' right top
sinr!
= SIN(-radianRotation
): cosr!
= COS(-radianRotation
) ' rotation helpers FOR i&
= 0 TO 3 ' calc new point locations with rotation and zoom x2& = xScale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = yScale * (py(i&) * cosr! - px(i&) * sinr!) + Y
px(i&) = x2&: py(i&) = y2&