[WPF]雪を降らす

 

WPFを使って画面中に雪を降らせるアプリケーションを作成します。
WPF 3D の習作です。
"TranslateTransform3D" と "DoubleAnimationUsingKeyFrames" を使って雪が降るアニメーションを実現します。

 

[実行結果1:YouTubeより]

 

[実行結果2:静止画]

 

[プログラムソース "MainWindow.xaml"]
<Window x:Class="SnowFall.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SnowFall"
        mc:Ignorable="d"
        Title="SnowFall" Height="600" Width="800" Loaded="Window_Loaded" Background="Black">
    <Grid>
        <Viewport3D>
            <Viewport3D.Effect>
                <BlurEffect Radius="5"/>
            </Viewport3D.Effect>
            
            <Viewport3D.Camera>
                <PerspectiveCamera x:Name="Target_CameraOR6" Position="0,-5,5"  LookDirection="0,2,-1"
                    UpDirection="0,1,0" FieldOfView="50" NearPlaneDistance="0.1" FarPlaneDistance="50"/>
            </Viewport3D.Camera>

            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <Model3DGroup x:Name="Scene">
                        <AmbientLight Color="#7777FF"/>
                        <DirectionalLight Color="White" Direction="-0.612372,-0.5,-0.612372"/>
                        <DirectionalLight Color="White" Direction="0.612372,-0.5,-0.612372"/>
                        
                        <!-- この"Model3DG"の配下にたくさんの雪のモデルがぶら下がります -->
                        <Model3DGroup x:Name="Model3DG"/>

                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </Viewport3D>
        
    </Grid>
</Window>

 

[プログラムソース "MainWindow.xaml.cs"]
using System.Windows;
using System.Windows.Media;

namespace SnowFall
{
    public partial class MainWindow : Window
    {

        private const int _MaxSnow = 100;
        private Snow[] _snow = new Snow[_MaxSnow];

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            CreateSnow();
        }

        private void CreateSnow()
        {
            for ( int i=0; i<_MaxSnow; ++i)
            {
                _snow[i] = SnowFactory.CreateSnowBall(Colors.White, 0.2);
                Model3DG.Children.Add(_snow[i].snowBall);

                _snow[i].BeginAnimation();
            }
        }
    }
}

 

[プログラムソース "SnowFall.cs"]
using System;                           // Random
using System.Windows.Media;             // Color
using System.Windows.Media.Animation;   // DoubleAnimationUsingKeyFrames, LinearDoubleKeyFrame
using System.Windows.Media.Media3D;     // GeometryModel3D, Transform3DGroup, ScaleTransform3D, TranslateTransform3D, RotateTransform3D

namespace SnowFall
{
    public class Snow
    {
        public GeometryModel3D snowBall = new GeometryModel3D();

        private DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames();
        private TranslateTransform3D t1 { get; set; }
        private TranslateTransform3D t2 { get; set; }
        private static Random _rnd = new Random();


        public Snow()
            : this(Colors.White, 0.1)
        {
        }

        public Snow(Color col, double size)
        {
            snowBall.Geometry = GetBall();
            snowBall.Transform = GetTransform(size);
            snowBall.Material = new DiffuseMaterial(new SolidColorBrush(col));

            CreateAnimation();
        }

        public void BeginAnimation()
        {
            t2.BeginAnimation(TranslateTransform3D.OffsetYProperty, daukf);
        }



        private Transform3DGroup GetTransform(double size)
        {
            Transform3DGroup t3dg = new Transform3DGroup();
            ScaleTransform3D s01 = new ScaleTransform3D(size, size, size);
            RotateTransform3D r01 = new RotateTransform3D();
            // TranslateTransform3D t1 = new TranslateTransform3D(GetRnd(50) - 25, 25, GetRnd(50) - 25);
            t1 = new TranslateTransform3D(GetRnd(100) - 50, 25, GetRnd(100) - 50);
            t2 = new TranslateTransform3D(0, 50, 0);

            t3dg.Children.Add(t1);
            t3dg.Children.Add(s01);
            t3dg.Children.Add(r01);
            t3dg.Children.Add(t2);

            return t3dg;
        }

