Archive for the ‘WPF’ Category

WPF におけるパッケージの URI

2013年3月9日

http://msdn.microsoft.com/ja-jp/library/vstudio/aa970069.aspx

test.jpg

this.Image1.Source = new BitmapImage(new Uri("pack://application:,,,/test.jpg"));

広告

Path を C# で構成する

2012年10月8日

環境: WIndows Phone 7 + Visual Studio 2010

WPF だと、Expression Blend などで次のように簡単に Path を自動生成してくれます。

<Path x:Name="path" Data="M183.66667,86.666667 C189.39235,102.51222 195.97031,115.69911 204.00303,124.34783 189.46184,124.37625 176.55191,127.63058 166.26051,130.07866 177.67961,136.62725 192.00787,141.50314 209.25719,141.39676 203.19164,149.57713 198.0335,156.49435 192.99912,166.33255 202.42621,162.74626 210.94614,156.64738 218.66605,148.33266 L222.66553,167.66588 C225.54016,165.52929 227.12504,154.35884 228.999,141.99936 234.06358,144.63928 238.15358,153.77991 241.33226,168.99921 L243.66592,167.99921 C241.1493,155.99855 236.78856,146.70538 230.66566,139.99937 241.69194,144.10578 251.73257,143.90948 260.99883,140.3327 255.36431,137.34626 248.38965,134.93892 240.33229,132.99941 250.52631,127.61701 259.03319,119.28195 265.66548,107.66621 L234.3321,118.99948 C236.99567,104.86417 236.63427,91.185053 232.99878,77.999712 226.74482,85.30016 221.8588,98.979918 218.33224,118.99948 209.59223,103.54312 197.83014,93.109381 183.66667,86.666667 z" Fill="red" Height="100" Stretch="Fill" Stroke="Red" RenderTransformOrigin="0.5,0.5"  Width="100" Margin="159,30,197,477">

Windows 環境だと、次のように PathGeometry.Parse でパースできるので、Expression Blend でデザインしたデータを C# で簡単に再利用することができます。

            const string PathData = “M248,64 C236.5247,64.625058 225.71435,67.192184 215.5,71.5 L207.5,95.5 191.5,79.5 C179.10929,77.102304 168.53048,80.027027 159.5,87.5 159.50162,99.540561 161.46431,108.60788 167.5,111.5 L183.5,119.5 159.5,135.5 C160.12292,156.23214 162.17492,169.92602 167.5,167.5 172.91066,172.67869 180.71148,173.07705 191.5,167.5 L207.5,151.5 C203.2411,162.05534 202.55968,170.46419 207.5,175.5 219.38597,184.51719 230.14356,187.65745 239.5,183.5 L255.5,167.5 C252.80927,155.47101 245.02601,144.74873 231.5,135.5 L263.5,143.5 C272.5318,139.39663 278.23003,131.78108 279.5,119.5 276.83333,114.16667 274.16667,108.83333 271.5,103.5 262.70483,100.69259 251.88845,100.91719 239.5,103.5 248.65115,105.75263 260.3255,80.446287 248,64 z”;
            var g = PathGeometry.Parse(PathData);

ところが、Windows Phone 環境だと、 Path.Parse が提供されていないのと、Object.Clone がないので、次のようにべたに書かざるを得なくなります。

