Ejemplo n.º 1
0
        private async Task PrepareRainday(CanvasAnimatedControl sender, string demo = "demo1",bool isFullScreen=false)
        {
          
            string imgPath = "Images/" + demo + ".jpg";
            imgbackground = await CanvasBitmap.LoadAsync(sender, imgPath, defaultDpi);

            blurEffect = new GaussianBlurEffect()
            {
                Source = imgbackground,
                BlurAmount = 4.0f, 
                BorderMode = EffectBorderMode.Soft
            };
            scalefactor =isFullScreen? (float)Math.Max(sender.Size.Width / imgbackground.Size.Width, sender.Size.Height / imgbackground.Size.Height) : (float)Math.Min(sender.Size.Width / imgbackground.Size.Width, sender.Size.Height / imgbackground.Size.Height);
            imgW = (float)imgbackground.Size.Width * scalefactor;
            imgH = (float)imgbackground.Size.Height * scalefactor;
            imgX = (float)(sender.Size.Width - imgW) / 2;
            imgY = (float)(sender.Size.Height - imgH) / 2;
            glassSurface = new CanvasRenderTarget(sender, imgW, imgH, defaultDpi);

            List<List<float>> pesets;


            if (demo == "demo1")
            {
                rainday = new RainyDay(sender, imgW, imgH, imgbackground)
                {
                    ImgSclaeFactor = scalefactor,
                    GravityAngle = (float)Math.PI / 2
                };
                pesets = new List<List<float>>() {

                new List<float> { 3, 3, 0.88f },
                new List<float> { 5, 5, 0.9f },
                new List<float> { 6, 2, 1 }
                };
            }
            else if (demo == "demo2")
            {
                rainday = new RainyDay(sender, imgW, imgH, imgbackground)
                {
                    ImgSclaeFactor = scalefactor,
                    GravityAngle = (float)Math.PI / 9
                };
                pesets = new List<List<float>>()
                {
                    new List<float> { 1, 0, 1000 },
                    new List<float> { 3, 3, 1 },
                };
            }
            else if (demo == "demo3")
            {
                rainday = new RainyDay(sender, imgW, imgH, imgbackground)
                {
                    ImgSclaeFactor = scalefactor,
                    CurrentGravity = RainyDay.GravityType.Gravity_None_Linear,
                    GravityAngle = (float)Math.PI / 2
                };
                pesets = new List<List<float>>() {
                new List<float> {0, 2, 200},
                new List<float> { 3, 3, 1 }

            };

            }
            else
            {
                rainday = new RainyDay(sender, imgW, imgH, imgbackground)
                {
                    ImgSclaeFactor = scalefactor,
                    GravityAngle = (float)Math.PI / 2,
                    CurrentGravity = RainyDay.GravityType.Gravity_None_Linear,
                    CurrentTrail = RainyDay.TrailType.Trail_Smudge
                };
                pesets = new List<List<float>>() {
                new List<float> { 3, 3, 0.1f }
            };
            }
            rainday.Rain(pesets, 100);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Clears the raindrop region.
 /// </summary>
 /// <param name="force">param force force stop</param>
 /// <returns>returns Boolean true if the animation is stopped</returns>
 public bool Clear(RainyDay rainyday, CanvasDrawingSession context, bool force=false)
 {
     context.Blend = CanvasBlend.Copy;
     context.FillRectangle(x - r - 1, y - r - 2, 2 * r + 2, 2 * r + 2, Colors.Transparent);
     context.Blend = CanvasBlend.SourceOver;
     if (force)
     {
         terminate = true;
         return true;
     }
     if (rainyday == null)
     {
         return true;
     }
     if ((y - r > rainyday.Height) || (x - r > rainyday.Width) || (x + r < 0))
     {
         // over edge so stop this drop
         return true;
     }
     return false;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Moves the raindrop to a new position according to the gravity.
        /// </summary>
        public bool Animate(RainyDay rainyday, CanvasDrawingSession context)
        {
            if (terminate)
            {
                return false;
            }
            var stopped = rainyday.Gravity(context, this);
            if (!stopped)
            {
                rainyday.Trail(context, this);
            }
            if (rainyday.EnableCollisions)
            {
                var collisions = rainyday.Matrix.Update(this, stopped);
                if (collisions != null)
                {
                    rainyday.Collision(context, this, collisions);
                }
            }
            return !stopped || terminate;

        }
Ejemplo n.º 4
0
 /// <summary>
 /// Draws a raindrop on canvas at the current position.
 /// </summary>
 public void Draw(RainyDay rainyday, CanvasDrawingSession context)
 {
     float orgR = r;
     r = 0.95f * r;
     if (r < 3)
     {
         clipGeo = CanvasGeometry.CreateCircle(context, new Vector2(x, y), r);
     }
     else if (colliding != null || yspeed > 2)
     {
         if (colliding != null)
         {
             var collider = colliding;
             r = 1.001f * (r > collider.r ? r : collider.r);
             x += (collider.x - x);
             colliding = null;
         }
         float yr = 1 + 0.1f * yspeed;
         using (CanvasPathBuilder path = new CanvasPathBuilder(context))
         {
             path.BeginFigure(x - r / yr, y);
             path.AddCubicBezier(new Vector2(x - r, y - r * 2), new Vector2(x + r, y - r * 2), new Vector2(x + r / yr, y));
             path.AddCubicBezier(new Vector2(x + r, y + yr * r), new Vector2(x - r, y + yr * r), new Vector2(x - r / yr, y));
             path.EndFigure(CanvasFigureLoop.Closed);
             clipGeo = CanvasGeometry.CreatePath(path);
         }
     }
     else
     {
         clipGeo = CanvasGeometry.CreateCircle(context, new Vector2(x, y), 0.9f * r);
     }
     r = orgR;
     if (rainyday.Reflection != null)
     {
         using (context.CreateLayer(1, clipGeo))
         {
             rainyday.Reflection(context, this);
         }
     }
     if (clipGeo != null)
     {
         clipGeo.Dispose();
     }
 }