亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Silverlight實(shí)現(xiàn)星星閃爍動(dòng)畫

 更新時(shí)間:2018年07月04日 11:56:56   作者:東邪獨(dú)孤  
這篇文章主要為大家詳細(xì)介紹了Silverlight實(shí)現(xiàn)星星閃爍動(dòng)畫,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Silverlight實(shí)現(xiàn)星星閃爍動(dòng)畫展示的具體代碼,供大家參考,具體內(nèi)容如下

原理很簡(jiǎn)單,生成1000個(gè)圓,從隨機(jī)數(shù)來布置它們的位置,通過動(dòng)畫來處理它們的透明度,動(dòng)畫時(shí)長(zhǎng)也是隨機(jī)生成。 

1、創(chuàng)建圖形數(shù)組并設(shè)置背景透明,漸變筆觸,大小等,而后加入到Grid元素的子元素集中;
2、創(chuàng)建動(dòng)畫時(shí)間線;
3、加載完成后播放動(dòng)畫;
4、每一輪動(dòng)畫播放完畢后,重新隨機(jī)生成一下圖形的Margin,動(dòng)畫的時(shí)間長(zhǎng)度也是隨機(jī)生成。

代碼: 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes; 
 
namespace RandEllipseSample
{
  public partial class MainPage : UserControl
  {
    int shapesCount = 500; //圖形數(shù)組的容量
    //隨機(jī)大小的上限
    int theMaxW = 1300;
    int theMaxH = 720;
    Random rand = null;
    Storyboard story = null;
    Ellipse[] myShapes = null;
    public MainPage()
    {
      InitializeComponent();
      rand = new Random();
      story = new Storyboard();
      story.Completed += new EventHandler(story_Completed);
      InitShapes();
      InitAnimation();
      //加載完成后馬上播放動(dòng)畫
      this.Loaded += new RoutedEventHandler(MainPage_Loaded);
    } 
 
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
      story.Begin();
    } 
 
    void story_Completed(object sender, EventArgs e)
    {
      for (int x = 0; x < shapesCount; x++)
      {
        myShapes[x].Margin = new Thickness(Convert.ToDouble(rand.Next(0, theMaxW)), Convert.ToDouble(rand.Next(0, theMaxH)), 0, 0);
      }
      InitAnimation();
    } 
 
    /// <summary>
    /// 初始化形狀數(shù)組
    /// </summary>
    private void InitShapes()
    {
      myShapes = new Ellipse[shapesCount];
      //實(shí)例化所有成員
      for (int n = 0; n < shapesCount; n++)
      {
        myShapes[n] = new Ellipse();
        myShapes[n].Fill = new SolidColorBrush(Colors.Transparent);
        myShapes[n].StrokeThickness = 2d;
        //筆觸為線性漸變
        LinearGradientBrush gBrush = new LinearGradientBrush();
        gBrush.StartPoint = new Point(0, 0);
        gBrush.EndPoint = new Point(1, 1);
        gBrush.GradientStops.Add(new GradientStop()
        {
          Color = Colors.Yellow,
          Offset = 0
        });
        gBrush.GradientStops.Add(new GradientStop()
        {
          Color = Colors.Red,
          Offset = 0.25
        });
        gBrush.GradientStops.Add(new GradientStop()
        {
          Color = Colors.White,
          Offset = 0.5
        });
        gBrush.GradientStops.Add(new GradientStop()
        {
          Color = Colors.Blue,
          Offset = 0.75
        });
        myShapes[n].Stroke = gBrush;
        //位置
        myShapes[n].Margin = new Thickness(Convert.ToDouble(rand.Next(0,theMaxW)), Convert.ToDouble(rand.Next(0,theMaxH)), 0, 0);
        //大小
        myShapes[n].Width = 10;
        myShapes[n].Height = 10;
        myShapes[n].HorizontalAlignment = HorizontalAlignment.Left;
        myShapes[n].VerticalAlignment = VerticalAlignment.Top;
        //加入可視化樹
        this.LayoutRoot.Children.Add(myShapes[n]);
      }
    } 
 