private Path CreatePath()
{
    var pf = new PathFigure();
    pf.StartPoint = new Point(183.66667, 86.666667);
   
    var b1 = new BezierSegment(); // C189.39235,102.51222 195.97031,115.69911 204.00303,124.34783
    b1.Point1 = new Point(189.39235, 102.51222);
    b1.Point2 = new Point(195.97031, 115.69911);
    b1.Point3 = new Point(204.00303, 124.34783);
    pf.Segments.Add(b1);
    var b2 = new BezierSegment();  // 189.46184,124.37625 176.55191,127.63058 166.26051,130.07866
    b2.Point1 = new Point(189.46184, 124.37625);
    b2.Point2 = new Point(176.55191, 127.63058);
    b2.Point3 = new Point(166.26051, 130.07866);
    pf.Segments.Add(b2);
    var b3 = new BezierSegment();  // 177.67961,136.62725 192.00787,141.50314 209.25719,141.39676 
    b3.Point1 = new Point(177.67961, 136.62725);
    b3.Point2 = new Point(192.00787, 141.50314);
    b3.Point3 = new Point(209.25719, 141.39676);
    pf.Segments.Add(b3);
    var b4 = new BezierSegment();  // 203.19164,149.57713 198.0335,156.49435 192.99912,166.33255
    b4.Point1 = new Point(203.19164, 149.57713);
    b4.Point2 = new Point(198.0335, 156.49435);
    b4.Point3 = new Point(192.99912, 166.33255);
    pf.Segments.Add(b4);
    var b5 = new BezierSegment();  // 202.42621,162.74626 210.94614,156.64738 218.66605,148.33266
    b5.Point1 = new Point(202.42621, 162.74626);
    b5.Point2 = new Point(210.94614, 156.64738);
    b5.Point3 = new Point(218.66605, 148.33266);
    pf.Segments.Add(b5);

    // L222.66553,167.66588
    var l1 = new LineSegment();
    l1.Point = new Point(222.66553,167.66588 );
    pf.Segments.Add(l1);

    var b6 = new BezierSegment();  // C225.54016,165.52929 227.12504,154.35884 228.999,141.99936 
    b6.Point1 = new Point(225.54016, 165.52929);
    b6.Point2 = new Point(227.12504, 154.35884);
    b6.Point3 = new Point(228.999, 141.99936);
    pf.Segments.Add(b6);

    var b7 = new BezierSegment();  // 234.06358,144.63928 238.15358,153.77991 241.33226,168.99921 
    b7.Point1 = new Point(234.06358, 144.63928);
    b7.Point2 = new Point(238.15358, 153.77991);
    b7.Point3 = new Point(241.33226, 168.99921);
    pf.Segments.Add(b7);

    // L243.66592,167.99921
    var l2 = new LineSegment();
    l2.Point = new Point(243.66592, 167.99921);
    pf.Segments.Add(l2);

    var b8 = new BezierSegment();  // C241.1493,155.99855 236.78856,146.70538 230.66566,139.99937  
    b8.Point1 = new Point(241.1493, 155.99855);
    b8.Point2 = new Point(236.78856, 146.70538);
    b8.Point3 = new Point(230.66566, 139.99937);
    pf.Segments.Add(b8);

    var b9 = new BezierSegment();  // 241.69194,144.10578 251.73257,143.90948 260.99883,140.3327
    b9.Point1 = new Point(241.69194, 144.10578);
    b9.Point2 = new Point(251.73257, 143.90948);
    b9.Point3 = new Point(260.99883, 140.3327);
    pf.Segments.Add(b9);

    var b10 = new BezierSegment();  // 255.36431,137.34626 248.38965,134.93892 240.33229,132.99941 
    b10.Point1 = new Point(255.36431, 137.34626);
    b10.Point2 = new Point(248.38965, 134.93892);
    b10.Point3 = new Point(240.33229, 132.99941);
    pf.Segments.Add(b10);

    var b11 = new BezierSegment();  // 250.52631,127.61701 259.03319,119.28195 265.66548,107.66621  
    b11.Point1 = new Point(250.52631, 127.61701);
    b11.Point2 = new Point(259.03319, 119.28195);
    b11.Point3 = new Point(265.66548,107.66621);
    pf.Segments.Add(b11);

    // L234.3321,118.99948
    var l3 = new LineSegment();
    l3.Point = new Point(234.3321, 118.99948);
    pf.Segments.Add(l3);

    var b12 = new BezierSegment();  // C236.99567,104.86417 236.63427,91.185053 232.99878,77.999712      
    b12.Point1 = new Point(236.99567, 104.86417);
    b12.Point2 = new Point(236.63427, 91.185053);
    b12.Point3 = new Point(232.99878, 77.999712);
    pf.Segments.Add(b12);
    var b13 = new BezierSegment();  // 226.74482,85.30016 221.8588,98.979918 218.33224,118.99948
    b13.Point1 = new Point(226.74482, 85.30016);
    b13.Point2 = new Point(221.8588, 98.979918);
    b13.Point3 = new Point(218.33224, 118.99948);
    pf.Segments.Add(b13);
    var b14 = new BezierSegment();  // 209.59223,103.54312 197.83014,93.109381 183.66667,86.666667
    b14.Point1 = new Point(209.59223, 103.54312);
    b14.Point2 = new Point(197.83014, 93.109381);
    b14.Point3 = new Point(183.66667, 86.666667);
    pf.Segments.Add(b14);

    PathFigureCollection pfc = new PathFigureCollection();
    pfc.Add(pf);

    PathGeometry pg = new PathGeometry();
    pg.Figures = pfc;
    var path = new Path();
    path.RenderTransformOrigin = new Point(0.5, 0.5);
    path.StrokeThickness = 3;
    path.Stroke = new SolidColorBrush(Colors.Red);
    path.Width = 100;
    path.Height = 100;
    path.Fill = new SolidColorBrush(Colors.Orange);
    path.Data = pg;
    path.Stretch = Stretch.Fill;
    var ct = new CompositeTransform();
    path.RenderTransform = ct;

    return path;
}

赤いモミジが WPF、オレンジのモミジが C# で実装したものです。

image

Windows Phone では、システムの肥大化を防ぐために API を絞っていますが、Clone は削らないでほしかった・・・

Path を回す

2012年9月27日

環境: Windows Phone 7

デザイナーでアニメーションを設定するのは簡単ですが、固定パターンしかアニメーションを設定できません。動的にアニメーションを作成するには、次のような方法でオブジェクトにアニメーションを設定して、ストーリーボードを再生する必要があります。この時、試行錯誤をしたので、その時のメモです。