        private static MeshGeometry3D GetBall()
        {
            MeshGeometry3D ball = new MeshGeometry3D();

            ball.Positions = new Point3DCollection { new Point3D(0.09012, 0.490393, 0.0373289), new Point3D(0.0975452, 0.490393, 0), new Point3D(0, 0.5, 0), new Point3D(0.0689748, 0.490393, 0.0689748), new Point3D(0.0373289, 0.490393, 0.09012), new Point3D(5.97292e-018, 0.490393, 0.0975452), new Point3D(-0.0373289, 0.490393, 0.09012), new Point3D(-0.0689748, 0.490393, 0.0689748), new Point3D(-0.09012, 0.490393, 0.0373289), new Point3D(-0.0975452, 0.490393, 1.19458e-017), new Point3D(-0.09012, 0.490393, -0.0373289), new Point3D(-0.0689748, 0.490393, -0.0689748), new Point3D(-0.0373289, 0.490393, -0.09012), new Point3D(-1.79188e-017, 0.490393, -0.0975452), new Point3D(0.0373289, 0.490393, -0.09012), new Point3D(0.0689748, 0.490393, -0.0689748), new Point3D(0.09012, 0.490393, -0.0373289), new Point3D(0.176777, 0.46194, 0.0732233), new Point3D(0.191342, 0.46194, 0), new Point3D(0.135299, 0.46194, 0.135299), new Point3D(0.0732233, 0.46194, 0.176777), new Point3D(1.17163e-017, 0.46194, 0.191342), new Point3D(-0.0732233, 0.46194, 0.176777), new Point3D(-0.135299, 0.46194, 0.135299), new Point3D(-0.176777, 0.46194, 0.0732233), new Point3D(-0.191342, 0.46194, 2.34326e-017), new Point3D(-0.176777, 0.46194, -0.0732233), new Point3D(-0.135299, 0.46194, -0.135299), new Point3D(-0.0732233, 0.46194, -0.176777), new Point3D(-3.51489e-017, 0.46194, -0.191342), new Point3D(0.0732233, 0.46194, -0.176777), new Point3D(0.135299, 0.46194, -0.135299), new Point3D(0.176777, 0.46194, -0.0732233), new Point3D(0.25664, 0.415735, 0.106304), new Point3D(0.277785, 0.415735, 0), new Point3D(0.196424, 0.415735, 0.196424), new Point3D(0.106304, 0.415735, 0.25664), new Point3D(1.70094e-017, 0.415735, 0.277785), new Point3D(-0.106304, 0.415735, 0.25664), new Point3D(-0.196424, 0.415735, 0.196424), new Point3D(-0.25664, 0.415735, 0.106304), new Point3D(-0.277785, 0.415735, 3.40189e-017), new Point3D(-0.25664, 0.415735, -0.106304), new Point3D(-0.196424, 0.415735, -0.196424), new Point3D(-0.106304, 0.415735, -0.25664), new Point3D(-5.10283e-017, 0.415735, -0.277785), new Point3D(0.106304, 0.415735, -0.25664), new Point3D(0.196424, 0.415735, -0.196424), new Point3D(0.25664, 0.415735, -0.106304), new Point3D(0.326641, 0.353553, 0.135299), new Point3D(0.353553, 0.353553, 0), new Point3D(0.25, 0.353553, 0.25), new Point3D(0.135299, 0.353553, 0.326641), new Point3D(2.16489e-017, 0.353553, 0.353553), new Point3D(-0.135299, 0.353553, 0.326641), new Point3D(-0.25, 0.353553, 0.25), new Point3D(-0.326641, 0.353553, 0.135299), new Point3D(-0.353553, 0.353553, 4.32978e-017), new Point3D(-0.326641, 0.353553, -0.135299), new Point3D(-0.25, 0.353553, -0.25), new Point3D(-0.135299, 0.353553, -0.326641), new Point3D(-6.49467e-017, 0.353553, -0.353553), new Point3D(0.135299, 0.353553, -0.326641), new Point3D(0.25, 0.353553, -0.25), new Point3D(0.326641, 0.353553, -0.135299), new Point3D(0.384089, 0.277785, 0.159095), new Point3D(0.415735, 0.277785, 0), new Point3D(0.293969, 0.277785, 0.293969), new Point3D(0.159095, 0.277785, 0.384089), new Point3D(2.54564e-017, 0.277785, 0.415735), new Point3D(-0.159095, 0.277785, 0.384089), new Point3D(-0.293969, 0.277785, 0.293969), new Point3D(-0.384089, 0.277785, 0.159095), new Point3D(-0.415735, 0.277785, 5.09128e-017), new Point3D(-0.384089, 0.277785, -0.159095), new Point3D(-0.293969, 0.277785, -0.293969), new Point3D(-0.159095, 0.277785, -0.384089), new Point3D(-7.63692e-017, 0.277785, -0.415735), new Point3D(0.159095, 0.277785, -0.384089), new Point3D(0.293969, 0.277785, -0.293969), new Point3D(0.384089, 0.277785, -0.159095), new Point3D(0.426777, 0.191342, 0.176777), new Point3D(0.46194, 0.191342, 0), new Point3D(0.326641, 0.191342, 0.326641), new Point3D(0.176777, 0.191342, 0.426777), new Point3D(2.82857e-017, 0.191342, 0.46194), new Point3D(-0.176777, 0.191342, 0.426777), new Point3D(-0.326641, 0.191342, 0.326641), new Point3D(-0.426777, 0.191342, 0.176777), new Point3D(-0.46194, 0.191342, 5.65713e-017), new Point3D(-0.426777, 0.191342, -0.176777), new Point3D(-0.326641, 0.191342, -0.326641), new Point3D(-0.176777, 0.191342, -0.426777), new Point3D(-8.4857e-017, 0.191342, -0.46194), new Point3D(0.176777, 0.191342, -0.426777), new Point3D(0.326641, 0.191342, -0.326641), new Point3D(0.426777, 0.191342, -0.176777), new Point3D(0.453064, 0.0975452, 0.187665), new Point3D(0.490393, 0.0975452, 0), new Point3D(0.34676, 0.0975452, 0.34676), new Point3D(0.187665, 0.0975452, 0.453064), new Point3D(3.00279e-017, 0.0975452, 0.490393), new Point3D(-0.187665, 0.0975452, 0.453064), new Point3D(-0.34676, 0.0975452, 0.34676), new Point3D(-0.453064, 0.0975452, 0.187665), new Point3D(-0.490393, 0.0975452, 6.00558e-017), new Point3D(-0.453064, 0.0975452, -0.187665), new Point3D(-0.34676, 0.0975452, -0.34676), new Point3D(-0.187665, 0.0975452, -0.453064), new Point3D(-9.00837e-017, 0.0975452, -0.490393), new Point3D(0.187665, 0.0975452, -0.453064), new Point3D(0.34676, 0.0975452, -0.34676), new Point3D(0.453064, 0.0975452, -0.187665), new Point3D(0.46194, 0, 0.191342), new Point3D(0.5, 0, 0), new Point3D(0.353553, 0, 0.353553), new Point3D(0.191342, 0, 0.46194), new Point3D(3.06162e-017, 0, 0.5), new Point3D(-0.191342, 0, 0.46194), new Point3D(-0.353553, 0, 0.353553), new Point3D(-0.46194, 0, 0.191342), new Point3D(-0.5, 0, 6.12323e-017), new Point3D(-0.46194, 0, -0.191342), new Point3D(-0.353553, 0, -0.353553), new Point3D(-0.191342, 0, -0.46194), new Point3D(-9.18485e-017, 0, -0.5), new Point3D(0.191342, 0, -0.46194), new Point3D(0.353553, 0, -0.353553), new Point3D(0.46194, 0, -0.191342), new Point3D(0.453064, -0.0975452, 0.187665), new Point3D(0.490393, -0.0975452, 0), new Point3D(0.34676, -0.0975452, 0.34676), new Point3D(0.187665, -0.0975452, 0.453064), new Point3D(3.00279e-017, -0.0975452, 0.490393), new Point3D(-0.187665, -0.0975452, 0.453064), new Point3D(-0.34676, -0.0975452, 0.34676), new Point3D(-0.453064, -0.0975452, 0.187665), new Point3D(-0.490393, -0.0975452, 6.00558e-017), new Point3D(-0.453064, -0.0975452, -0.187665), new Point3D(-0.34676, -0.0975452, -0.34676), new Point3D(-0.187665, -0.0975452, -0.453064), new Point3D(-9.00837e-017, -0.0975452, -0.490393), new Point3D(0.187665, -0.0975452, -0.453064), new Point3D(0.34676, -0.0975452, -0.34676), new Point3D(0.453064, -0.0975452, -0.187665), new Point3D(0.426777, -0.191342, 0.176777), new Point3D(0.46194, -0.191342, 0), new Point3D(0.326641, -0.191342, 0.326641), new Point3D(0.176777, -0.191342, 0.426777), new Point3D(2.82857e-017, -0.191342, 0.46194), new Point3D(-0.176777, -0.191342, 0.426777), new Point3D(-0.326641, -0.191342, 0.326641), new Point3D(-0.426777, -0.191342, 0.176777), new Point3D(-0.46194, -0.191342, 5.65713e-017), new Point3D(-0.426777, -0.191342, -0.176777), new Point3D(-0.326641, -0.191342, -0.326641), new Point3D(-0.176777, -0.191342, -0.426777), new Point3D(-8.4857e-017, -0.191342, -0.46194), new Point3D(0.176777, -0.191342, -0.426777), new Point3D(0.326641, -0.191342, -0.326641), new Point3D(0.426777, -0.191342, -0.176777), new Point3D(0.384089, -0.277785, 0.159095), new Point3D(0.415735, -0.277785, 0), new Point3D(0.293969, -0.277785, 0.293969), new Point3D(0.159095, -0.277785, 0.384089), new Point3D(2.54564e-017, -0.277785, 0.415735), new Point3D(-0.159095, -0.277785, 0.384089), new Point3D(-0.293969, -0.277785, 0.293969), new Point3D(-0.384089, -0.277785, 0.159095), new Point3D(-0.415735, -0.277785, 5.09128e-017), new Point3D(-0.384089, -0.277785, -0.159095), new Point3D(-0.293969, -0.277785, -0.293969), new Point3D(-0.159095, -0.277785, -0.384089), new Point3D(-7.63692e-017, -0.277785, -0.415735), new Point3D(0.159095, -0.277785, -0.384089), new Point3D(0.293969, -0.277785, -0.293969), new Point3D(0.384089, -0.277785, -0.159095), new Point3D(0.326641, -0.353553, 0.135299), new Point3D(0.353553, -0.353553, 0), new Point3D(0.25, -0.353553, 0.25), new Point3D(0.135299, -0.353553, 0.326641), new Point3D(2.16489e-017, -0.353553, 0.353553), new Point3D(-0.135299, -0.353553, 0.326641), new Point3D(-0.25, -0.353553, 0.25), new Point3D(-0.326641, -0.353553, 0.135299), new Point3D(-0.353553, -0.353553, 4.32978e-017), new Point3D(-0.326641, -0.353553, -0.135299), new Point3D(-0.25, -0.353553, -0.25), new Point3D(-0.135299, -0.353553, -0.326641), new Point3D(-6.49467e-017, -0.353553, -0.353553), new Point3D(0.135299, -0.353553, -0.326641), new Point3D(0.25, -0.353553, -0.25), new Point3D(0.326641, -0.353553, -0.135299), new Point3D(0.25664, -0.415735, 0.106304), new Point3D(0.277785, -0.415735, 0), new Point3D(0.196424, -0.415735, 0.196424), new Point3D(0.106304, -0.415735, 0.25664), new Point3D(1.70094e-017, -0.415735, 0.277785), new Point3D(-0.106304, -0.415735, 0.25664), new Point3D(-0.196424, -0.415735, 0.196424), new Point3D(-0.25664, -0.415735, 0.106304), new Point3D(-0.277785, -0.415735, 3.40189e-017), new Point3D(-0.25664, -0.415735, -0.106304), new Point3D(-0.196424, -0.415735, -0.196424), new Point3D(-0.106304, -0.415735, -0.25664), new Point3D(-5.10283e-017, -0.415735, -0.277785), new Point3D(0.106304, -0.415735, -0.25664), new Point3D(0.196424, -0.415735, -0.196424), new Point3D(0.25664, -0.415735, -0.106304), new Point3D(0.176777, -0.46194, 0.0732233), new Point3D(0.191342, -0.46194, 0), new Point3D(0.135299, -0.46194, 0.135299), new Point3D(0.0732233, -0.46194, 0.176777), new Point3D(1.17163e-017, -0.46194, 0.191342), new Point3D(-0.0732233, -0.46194, 0.176777), new Point3D(-0.135299, -0.46194, 0.135299), new Point3D(-0.176777, -0.46194, 0.0732233), new Point3D(-0.191342, -0.46194, 2.34326e-017), new Point3D(-0.176777, -0.46194, -0.0732233), new Point3D(-0.135299, -0.46194, -0.135299), new Point3D(-0.0732233, -0.46194, -0.176777), new Point3D(-3.51489e-017, -0.46194, -0.191342), new Point3D(0.0732233, -0.46194, -0.176777), new Point3D(0.135299, -0.46194, -0.135299), new Point3D(0.176777, -0.46194, -0.0732233), new Point3D(0.09012, -0.490393, 0.0373289), new Point3D(0.0975452, -0.490393, 0), new Point3D(0.0689748, -0.490393, 0.0689748), new Point3D(0.0373289, -0.490393, 0.09012), new Point3D(5.97292e-018, -0.490393, 0.0975452), new Point3D(-0.0373289, -0.490393, 0.09012), new Point3D(-0.0689748, -0.490393, 0.0689748), new Point3D(-0.09012, -0.490393, 0.0373289), new Point3D(-0.0975452, -0.490393, 1.19458e-017), new Point3D(-0.09012, -0.490393, -0.0373289), new Point3D(-0.0689748, -0.490393, -0.0689748), new Point3D(-0.0373289, -0.490393, -0.09012), new Point3D(-1.79188e-017, -0.490393, -0.0975452), new Point3D(0.0373289, -0.490393, -0.09012), new Point3D(0.0689748, -0.490393, -0.0689748), new Point3D(0.09012, -0.490393, -0.0373289), new Point3D(0, -0.5, 0) };
            ball.TriangleIndices = new Int32Collection { 0, 1, 2, 3, 0, 2, 4, 3, 2, 5, 4, 2, 6, 5, 2, 7, 6, 2, 8, 7, 2, 9, 8, 2, 10, 9, 2, 11, 10, 2, 12, 11, 2, 13, 12, 2, 14, 13, 2, 15, 14, 2, 16, 15, 2, 1, 16, 2, 17, 18, 1, 1, 0, 17, 19, 17, 0, 0, 3, 19, 20, 19, 3, 3, 4, 20, 21, 20, 4, 4, 5, 21, 22, 21, 5, 5, 6, 22, 23, 22, 6, 6, 7, 23, 24, 23, 7, 7, 8, 24, 25, 24, 8, 8, 9, 25, 26, 25, 9, 9, 10, 26, 27, 26, 10, 10, 11, 27, 28, 27, 11, 11, 12, 28, 29, 28, 12, 12, 13, 29, 30, 29, 13, 13, 14, 30, 31, 30, 14, 14, 15, 31, 32, 31, 15, 15, 16, 32, 18, 32, 16, 16, 1, 18, 33, 34, 18, 18, 17, 33, 35, 33, 17, 17, 19, 35, 36, 35, 19, 19, 20, 36, 37, 36, 20, 20, 21, 37, 38, 37, 21, 21, 22, 38, 39, 38, 22, 22, 23, 39, 40, 39, 23, 23, 24, 40, 41, 40, 24, 24, 25, 41, 42, 41, 25, 25, 26, 42, 43, 42, 26, 26, 27, 43, 44, 43, 27, 27, 28, 44, 45, 44, 28, 28, 29, 45, 46, 45, 29, 29, 30, 46, 47, 46, 30, 30, 31, 47, 48, 47, 31, 31, 32, 48, 34, 48, 32, 32, 18, 34, 49, 50, 34, 34, 33, 49, 51, 49, 33, 33, 35, 51, 52, 51, 35, 35, 36, 52, 53, 52, 36, 36, 37, 53, 54, 53, 37, 37, 38, 54, 55, 54, 38, 38, 39, 55, 56, 55, 39, 39, 40, 56, 57, 56, 40, 40, 41, 57, 58, 57, 41, 41, 42, 58, 59, 58, 42, 42, 43, 59, 60, 59, 43, 43, 44, 60, 61, 60, 44, 44, 45, 61, 62, 61, 45, 45, 46, 62, 63, 62, 46, 46, 47, 63, 64, 63, 47, 47, 48, 64, 50, 64, 48, 48, 34, 50, 65, 66, 50, 50, 49, 65, 67, 65, 49, 49, 51, 67, 68, 67, 51, 51, 52, 68, 69, 68, 52, 52, 53, 69, 70, 69, 53, 53, 54, 70, 71, 70, 54, 54, 55, 71, 72, 71, 55, 55, 56, 72, 73, 72, 56, 56, 57, 73, 74, 73, 57, 57, 58, 74, 75, 74, 58, 58, 59, 75, 76, 75, 59, 59, 60, 76, 77, 76, 60, 60, 61, 77, 78, 77, 61, 61, 62, 78, 79, 78, 62, 62, 63, 79, 80, 79, 63, 63, 64, 80, 66, 80, 64, 64, 50, 66, 81, 82, 66, 66, 65, 81, 83, 81, 65, 65, 67, 83, 84, 83, 67, 67, 68, 84, 85, 84, 68, 68, 69, 85, 86, 85, 69, 69, 70, 86, 87, 86, 70, 70, 71, 87, 88, 87, 71, 71, 72, 88, 89, 88, 72, 72, 73, 89, 90, 89, 73, 73, 74, 90, 91, 90, 74, 74, 75, 91, 92, 91, 75, 75, 76, 92, 93, 92, 76, 76, 77, 93, 94, 93, 77, 77, 78, 94, 95, 94, 78, 78, 79, 95, 96, 95, 79, 79, 80, 96, 82, 96, 80, 80, 66, 82, 97, 98, 82, 82, 81, 97, 99, 97, 81, 81, 83, 99, 100, 99, 83, 83, 84, 100, 101, 100, 84, 84, 85, 101, 102, 101, 85, 85, 86, 102, 103, 102, 86, 86, 87, 103, 104, 103, 87, 87, 88, 104, 105, 104, 88, 88, 89, 105, 106, 105, 89, 89, 90, 106, 107, 106, 90, 90, 91, 107, 108, 107, 91, 91, 92, 108, 109, 108, 92, 92, 93, 109, 110, 109, 93, 93, 94, 110, 111, 110, 94, 94, 95, 111, 112, 111, 95, 95, 96, 112, 98, 112, 96, 96, 82, 98, 113, 114, 98, 98, 97, 113, 115, 113, 97, 97, 99, 115, 116, 115, 99, 99, 100, 116, 117, 116, 100, 100, 101, 117, 118, 117, 101, 101, 102, 118, 119, 118, 102, 102, 103, 119, 120, 119, 103, 103, 104, 120, 121, 120, 104, 104, 105, 121, 122, 121, 105, 105, 106, 122, 123, 122, 106, 106, 107, 123, 124, 123, 107, 107, 108, 124, 125, 124, 108, 108, 109, 125, 126, 125, 109, 109, 110, 126, 127, 126, 110, 110, 111, 127, 128, 127, 111, 111, 112, 128, 114, 128, 112, 112, 98, 114, 129, 130, 114, 114, 113, 129, 131, 129, 113, 113, 115, 131, 132, 131, 115, 115, 116, 132, 133, 132, 116, 116, 117, 133, 134, 133, 117, 117, 118, 134, 135, 134, 118, 118, 119, 135, 136, 135, 119, 119, 120, 136, 137, 136, 120, 120, 121, 137, 138, 137, 121, 121, 122, 138, 139, 138, 122, 122, 123, 139, 140, 139, 123, 123, 124, 140, 141, 140, 124, 124, 125, 141, 142, 141, 125, 125, 126, 142, 143, 142, 126, 126, 127, 143, 144, 143, 127, 127, 128, 144, 130, 144, 128, 128, 114, 130, 145, 146, 130, 130, 129, 145, 147, 145, 129, 129, 131, 147, 148, 147, 131, 131, 132, 148, 149, 148, 132, 132, 133, 149, 150, 149, 133, 133, 134, 150, 151, 150, 134, 134, 135, 151, 152, 151, 135, 135, 136, 152, 153, 152, 136, 136, 137, 153, 154, 153, 137, 137, 138, 154, 155, 154, 138, 138, 139, 155, 156, 155, 139, 139, 140, 156, 157, 156, 140, 140, 141, 157, 158, 157, 141, 141, 142, 158, 159, 158, 142, 142, 143, 159, 160, 159, 143, 143, 144, 160, 146, 160, 144, 144, 130, 146, 161, 162, 146, 146, 145, 161, 163, 161, 145, 145, 147, 163, 164, 163, 147, 147, 148, 164, 165, 164, 148, 148, 149, 165, 166, 165, 149, 149, 150, 166, 167, 166, 150, 150, 151, 167, 168, 167, 151, 151, 152, 168, 169, 168, 152, 152, 153, 169, 170, 169, 153, 153, 154, 170, 171, 170, 154, 154, 155, 171, 172, 171, 155, 155, 156, 172, 173, 172, 156, 156, 157, 173, 174, 173, 157, 157, 158, 174, 175, 174, 158, 158, 159, 175, 176, 175, 159, 159, 160, 176, 162, 176, 160, 160, 146, 162, 177, 178, 162, 162, 161, 177, 179, 177, 161, 161, 163, 179, 180, 179, 163, 163, 164, 180, 181, 180, 164, 164, 165, 181, 182, 181, 165, 165, 166, 182, 183, 182, 166, 166, 167, 183, 184, 183, 167, 167, 168, 184, 185, 184, 168, 168, 169, 185, 186, 185, 169, 169, 170, 186, 187, 186, 170, 170, 171, 187, 188, 187, 171, 171, 172, 188, 189, 188, 172, 172, 173, 189, 190, 189, 173, 173, 174, 190, 191, 190, 174, 174, 175, 191, 192, 191, 175, 175, 176, 192, 178, 192, 176, 176, 162, 178, 193, 194, 178, 178, 177, 193, 195, 193, 177, 177, 179, 195, 196, 195, 179, 179, 180, 196, 197, 196, 180, 180, 181, 197, 198, 197, 181, 181, 182, 198, 199, 198, 182, 182, 183, 199, 200, 199, 183, 183, 184, 200, 201, 200, 184, 184, 185, 201, 202, 201, 185, 185, 186, 202, 203, 202, 186, 186, 187, 203, 204, 203, 187, 187, 188, 204, 205, 204, 188, 188, 189, 205, 206, 205, 189, 189, 190, 206, 207, 206, 190, 190, 191, 207, 208, 207, 191, 191, 192, 208, 194, 208, 192, 192, 178, 194, 209, 210, 194, 194, 193, 209, 211, 209, 193, 193, 195, 211, 212, 211, 195, 195, 196, 212, 213, 212, 196, 196, 197, 213, 214, 213, 197, 197, 198, 214, 215, 214, 198, 198, 199, 215, 216, 215, 199, 199, 200, 216, 217, 216, 200, 200, 201, 217, 218, 217, 201, 201, 202, 218, 219, 218, 202, 202, 203, 219, 220, 219, 203, 203, 204, 220, 221, 220, 204, 204, 205, 221, 222, 221, 205, 205, 206, 222, 223, 222, 206, 206, 207, 223, 224, 223, 207, 207, 208, 224, 210, 224, 208, 208, 194, 210, 225, 226, 210, 210, 209, 225, 227, 225, 209, 209, 211, 227, 228, 227, 211, 211, 212, 228, 229, 228, 212, 212, 213, 229, 230, 229, 213, 213, 214, 230, 231, 230, 214, 214, 215, 231, 232, 231, 215, 215, 216, 232, 233, 232, 216, 216, 217, 233, 234, 233, 217, 217, 218, 234, 235, 234, 218, 218, 219, 235, 236, 235, 219, 219, 220, 236, 237, 236, 220, 220, 221, 237, 238, 237, 221, 221, 222, 238, 239, 238, 222, 222, 223, 239, 240, 239, 223, 223, 224, 240, 226, 240, 224, 224, 210, 226, 241, 226, 225, 241, 225, 227, 241, 227, 228, 241, 228, 229, 241, 229, 230, 241, 230, 231, 241, 231, 232, 241, 232, 233, 241, 233, 234, 241, 234, 235, 241, 235, 236, 241, 236, 237, 241, 237, 238, 241, 238, 239, 241, 239, 240, 241, 240, 226 };
            ball.Normals = new Vector3DCollection { new Vector3D(0.18024, 0.980785, 0.0746578), new Vector3D(0.19509, 0.980785, 0), new Vector3D(0, 1, 0), new Vector3D(0.13795, 0.980785, 0.13795), new Vector3D(0.0746578, 0.980785, 0.18024), new Vector3D(1.19458e-017, 0.980785, 0.19509), new Vector3D(-0.0746578, 0.980785, 0.18024), new Vector3D(-0.13795, 0.980785, 0.13795), new Vector3D(-0.18024, 0.980785, 0.0746578), new Vector3D(-0.19509, 0.980785, 2.38917e-017), new Vector3D(-0.18024, 0.980785, -0.0746578), new Vector3D(-0.13795, 0.980785, -0.13795), new Vector3D(-0.0746578, 0.980785, -0.18024), new Vector3D(-3.58375e-017, 0.980785, -0.19509), new Vector3D(0.0746578, 0.980785, -0.18024), new Vector3D(0.13795, 0.980785, -0.13795), new Vector3D(0.18024, 0.980785, -0.0746578), new Vector3D(0.353553, 0.92388, 0.146447), new Vector3D(0.382683, 0.92388, 0), new Vector3D(0.270598, 0.92388, 0.270598), new Vector3D(0.146447, 0.92388, 0.353553), new Vector3D(2.34326e-017, 0.92388, 0.382683), new Vector3D(-0.146447, 0.92388, 0.353553), new Vector3D(-0.270598, 0.92388, 0.270598), new Vector3D(-0.353553, 0.92388, 0.146447), new Vector3D(-0.382683, 0.92388, 4.68652e-017), new Vector3D(-0.353553, 0.92388, -0.146447), new Vector3D(-0.270598, 0.92388, -0.270598), new Vector3D(-0.146447, 0.92388, -0.353553), new Vector3D(-7.02978e-017, 0.92388, -0.382683), new Vector3D(0.146447, 0.92388, -0.353553), new Vector3D(0.270598, 0.92388, -0.270598), new Vector3D(0.353553, 0.92388, -0.146447), new Vector3D(0.51328, 0.83147, 0.212608), new Vector3D(0.55557, 0.83147, 0), new Vector3D(0.392847, 0.83147, 0.392847), new Vector3D(0.212608, 0.83147, 0.51328), new Vector3D(3.40189e-017, 0.83147, 0.55557), new Vector3D(-0.212608, 0.83147, 0.51328), new Vector3D(-0.392847, 0.83147, 0.392847), new Vector3D(-0.51328, 0.83147, 0.212608), new Vector3D(-0.55557, 0.83147, 6.80377e-017), new Vector3D(-0.51328, 0.83147, -0.212608), new Vector3D(-0.392847, 0.83147, -0.392847), new Vector3D(-0.212608, 0.83147, -0.51328), new Vector3D(-1.02057e-016, 0.83147, -0.55557), new Vector3D(0.212608, 0.83147, -0.51328), new Vector3D(0.392847, 0.83147, -0.392847), new Vector3D(0.51328, 0.83147, -0.212608), new Vector3D(0.653282, 0.707107, 0.270598), new Vector3D(0.707107, 0.707107, 0), new Vector3D(0.5, 0.707107, 0.5), new Vector3D(0.270598, 0.707107, 0.653282), new Vector3D(4.32978e-017, 0.707107, 0.707107), new Vector3D(-0.270598, 0.707107, 0.653282), new Vector3D(-0.5, 0.707107, 0.5), new Vector3D(-0.653282, 0.707107, 0.270598), new Vector3D(-0.707107, 0.707107, 8.65956e-017), new Vector3D(-0.653282, 0.707107, -0.270598), new Vector3D(-0.5, 0.707107, -0.5), new Vector3D(-0.270598, 0.707107, -0.653282), new Vector3D(-1.29893e-016, 0.707107, -0.707107), new Vector3D(0.270598, 0.707107, -0.653282), new Vector3D(0.5, 0.707107, -0.5), new Vector3D(0.653282, 0.707107, -0.270598), new Vector3D(0.768178, 0.55557, 0.31819), new Vector3D(0.83147, 0.55557, 0), new Vector3D(0.587938, 0.55557, 0.587938), new Vector3D(0.31819, 0.55557, 0.768178), new Vector3D(5.09128e-017, 0.55557, 0.83147), new Vector3D(-0.31819, 0.55557, 0.768178), new Vector3D(-0.587938, 0.55557, 0.587938), new Vector3D(-0.768178, 0.55557, 0.31819), new Vector3D(-0.83147, 0.55557, 1.01826e-016), new Vector3D(-0.768178, 0.55557, -0.31819), new Vector3D(-0.587938, 0.55557, -0.587938), new Vector3D(-0.31819, 0.55557, -0.768178), new Vector3D(-1.52738e-016, 0.55557, -0.83147), new Vector3D(0.31819, 0.55557, -0.768178), new Vector3D(0.587938, 0.55557, -0.587938), new Vector3D(0.768178, 0.55557, -0.31819), new Vector3D(0.853553, 0.382683, 0.353553), new Vector3D(0.92388, 0.382683, 0), new Vector3D(0.653282, 0.382683, 0.653282), new Vector3D(0.353553, 0.382683, 0.853553), new Vector3D(5.65713e-017, 0.382683, 0.92388), new Vector3D(-0.353553, 0.382683, 0.853553), new Vector3D(-0.653282, 0.382683, 0.653282), new Vector3D(-0.853553, 0.382683, 0.353553), new Vector3D(-0.92388, 0.382683, 1.13143e-016), new Vector3D(-0.853553, 0.382683, -0.353553), new Vector3D(-0.653282, 0.382683, -0.653282), new Vector3D(-0.353553, 0.382683, -0.853553), new Vector3D(-1.69714e-016, 0.382683, -0.92388), new Vector3D(0.353553, 0.382683, -0.853553), new Vector3D(0.653282, 0.382683, -0.653282), new Vector3D(0.853553, 0.382683, -0.353553), new Vector3D(0.906127, 0.19509, 0.37533), new Vector3D(0.980785, 0.19509, 0), new Vector3D(0.69352, 0.19509, 0.69352), new Vector3D(0.37533, 0.19509, 0.906127), new Vector3D(6.00558e-017, 0.19509, 0.980785), new Vector3D(-0.37533, 0.19509, 0.906127), new Vector3D(-0.69352, 0.19509, 0.69352), new Vector3D(-0.906127, 0.19509, 0.37533), new Vector3D(-0.980785, 0.19509, 1.20112e-016), new Vector3D(-0.906127, 0.19509, -0.37533), new Vector3D(-0.69352, 0.19509, -0.69352), new Vector3D(-0.37533, 0.19509, -0.906127), new Vector3D(-1.80167e-016, 0.19509, -0.980785), new Vector3D(0.37533, 0.19509, -0.906127), new Vector3D(0.69352, 0.19509, -0.69352), new Vector3D(0.906127, 0.19509, -0.37533), new Vector3D(0.92388, 0, 0.382683), new Vector3D(1, 0, 0), new Vector3D(0.707107, 0, 0.707107), new Vector3D(0.382683, 0, 0.92388), new Vector3D(6.12323e-017, 0, 1), new Vector3D(-0.382683, 0, 0.92388), new Vector3D(-0.707107, 0, 0.707107), new Vector3D(-0.92388, 0, 0.382683), new Vector3D(-1, 0, 1.22465e-016), new Vector3D(-0.92388, 0, -0.382683), new Vector3D(-0.707107, 0, -0.707107), new Vector3D(-0.382683, 0, -0.92388), new Vector3D(-1.83697e-016, 0, -1), new Vector3D(0.382683, 0, -0.92388), new Vector3D(0.707107, 0, -0.707107), new Vector3D(0.92388, 0, -0.382683), new Vector3D(0.906127, -0.19509, 0.37533), new Vector3D(0.980785, -0.19509, 0), new Vector3D(0.69352, -0.19509, 0.69352), new Vector3D(0.37533, -0.19509, 0.906127), new Vector3D(6.00558e-017, -0.19509, 0.980785), new Vector3D(-0.37533, -0.19509, 0.906127), new Vector3D(-0.69352, -0.19509, 0.69352), new Vector3D(-0.906127, -0.19509, 0.37533), new Vector3D(-0.980785, -0.19509, 1.20112e-016), new Vector3D(-0.906127, -0.19509, -0.37533), new Vector3D(-0.69352, -0.19509, -0.69352), new Vector3D(-0.37533, -0.19509, -0.906127), new Vector3D(-1.80167e-016, -0.19509, -0.980785), new Vector3D(0.37533, -0.19509, -0.906127), new Vector3D(0.69352, -0.19509, -0.69352), new Vector3D(0.906127, -0.19509, -0.37533), new Vector3D(0.853553, -0.382683, 0.353553), new Vector3D(0.92388, -0.382683, 0), new Vector3D(0.653282, -0.382683, 0.653282), new Vector3D(0.353553, -0.382683, 0.853553), new Vector3D(5.65713e-017, -0.382683, 0.92388), new Vector3D(-0.353553, -0.382683, 0.853553), new Vector3D(-0.653282, -0.382683, 0.653282), new Vector3D(-0.853553, -0.382683, 0.353553), new Vector3D(-0.92388, -0.382683, 1.13143e-016), new Vector3D(-0.853553, -0.382683, -0.353553), new Vector3D(-0.653282, -0.382683, -0.653282), new Vector3D(-0.353553, -0.382683, -0.853553), new Vector3D(-1.69714e-016, -0.382683, -0.92388), new Vector3D(0.353553, -0.382683, -0.853553), new Vector3D(0.653282, -0.382683, -0.653282), new Vector3D(0.853553, -0.382683, -0.353553), new Vector3D(0.768178, -0.55557, 0.31819), new Vector3D(0.83147, -0.55557, 0), new Vector3D(0.587938, -0.55557, 0.587938), new Vector3D(0.31819, -0.55557, 0.768178), new Vector3D(5.09128e-017, -0.55557, 0.83147), new Vector3D(-0.31819, -0.55557, 0.768178), new Vector3D(-0.587938, -0.55557, 0.587938), new Vector3D(-0.768178, -0.55557, 0.31819), new Vector3D(-0.83147, -0.55557, 1.01826e-016), new Vector3D(-0.768178, -0.55557, -0.31819), new Vector3D(-0.587938, -0.55557, -0.587938), new Vector3D(-0.31819, -0.55557, -0.768178), new Vector3D(-1.52738e-016, -0.55557, -0.83147), new Vector3D(0.31819, -0.55557, -0.768178), new Vector3D(0.587938, -0.55557, -0.587938), new Vector3D(0.768178, -0.55557, -0.31819), new Vector3D(0.653282, -0.707107, 0.270598), new Vector3D(0.707107, -0.707107, 0), new Vector3D(0.5, -0.707107, 0.5), new Vector3D(0.270598, -0.707107, 0.653282), new Vector3D(4.32978e-017, -0.707107, 0.707107), new Vector3D(-0.270598, -0.707107, 0.653282), new Vector3D(-0.5, -0.707107, 0.5), new Vector3D(-0.653282, -0.707107, 0.270598), new Vector3D(-0.707107, -0.707107, 8.65956e-017), new Vector3D(-0.653282, -0.707107, -0.270598), new Vector3D(-0.5, -0.707107, -0.5), new Vector3D(-0.270598, -0.707107, -0.653282), new Vector3D(-1.29893e-016, -0.707107, -0.707107), new Vector3D(0.270598, -0.707107, -0.653282), new Vector3D(0.5, -0.707107, -0.5), new Vector3D(0.653282, -0.707107, -0.270598), new Vector3D(0.51328, -0.83147, 0.212608), new Vector3D(0.55557, -0.83147, 0), new Vector3D(0.392847, -0.83147, 0.392847), new Vector3D(0.212608, -0.83147, 0.51328), new Vector3D(3.40189e-017, -0.83147, 0.55557), new Vector3D(-0.212608, -0.83147, 0.51328), new Vector3D(-0.392847, -0.83147, 0.392847), new Vector3D(-0.51328, -0.83147, 0.212608), new Vector3D(-0.55557, -0.83147, 6.80377e-017), new Vector3D(-0.51328, -0.83147, -0.212608), new Vector3D(-0.392847, -0.83147, -0.392847), new Vector3D(-0.212608, -0.83147, -0.51328), new Vector3D(-1.02057e-016, -0.83147, -0.55557), new Vector3D(0.212608, -0.83147, -0.51328), new Vector3D(0.392847, -0.83147, -0.392847), new Vector3D(0.51328, -0.83147, -0.212608), new Vector3D(0.353553, -0.92388, 0.146447), new Vector3D(0.382683, -0.92388, 0), new Vector3D(0.270598, -0.92388, 0.270598), new Vector3D(0.146447, -0.92388, 0.353553), new Vector3D(2.34326e-017, -0.92388, 0.382683), new Vector3D(-0.146447, -0.92388, 0.353553), new Vector3D(-0.270598, -0.92388, 0.270598), new Vector3D(-0.353553, -0.92388, 0.146447), new Vector3D(-0.382683, -0.92388, 4.68652e-017), new Vector3D(-0.353553, -0.92388, -0.146447), new Vector3D(-0.270598, -0.92388, -0.270598), new Vector3D(-0.146447, -0.92388, -0.353553), new Vector3D(-7.02978e-017, -0.92388, -0.382683), new Vector3D(0.146447, -0.92388, -0.353553), new Vector3D(0.270598, -0.92388, -0.270598), new Vector3D(0.353553, -0.92388, -0.146447), new Vector3D(0.18024, -0.980785, 0.0746578), new Vector3D(0.19509, -0.980785, 0), new Vector3D(0.13795, -0.980785, 0.13795), new Vector3D(0.0746578, -0.980785, 0.18024), new Vector3D(1.19458e-017, -0.980785, 0.19509), new Vector3D(-0.0746578, -0.980785, 0.18024), new Vector3D(-0.13795, -0.980785, 0.13795), new Vector3D(-0.18024, -0.980785, 0.0746578), new Vector3D(-0.19509, -0.980785, 2.38917e-017), new Vector3D(-0.18024, -0.980785, -0.0746578), new Vector3D(-0.13795, -0.980785, -0.13795), new Vector3D(-0.0746578, -0.980785, -0.18024), new Vector3D(-3.58375e-017, -0.980785, -0.19509), new Vector3D(0.0746578, -0.980785, -0.18024), new Vector3D(0.13795, -0.980785, -0.13795), new Vector3D(0.18024, -0.980785, -0.0746578), new Vector3D(0, -1, 0) };

            return ball;
        }

