Animated Rising Sun

Here is a small and simple class I wrote this morning to create an animated rising sun. You can configure the number of segments and the size very easily.

risingsun

  1.  
  2. package
  3. {
  4. import flash.display.Sprite;
  5. import flash.events.Event;
  6.  
  7. public class RisingSun extends Sprite
  8. {
  9. private var _segments :Number = 40;
  10. private var _rad :Number = 730;
  11.  
  12. public function RisingSun()
  13. {
  14. super();
  15.  
  16. x = 364;
  17. y = 45;
  18.  
  19. graphics.clear();
  20. graphics.beginFill(0xFF0000, 0.8);
  21. graphics.drawCircle(0, 0, _rad);
  22. graphics.endFill();
  23.  
  24. var _angle:Number = Math.PI / _segments;
  25. var a:Number = _angle;
  26.  
  27. for (var i:Number = 0; i < _segments; i++)
  28. {
  29. var s:Sprite = new Sprite();
  30. s.graphics.clear();
  31. s.graphics.beginFill(0xCC0000, 0.5);
  32. s.graphics.lineTo(Math.cos(a)*_rad, Math.sin(a)*_rad);
  33. a += _angle;
  34. s.graphics.lineTo(Math.cos(a)*_rad, Math.sin(a)*_rad);
  35. s.graphics.lineTo(0, 0);
  36. s.graphics.endFill();
  37. a += _angle;
  38. addChild(s);
  39. }
  40. addEventListener(Event.ENTER_FRAME, _frame);
  41. }
  42.  
  43. private function _frame(e:Event):void
  44. {
  45. rotation += 0.5;
  46. }
  47. }
  48. }
  49.  

Leave a Reply