ポイント1:
SetTarget で、CompositeTransform に名前を付けて、それに対して、アニメーションのターゲットを設定します。
この時、SetTargetName(daukf1, “ct”);
のように名前で指定しようとすると、InvalidOperationalException、”Cannot resolve TargetName ct” という例外が発生して、うまくいきません。SetTarget(daukf1, ct) で直接指定するとうまくいきます。指定方法が悪いのか、原因は不明です。

ポイント2:
SetTargetPropert で、 ターゲットプロパティに new PropertyPath(CompositeTransform.RotationProperty) を設定します。

<Path x:Name="path" Data="M178,173 L231,109 C231,109 278,143 279,146 C280,149 276,221 272,222 C268,223 203.00009,247 192.00006,245 C181.00002,243 178,173 178,173 z" Fill="Blue" Height="100" Stretch="Fill" Stroke="Red" RenderTransformOrigin="0.5,0.5"  Width="100">
    <Path.RenderTransform>
        <CompositeTransform x:Name="ct"/>
    </Path.RenderTransform>
</Path>

Storyboard sb1 = new Storyboard();

DoubleAnimationUsingKeyFrames daukf1 = new DoubleAnimationUsingKeyFrames();

EasingDoubleKeyFrame ldkf1 = new EasingDoubleKeyFrame();
ldkf1.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0));
ldkf1.Value = 0;
EasingDoubleKeyFrame ldkf2 = new EasingDoubleKeyFrame();
ldkf2.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 1));
ldkf2.Value = 100;

daukf1.KeyFrames.Add(ldkf1);
daukf1.KeyFrames.Add(ldkf2);

Storyboard.SetTarget(daukf1, ct);
Storyboard.SetTargetProperty(daukf1, new PropertyPath(CompositeTransform.RotationProperty));

sb1.Children.Add(daukf1);
sb1.Begin();

水滴が付いたガラス越しに景色を見るWPF

2011年9月26日

水滴が付いたガラス越しに景色を見た写真がきれいだったので、WPFで作ってみた。

20070812 026

オリジナルの画像。

作り方

  • 背景

BlurEffect Radius=”15″ ぐらいでぼかす。

  • 水滴の作り方:

Ellipse に同じ画像を貼り付けて、180°回転させて、DropShadowEffectをつける。Ellipse は少し縦長にしてあげる。あとは、水滴をランダムに配置してあげる。水滴は重ならないので、重ならないように配置する。

image

意外とそれっぽく見える。とりあえず、実験用コードをメモっておく。重なり判定はしていません。

using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Effects;

        BitmapImage bi = new BitmapImage(new Uri(“pack://siteoforigin:,,,/20070812 026.jpg”));

        private void Doit()
        {
            for(int i = 0; i < 100; i++)
                CreateRaindrop();
        }

        private void CreateRaindrop()
        {
            Ellipse raindrop = new Ellipse();
            var effect = new DropShadowEffect();
            effect.Direction = 120;
            effect.Opacity = 0.5;
            raindrop.Effect = effect;
            raindrop.Width = 35;
            raindrop.Height = 40;
            raindrop.RenderTransform = GetTransform(GetRnd(0.5));
            raindrop.Fill = new ImageBrush(bi);
            raindrop.Margin = new Thickness(GetRnd(1200) – 650, GetRnd(800) – 400, 0, 0);

            this.MainGrid.Children.Add(raindrop);
        }

        static Random rnd = new Random();
 
        static double GetRnd(double range)
        {
            return (rnd.NextDouble() * range);
        }
       
        private TransformGroup GetTransform(double size)
        {
            var tg = new TransformGroup();
            var st = new ScaleTransform(size, size);
            var rot = new RotateTransform(180);

            tg.Children.Add(st);
            tg.Children.Add(rot);
 
            return tg;
        }
    }
}

Webページを巡回して、処理する

2011年9月23日

会社の文書管理サーバーの中にあるWebページを巡回して処理しないといけないことがあって、でも全社サーバーなのでAPIに触れないので、Webページを読み込んでHTMLを処理しないといけないということがたまにあって、何度か泣きながら同じようなコードを書いているので、スケルトンだけメモっておく。

参照に Microsoft.mshtmlを追加。

<Window x:Class=”Web.MainWindow”
        xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
        xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
        Title=”MainWindow” Height=”344″ Width=”432″>
    <Grid>
        <WebBrowser Margin=”0,44,0,0″ Name=”webBrowser1″  VerticalAlignment=”Stretch” HorizontalAlignment=”Stretch”  LoadCompleted=”webBrowser1_LoadCompleted” />
        <Button Content=”Button” Height=”23″ HorizontalAlignment=”Left” Margin=”24,15,0,0″ Name=”button1″ VerticalAlignment=”Top” Width=”75″ Click=”button1_Click” />
    </Grid>