        private void CreateAnimation()
        {
            LinearDoubleKeyFrame ldkf1 = new LinearDoubleKeyFrame();
            LinearDoubleKeyFrame ldkf2 = new LinearDoubleKeyFrame();

            ldkf1.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0));
            ldkf1.Value = 50;

            ldkf2.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 5));
            ldkf2.Value = -10;

            daukf.KeyFrames.Add(ldkf1);
            daukf.KeyFrames.Add(ldkf2);
            daukf.BeginTime = new TimeSpan(0, 0, 0, 0, (int)GetRnd(5000));
            daukf.Duration = new TimeSpan(0, 0, 0, 5);
            daukf.RepeatBehavior = RepeatBehavior.Forever;
        }

        private static double GetRnd(double range)
        {
            return (_rnd.NextDouble() * range);
        }
    }


    public class SnowFactory
    {
        public static Snow CreateSnowBall()
        {
            Snow snow = new Snow();
            return snow;
        }

        public static Snow CreateSnowBall(Color col, double size)
        {
            Snow snow = new Snow(col, size);
            return snow;
        }
    }
}

 


サンプルプログラム

サンプルプログラム ダウンロード

 

 

ライセンス

本ページの情報は、特記無い限り下記 MIT ライセンスで提供されます。

The MIT License (MIT)

Copyright © 2015-2022 Kinoshita Hidetoshi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 

 

参考

 


 

変更履歴

2022-11-21 - ページデザイン更新
2015-08-22 - 新規作成

 

Programming Items トップページ

プライバシーポリシー