    /// <summary>
    /// 初始化動(dòng)畫
    /// </summary>
    private void InitAnimation()
    {
      story.Children.Clear();
      for (int i = 0; i < shapesCount; i++)
      {
        int mSecond = rand.Next(0, 5);
        //透明度
        DoubleAnimation opacityAnimate = new DoubleAnimation();
        opacityAnimate.From = 1.0;
        opacityAnimate.To = 0.0;
        Storyboard.SetTarget(opacityAnimate, myShapes[i]);
        Storyboard.SetTargetProperty(opacityAnimate,
          new PropertyPath("Opacity"));
        opacityAnimate.Duration = new Duration(TimeSpan.FromSeconds(mSecond));
        opacityAnimate.RepeatBehavior = RepeatBehavior.Forever; 
 
        //將時(shí)間線添加到情節(jié)摘要
        story.Children.Add(opacityAnimate);
      }
    }
  }
}

效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C# String Replace高效的實(shí)例方法

    C# String Replace高效的實(shí)例方法

    C# String Replace高效的實(shí)例方法,需要的朋友可以參考一下
    2013-05-05
  • C#實(shí)現(xiàn)裝箱與拆箱操作簡(jiǎn)單實(shí)例

    C#實(shí)現(xiàn)裝箱與拆箱操作簡(jiǎn)單實(shí)例

    這篇文章主要介紹了C#實(shí)現(xiàn)裝箱與拆箱操作,對(duì)于新手理解裝箱與拆箱有一定的幫助,需要的朋友可以參考下
    2014-07-07
  • C#實(shí)現(xiàn)文件篩選讀取并翻譯的自動(dòng)化工具

    C#實(shí)現(xiàn)文件篩選讀取并翻譯的自動(dòng)化工具

    這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)文件篩選及讀取內(nèi)容,并翻譯的自動(dòng)化工具,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下
    2023-03-03
  • c#獲取當(dāng)前年的周數(shù)及當(dāng)前月的天數(shù)示例代碼

    c#獲取當(dāng)前年的周數(shù)及當(dāng)前月的天數(shù)示例代碼

    本篇文章主要是對(duì)c#獲取當(dāng)前年的周數(shù)及當(dāng)前月的天數(shù)示例代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助
    2014-01-01
  • C#中截取字符串的的基本方法詳解

    C#中截取字符串的的基本方法詳解

    這篇文章主要介紹了C#中截取字符串的的基本方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • c#中的正則表達(dá)式和日期的使用示例

    c#中的正則表達(dá)式和日期的使用示例

    在?C#?中,正則表達(dá)式(Regular?Expressions)是一種強(qiáng)大的文本處理工具,用于執(zhí)行各種字符串搜索、替換和驗(yàn)證任務(wù),這篇文章主要介紹了c#中的正則表達(dá)式和日期的使用示例,需要的朋友可以參考下
    2024-07-07
  • C#異步調(diào)用的好處和方法分享

    C#異步調(diào)用的好處和方法分享

    我們要明確,為什么要進(jìn)行異步回調(diào)?眾所周知,普通方法運(yùn)行,是單線程的,如果中途有大型操作(如:讀取大文件,大批量操作數(shù)據(jù)庫,網(wǎng)絡(luò)傳輸?shù)龋?,都?huì)導(dǎo)致方法阻塞,表現(xiàn)在界面上就是,程序卡或者死掉,界面元素不動(dòng)了,不響應(yīng)了
    2012-04-04
  • C#類繼承中構(gòu)造函數(shù)的執(zhí)行序列示例詳解

    C#類繼承中構(gòu)造函數(shù)的執(zhí)行序列示例詳解

    這篇文章主要給大家介紹了關(guān)于C#類繼承中構(gòu)造函數(shù)的執(zhí)行序列的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-09-09
  • C#線程開發(fā)之System.Thread類詳解

    C#線程開發(fā)之System.Thread類詳解

    本文詳細(xì)講解了C#線程開發(fā)之System.Thread類,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • c#中string的特性介紹及注意事項(xiàng)小結(jié)

    c#中string的特性介紹及注意事項(xiàng)小結(jié)

    這篇文章主要給大家介紹了關(guān)于c#中string的特性介紹及注意事項(xiàng)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用c#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11

最新評(píng)論