</Window>

using System;
using System.Windows;
using System.Windows.Navigation;
using System.Collections;

namespace Web
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            DoScan();
        }

        string[] url = {
                           “http://www.yahoo.co.jp”,
                           “http://uchukamen.com”,
                           “http://www.google.co.jp”
                       };

        IEnumerator en = null;

        private void DoScan()
        {
            this.button1.IsEnabled = false;
            en = url.GetEnumerator();
            GoToNextWebPage();
        }

        private void GoToNextWebPage()
        {
            if (en.MoveNext())
                this.webBrowser1.Source = new Uri((string)en.Current);
            else
                this.button1.IsEnabled = true;
        }

        private void webBrowser1_LoadCompleted(object sender, NavigationEventArgs e)
        {
            DoParse();
            GoToNextWebPage();
        }

        private void DoParse()
        {
            string text = ((mshtml.HTMLDocument)this.webBrowser1.Document).documentElement.innerHTML;
            string innterText = ((mshtml.HTMLDocument)this.webBrowser1.Document).documentElement.innerText;
        }

    }
}

Angel Beats! PV6 タイトルをExpression Blend で作ってみた

2011年9月18日

AB PV6 タイトルをExpression Blend で作ってみた

Expression Blendで、30分ぐらいあれば、ノーコーティングで作れます。

もともとのデザインがあって、その通りWPFで作るのは簡単だけど、ゼロからデザインするのは、本当にデザインセンスが問われますね。

<Window
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
x:Class=”WpfApplication6.MainWindow”
x:Name=”Window”
Title=”MainWindow”
Width=”640″ Height=”480″>
<Window.Resources>
<Storyboard x:Key=”OnLoaded1″>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)” Storyboard.TargetName=”image”>
<EasingDoubleKeyFrame KeyTime=”0″ Value=”227″/>
<EasingDoubleKeyFrame KeyTime=”0:0:0.5″ Value=”5.667″/>
<EasingDoubleKeyFrame KeyTime=”0:0:2″ Value=”5.667″/>
<EasingDoubleKeyFrame KeyTime=”0:0:3″ Value=”5.667″/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)” Storyboard.TargetName=”image”>
<EasingDoubleKeyFrame KeyTime=”0″ Value=”26″/>
<EasingDoubleKeyFrame KeyTime=”0:0:0.5″ Value=”5.667″/>
<EasingDoubleKeyFrame KeyTime=”0:0:2″ Value=”5.667″/>
<EasingDoubleKeyFrame KeyTime=”0:0:3″ Value=”5.667″/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)” Storyboard.TargetName=”viewbox”>
<EasingDoubleKeyFrame KeyTime=”0″ Value=”0″/>
<EasingDoubleKeyFrame KeyTime=”0:0:3″ Value=”20″/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)” Storyboard.TargetName=”viewbox”>
<EasingDoubleKeyFrame KeyTime=”0″ Value=”0″/>
<EasingDoubleKeyFrame KeyTime=”0:0:3″ Value=”20″/>
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty=”(TextElement.Foreground).(SolidColorBrush.Color)” Storyboard.TargetName=”textBlock”>
<EasingColorKeyFrame KeyTime=”0″ Value=”#0087CEFA”/>
<EasingColorKeyFrame KeyTime=”0:0:1″ Value=”LightSkyBlue”/>
<EasingColorKeyFrame KeyTime=”0:0:2″ Value=”LightSkyBlue”/>
<EasingColorKeyFrame KeyTime=”0:0:3″ Value=”#0087CEFA”/>
</ColorAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)” Storyboard.TargetName=”textBlock”>
<EasingDoubleKeyFrame KeyTime=”0″ Value=”10″/>
<EasingDoubleKeyFrame KeyTime=”0:0:0.5″ Value=”1″/>
<EasingDoubleKeyFrame KeyTime=”0:0:2″ Value=”1″/>
<EasingDoubleKeyFrame KeyTime=”0:0:3″ Value=”1″/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)” Storyboard.TargetName=”textBlock”>
<EasingDoubleKeyFrame KeyTime=”0″ Value=”10″/>
<EasingDoubleKeyFrame KeyTime=”0:0:0.5″ Value=”1″/>
<EasingDoubleKeyFrame KeyTime=”0:0:2″ Value=”1″/>
<EasingDoubleKeyFrame KeyTime=”0:0:3″ Value=”1″/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)” Storyboard.TargetName=”textBlock”>
<EasingDoubleKeyFrame KeyTime=”0″ Value=”3″/>
<EasingDoubleKeyFrame KeyTime=”0:0:1″ Value=”0″/>
<EasingDoubleKeyFrame KeyTime=”0:0:2″ Value=”0″/>
<EasingDoubleKeyFrame KeyTime=”0:0:3″ Value=”0″/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)” Storyboard.TargetName=”textBlock”>
<EasingDoubleKeyFrame KeyTime=”0″ Value=”1″/>
<EasingDoubleKeyFrame KeyTime=”0:0:1″ Value=”0″/>
<EasingDoubleKeyFrame KeyTime=”0:0:2″ Value=”0″/>
<EasingDoubleKeyFrame KeyTime=”0:0:3″ Value=”0″/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.Opacity)” Storyboard.TargetName=”image”>
<EasingDoubleKeyFrame KeyTime=”0″ Value=”1″/>
<EasingDoubleKeyFrame KeyTime=”0:0:1″ Value=”1″/>
<EasingDoubleKeyFrame KeyTime=”0:0:2″ Value=”1″/>
<EasingDoubleKeyFrame KeyTime=”0:0:3″ Value=”0″/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent=”UIElement.MouseLeftButtonDown”>
<BeginStoryboard x:Name=”OnLoaded1_BeginStoryboard” Storyboard=”{StaticResource OnLoaded1}”/>
</EventTrigger>
<EventTrigger RoutedEvent=”FrameworkElement.Loaded”>
<BeginStoryboard Storyboard=”{StaticResource OnLoaded1}”/>
</EventTrigger>
</Window.Triggers>

