Back in 2005, I created a stack called Flurry that demonstrated a method of creating a simulated snowfall effect. In the spirit of this season, I decided to revisit the stack and update it with some new visuals and custom controls. Clicking the lamppost toggles the snowfall, and lets you enjoy some snowy weather on your desktop.
 
To get the stack, execute the following line in your liveCode message box:


 
The main script of the stack is located in the card script. An interesting aspect of the stack is that all the snowflakes are drawn using a single polygon graphic object. By including empty lines among the points list of the polygon, you can create discontiguous polygon shapes within the same graphic. The runFlurry handler takes care of positioning each snowflake by first checking whether any point of a flake is at ground level (the height of the stack). If true, the flake’s new point locations are set to the top of the stack; if false, the points are increased by a random rate value that was assigned to the flake when the snow graphic is first created or modified. By using a range of rates, the snowfall effect has a more organic feel, and gets subtle sense of depth that would be absent if all the flakes fell at the same rate.
 
Use the sliders provided to modify the snowfall effect.
 

# MAIN SNOWFALL HANDLER
command runFlurry
   if not the uActive of me then exit runFlurry
   put height of me into theStackHeight
   repeat with N = 1 to theDensity
      put empty into theNewPoints
      put snowFlake[N][“points”] into theFlakePoints
      put snowFlake[N][“rate”] into theRate
      put false into groundFlag
      — CHECK IF FLAKE IS AT GROUND LEVEL
      repeat for each line theLine in theFlakePoints
         if item 2 of theLine > theStackHeight then
            put true into groundFlag
            exit repeat
         end if
      end repeat
      — POSITION FLAKE
      repeat for each line theLine in theFlakePoints
         put theLine after theNewPoints
         if item 2 of theLine is not empty then
            if groundFlag then
               add -theStackHeight to item 2 of last line of theNewPoints
            else add theRate to item 2 of last line of theNewPoints
         end if
         put cr after theNewPoints
      end repeat
      put theNewPoints into snowFlake[N][“points”]
      put theNewPoints & cr after theMasterPointList
   end repeat
   set points of grc “snow” to theMasterPointList
   send “runFlurry” to me in (the uThumbPos of control “delay_slider”) millisecs
end runFlurry

 
All visual elements in this stack were created using graphic objects. The lamppost is made from multiple polygon and roundrect objects, and the glass region of the lantern at the top of the lamppost was “knocked out” using the fillRule property of polygon graphics. The lamp glow is an oval graphic with a fillGradient applied that contains alpha transparency in the outer color. I thought the native sliders used in the original stack looked out of place, so I created some snowball sliders controlled by a behavior script that handles the thumb positioning and distance calculations.
 
Enjoy the stack, and Happy Holidays to all LC developers wherever you may be this time of year.
 

(Visited 369 times, 1 visits today)
4