<Grid x:Name=”LayoutRoot”>
<Image x:Name=”image” Margin=”0,95,-82,-22″ Source=”CS001.jpg” Stretch=”Fill” RenderTransformOrigin=”0.5,0.5″ HorizontalAlignment=”Right” Width=”290″>
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Viewbox x:Name=”viewbox” Margin=”215,166,268,158″ RenderTransformOrigin=”0.5,0.5″>
<Viewbox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Viewbox.RenderTransform>
<Viewbox.Effect>
<BlurEffect/>
</Viewbox.Effect>
<Ellipse Fill=”#00F4F4F5″ Height=”100″ Stroke=”LightSkyBlue” Width=”100″/>
</Viewbox>
<TextBlock x:Name=”textBlock” Margin=”161,199,161,160″ TextWrapping=”Wrap” FontFamily=”AR DESTINE” FontSize=”21.333″ Foreground=”LightSkyBlue” TextAlignment=”Center” RenderTransformOrigin=”0.5,0.5″>
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform><Run Language=”ja-jp” Text=”Chief Architect”/><LineBreak/><Run FontSize=”53.333″ Language=”ja-jp” Text=”Uchukamen”/></TextBlock>
</Grid>
</Window>

WPF であの花を降らせてみた

2011年9月4日

WPF で雪を降らせていたら、あの花を降らせてみてと言われたので、降らせてみた。

あの花 by WPF

 

ついでに、FlowerFactory をMomijiFactory に書き換えて、もみじにしてみた。

もみじ by WPF

 

メインXAML

<Window x:Class=”WpfAnohana.MainWindow”
        Background=”LightGray”
        xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
        xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
        Title=”MainWindow” Height=”480″ Width=”640″ Loaded=”Window_Loaded”>
    <Grid x:Name=”grid”>
        <Grid.Effect>
            <BlurEffect Radius=”5″></BlurEffect>
        </Grid.Effect>
    </Grid>
</Window>

メイン.cs

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace WpfAnohana
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            CreateFlowers();
        //    CreateMomiji();
        }

        // トランジション用(未実装)
        Queue<Viewbox> vb = new Queue<Viewbox>(2020);  

        private void CreateFlowers()
        {
            // Small Size, Fast
            CreateFlowers(0.05, 0.1, 1000, 5);
            // Medium Size
            CreateFlowers(0.1, 0.3, 1000, 10);
            // Large Size
            CreateFlowers(0.3, 1.0, 10, 10);
        }

        private void CreateMomiji()
        {
            // Small Size, Fast
            CreateMomiji(0.05, 0.1, 1000, 5);
            // Medium Size
            CreateMomiji(0.1, 0.3, 1000, 10);
            // Large Size
            CreateMomiji(0.3, 1.0, 20, 10);
        }

        private void CreateFlowers(double minSize, double maxSize, int count, int duration)
        {
            var flowerFactory = new FlowerFactory();
            for (int i = 0; i < count; i++)
            {
                var flower = (Flower)flowerFactory.Create(minSize + GetRnd(maxSize-minSize), duration);
                vb.Enqueue(flower);
                this.grid.Children.Add(flower);
                flower.BeginAnimation();
            }
        }

        private void CreateMomiji(double minSize, double maxSize, int count, int duration)
        {
            var momijiFactory = new MomijiFactory();
            for (int i = 0; i < count; i++)
            {
                var momiji = (Momiji)momijiFactory.Create(minSize + GetRnd(maxSize – minSize), duration);
                vb.Enqueue(momiji);
                this.grid.Children.Add(momiji);
                momiji.BeginAnimation();
            }
        }

        static Random rnd = new Random();

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

ShapeFactory.cs

using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace WpfAnohana
{
    /// <summary>
    /// ———————————————————————–
    /// Factory パターン
    /// ———————————————————————–
    /// </summary>
    abstract public class ShapeFactory
    {
        abstract public Viewbox Create(double size, int duration);
    }

    /// <summary>
    /// ———————————————————————–
    /// </summary>
    public class AnimatedViewbox : Viewbox
    {
        protected DoubleAnimationUsingKeyFrames daukfRot = null;
        protected DoubleAnimationUsingKeyFrames daukfX = null;
        protected DoubleAnimationUsingKeyFrames daukfY = null;

        public RotateTransform RotTrans { get; set; }
        public TranslateTransform TransX { get; set; }
        public TranslateTransform TransY { get; set; }

        public static DoubleAnimationUsingKeyFrames DoubleAnimation(TimeSpan beginTime, TimeSpan duration, int from, int to)
        {
            var daukfRot = new DoubleAnimationUsingKeyFrames();

            var ldkfR1 = new LinearDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0)),
                Value = from
            };

            var ldkfR2 = new LinearDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(duration),
                Value = to
            };

            daukfRot.KeyFrames.Add(ldkfR1);
            daukfRot.KeyFrames.Add(ldkfR2);
            daukfRot.BeginTime = beginTime;
            daukfRot.Duration = duration;
            daukfRot.RepeatBehavior = RepeatBehavior.Forever;

            return daukfRot;
        }

        public void BeginAnimation()
        {
            TransX.BeginAnimation(TranslateTransform.XProperty, daukfX);
            TransY.BeginAnimation(TranslateTransform.YProperty, daukfY);
            RotTrans.BeginAnimation(RotateTransform.AngleProperty, daukfRot);
        }

        static Random rnd = new Random();

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

FlowerFactory.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace WpfAnohana
{
    /// <summary>
    /// ———————————————————————–
    /// </summary>
    public class FlowerFactory : ShapeFactory
    {
        public override Viewbox Create(double size, int duration)
        {
            var flower = new Flower(size, duration);
            return flower;
        }
    }

    /// <summary>
    /// ———————————————————————–
    /// </summary>
    public class Flower : AnimatedViewbox
    {
        public Flower(double size, int duration)
        {
            Reverse = true;
            RenderTransform = GetTransform(size);
            HorizontalAlignment = HorizontalAlignment.Left;
            VerticalAlignment = VerticalAlignment.Top;
            RenderTransformOrigin = new Point(0.5, 0.5);
            Width = 100;
            Height = 100;
            Child = CreateFlowerPath(FlowerColor.GetNext());

            CreateAnimation(duration);
        }

        public bool Reverse { get; set; }

        private void CreateAnimation(int duration)
        {
            var begin0 = new TimeSpan(0, 0, 0);
            var duration10 = new TimeSpan(0, 0, duration);
            var beginTimeRnd = new TimeSpan(0, 0, 0, 0, (int)GetRnd(duration * 1000));

            int fromY = Reverse ? 600 : -50;
            int toY = Reverse ? -50: 600;

            daukfRot = DoubleAnimation(begin0, duration10, 0, 360 * 2);
            daukfX = DoubleAnimation(beginTimeRnd, duration10, 0, (int)GetRnd(200) – 100);
            daukfY = DoubleAnimation(beginTimeRnd, duration10, fromY, toY);
        }

        private TransformGroup GetTransform(double size)
        {
            var tg = new TransformGroup();
            var st = new ScaleTransform(size, size);
            var skewt = new SkewTransform();
            var tt = new TranslateTransform(GetRnd(640+200) – 100, -150);
            TransX = new TranslateTransform(0, 0);
            TransY = new TranslateTransform(0, 0);
            RotTrans = new RotateTransform();

            tg.Children.Add(st);
            tg.Children.Add(skewt);
            tg.Children.Add(RotTrans);
            tg.Children.Add(TransY);
            tg.Children.Add(TransX);
            tg.Children.Add(tt);

            return tg;
        }

        private static Shape CreateFlowerPath(Color col)
        {
            const string PathData = “M248,64 C236.5247,64.625058 225.71435,67.192184 215.5,71.5 L207.5,95.5 191.5,79.5 C179.10929,77.102304 168.53048,80.027027 159.5,87.5 159.50162,99.540561 161.46431,108.60788 167.5,111.5 L183.5,119.5 159.5,135.5 C160.12292,156.23214 162.17492,169.92602 167.5,167.5 172.91066,172.67869 180.71148,173.07705 191.5,167.5 L207.5,151.5 C203.2411,162.05534 202.55968,170.46419 207.5,175.5 219.38597,184.51719 230.14356,187.65745 239.5,183.5 L255.5,167.5 C252.80927,155.47101 245.02601,144.74873 231.5,135.5 L263.5,143.5 C272.5318,139.39663 278.23003,131.78108 279.5,119.5 276.83333,114.16667 274.16667,108.83333 271.5,103.5 262.70483,100.69259 251.88845,100.91719 239.5,103.5 248.65115,105.75263 260.3255,80.446287 248,64 z”;
           
            var g = PathGeometry.Parse(PathData);
            var br = new SolidColorBrush(col);
            var p = new Path();
            p.Width = 50;
            p.Height = 50;
            p.RenderTransformOrigin = new Point(0.5, 0.5);
            p.Stretch = Stretch.Fill;
            p.Data = g;
            p.Fill = br;

            return p;
        }

        static Random rnd = new Random();

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

        class FlowerColor
        {
            static Color[] col = {
                          Color.FromRgb(222,89,182),
                              Color.FromRgb(247,203,224),
                              Color.FromRgb(239,78,100),
                              Color.FromRgb(243,141,147),
                              Color.FromRgb(240,154,232),
                              Color.FromRgb(244,228,188),
                              Color.FromRgb(246,187,167)
                      };

            static int i = -1;
            public static Color GetNext()
            {
                if (++i >= col.Length)
                    i = 0;
                return col[i];
            }
        }
    }
}

MomijiFactory.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace WpfAnohana
{

    /// <summary>
    /// ———————————————————————–
    /// </summary>
    public class MomijiFactory : ShapeFactory
    {
        public override Viewbox Create(double size, int duration)
        {
            var momiji = new Momiji(size, duration);
            return momiji;
        }
    }

    /// <summary>
    /// ———————————————————————–
    /// </summary>
    public class Momiji : AnimatedViewbox
    {
        public Momiji(double size, int duration)
        {
            RenderTransform = GetTransform(size);
            HorizontalAlignment = HorizontalAlignment.Left;
            VerticalAlignment = VerticalAlignment.Top;
            RenderTransformOrigin = new Point(0.5, 0.5);
            Width = 100;
            Height = 100;
            Child = CreateMomijiPath(MomijiColor.GetNext());

            CreateAnimation(duration);
        }

        private void CreateAnimation(int duration)
        {
            var begin0 = new TimeSpan(0, 0, 0);
            var duration10 = new TimeSpan(0, 0, duration);
            var beginTimeRnd = new TimeSpan(0, 0, 0, 0, (int)GetRnd(duration * 1000));

            daukfRot = DoubleAnimation(begin0, duration10, 0, 360 * 2);
            daukfX = DoubleAnimation(beginTimeRnd, duration10, 0, (int)GetRnd(200) – 100);
            daukfY = DoubleAnimation(beginTimeRnd, duration10, -50, 600);
        }

        private TransformGroup GetTransform(double size)
        {
            var tg = new TransformGroup();
            var st = new ScaleTransform(size, size);
            var skewt = new SkewTransform();
            var tt = new TranslateTransform(GetRnd(640) – 100, -150);
            TransX = new TranslateTransform(0, 0);
            TransY = new TranslateTransform(0, 0);
            RotTrans = new RotateTransform();

            tg.Children.Add(st);
            tg.Children.Add(skewt);
            tg.Children.Add(RotTrans);
            tg.Children.Add(TransY);
            tg.Children.Add(TransX);
            tg.Children.Add(tt);

            return tg;
        }

        private static Shape CreateMomijiPath(Color col)
        {
            const string PathData = “M183.66667,86.666667 C189.39235,102.51222 195.97031,115.69911 204.00303,124.34783 189.46184,124.37625 176.55191,127.63058 166.26051,130.07866 177.67961,136.62725 192.00787,141.50314 209.25719,141.39676 203.19164,149.57713 198.0335,156.49435 192.99912,166.33255 202.42621,162.74626 210.94614,156.64738 218.66605,148.33266 L222.66553,167.66588 C225.54016,165.52929 227.12504,154.35884 228.999,141.99936 234.06358,144.63928 238.15358,153.77991 241.33226,168.99921 L243.66592,167.99921 C241.1493,155.99855 236.78856,146.70538 230.66566,139.99937 241.69194,144.10578 251.73257,143.90948 260.99883,140.3327 255.36431,137.34626 248.38965,134.93892 240.33229,132.99941 250.52631,127.61701 259.03319,119.28195 265.66548,107.66621 L234.3321,118.99948 C236.99567,104.86417 236.63427,91.185053 232.99878,77.999712 226.74482,85.30016 221.8588,98.979918 218.33224,118.99948 209.59223,103.54312 197.83014,93.109381 183.66667,86.666667 z”;

            var g = PathGeometry.Parse(PathData);
            var br = new SolidColorBrush(col);
            var p = new Path();
            p.RenderTransformOrigin = new Point(0.5, 0.5);
            p.Stretch = Stretch.Fill;
            p.Data = g;
            p.Fill = br;

            return p;
        }

        static Random rnd = new Random();

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

        class MomijiColor
        {
            static Color[] col = {
                          Color.FromRgb((byte)0xdc,(byte)0x14,(byte)0x3c),
                          Color.FromRgb(239, 119,33),
                          Color.FromRgb(255, 51,45),
                          Color.FromRgb(239, 119,33),
                          Color.FromRgb(255, 51,45),
                          Colors.Gold,
                          Color.FromRgb(34,136,34)
                      };

            static int i = -1;
            public static Color GetNext()
            {
                if (++i >= col.Length)
                    i = 0;
                return col[i];
            }
        }
    }
}

WPF でキュウべえを降らせてみた

2011年8月29日

WPFで雪を降らせていたら、キュウべえを降らせてみてと言われたので、降らせてみた。

Let it snow!

 

雪バージョンとの違いは、WPF で キュウべえをデザインして、それをC#で Clone() しているだけで、ほとんど同じ。さすがにテクスチャーマッピングしているので、かなり重いです。

WPF で雪を降らせてみた

2011年8月28日

Let it snow.

 

<Window x:Class=”SnowFall.Window1″ Background=”Black” Title=”SnowFall” Width=”400″ Height=”300″ 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/interactivedesigner/2006″ xmlns:c=”http://schemas.openxmlformats.org/markup-compatibility/2006″ c:Ignorable=”d” Loaded=”Window_Loaded”>
    <Grid>
        <Viewport3D x:Name=”ZAM3DViewport3D” ClipToBounds=”true” >
            <Viewport3D.Effect>
                <BlurEffect Radius=”10″></BlurEffect>
            </Viewport3D.Effect>
            <Viewport3D.Camera>
                <PerspectiveCamera x:Name=”Target_CameraOR6″ FarPlaneDistance=”100″ LookDirection=”0,2,-1″ UpDirection=”0,1,0″ NearPlaneDistance=”0.1″ Position=”0,-5,5″ FieldOfView=”50″ />
            </Viewport3D.Camera>

            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <Model3DGroup x:Name=”Scene” >
                        <AmbientLight Color=”#7777FF” />
                        <DirectionalLight Color=”#FFFFFF” Direction=”-0.612372,-0.5,-0.612372″ />
                        <DirectionalLight Color=”#FFFFFF” Direction=”0.612372,-0.5,-0.612372″ />
                        <Model3DGroup x:Name=”Model3DG” />
                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </Viewport3D>
    </Grid>
</Window>

C# Code

using System;
using System.Windows;
using System.Windows.Media.Media3D;
using System.Windows.Media.Animation;
using System.Windows.Media;
using System.Windows.Markup;

namespace SnowFall
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>

    public partial class Window1 : System.Windows.Window
    {
        private const int maxSnow = 1000;

        public Window1()
        {
            InitializeComponent();
        }

        Snow[] snow = new Snow[maxSnow];

        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);

                this.Model3DG.Children.Add(snow[i].snowBall);

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

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

        public DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames();

        public Snow()
        {
            snowBall.Geometry = GetBall();
            snowBall.Transform = GetTransform(0.1);
            snowBall.Material = new DiffuseMaterial(new SolidColorBrush(Colors.White));

            daukf = CreateAnimation();
        }

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

            daukf = CreateAnimation();
        }

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

        public TranslateTransform3D t2 { get; set; }

        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);
            t2 = new TranslateTransform3D(0, 0, 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.TriangleIndices = new Int32Collection { 0, 1, 2, 3, 0, 2,…..240, 226 };
            ball.Normals = new Vector3DCollection { new Vector3D(0.18024, 0.980785, 0.0746578), …., new Vector3D(0, -1, 0) };
            ball.Positions = new Point3DCollection { new Point3D(0.09012, 0.490393, 0.0373289), … new Point3D(0, -0.5, 0) };
            return ball;
        }

        LinearDoubleKeyFrame ldkf1 = new LinearDoubleKeyFrame();
        LinearDoubleKeyFrame ldkf2 = new LinearDoubleKeyFrame();

        private DoubleAnimationUsingKeyFrames CreateAnimation()
        {
            ldkf1.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0));
            ldkf1.Value = 20;

            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;

            return daukf;
        }

        Random rnd = new Random();
        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;
        }
    }
}

WPF CreateBall

2011年8月28日

これもテスト用コードのメモ。

private GeometryModel3D CreateBall()
{
    MeshGeometry3D ball = new MeshGeometry3D();
    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) };
    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) };

    Transform3DGroup t3dg = new Transform3DGroup();
    ScaleTransform3D s01 = new ScaleTransform3D(0.1, 0.1, 0.1);
    RotateTransform3D r01 = new RotateTransform3D();
    TranslateTransform3D t1 = new TranslateTransform3D(GetRnd(), -1, GetRnd());
    TranslateTransform3D t2 = new TranslateTransform3D(0, 0, 0);

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

    GeometryModel3D gm3d = new GeometryModel3D();

    gm3d.Geometry = ball;

    SolidColorBrush vb = new SolidColorBrush(Colors.Red);
    gm3d.Material = new DiffuseMaterial(vb);

    gm3d.Transform = t3dg;

    return gm3d;
}