Article From:https://www.cnblogs.com/lonelyxmas/p/9689214.html
WPF: Simulation of sun, earth and moon trajectories

Copyright notice: This article is an original article for bloggers. It can not be reproduced without permission from bloggers. Https://blog.csdn.net/yangyisen0713/article/details/18216803

WPFSimulate the sun. The simulation of the trajectory of the moon and the earth has not yet been added to the animation of the sun’s autobiography.

Mainly using EllipseGeometry to achieve path rendering.

xamlThe code is as follows:

<Window x:Class="MyFirstWpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="The Earth, Moon and Sun motion simulation "Height =" 768 "Width =" 1366 "Windows Startup Location =" CenterScreen "& gt;< Grid≫< Grid.Background>< ImageBrush ImageSource= "earth.jpg" />< /Grid.Background>< Ellipse Height= "150" HorizontalAlignment= "Left"Margin= "619321,0,0" Name= "ellipse3" VerticalAlignment= "Top" Width= "150" ToolTip= "sun" >< Ellipse.Fill>< LinearGradientBrush EndPoint= "1,0.5" StartPoint= "0,0.5">< GradientStop Color= "#FFFFCA00" Offset= "0.246" />< GradientStop Color= "#FFFF0034" Offset= "0.967" />< /LinearGradientBrush>< /Ellipse.Fill>< /Ellipse><!! - by using EllipseGeometrY implements ellipse path drawing -->< Path Margin= "308136120,81" Stroke= "#FFFF7900" RenderTransformOrigin="0.415,0.498" >< Path.Data>< EllipseGeometry Center= "400250 "RadiusX=" 400 "RadiusY=" 250 "x:Name=" E1 "/>";< /Path.Data>< /Path&gT;< Grid Height= "352" HorizontalAlignment= "Left" Margin= "30, -12,0,0" Name= "GRID1" VerticAlAlignment= "Top" Width= "484" >< Grid.RenderTransform>< MatRixTransform x:Name= "grid" />< /Grid.RenderTransform><!! --Grid touchHair device -->< Grid.Triggers>< EventTrigger RoutedEvent= "Page.LoadEd ">< BeginStoryboard>< Storyboard x:Name="SB1" RepeatBehavior= "Forever" >< MatrixAnimationUsingPath x:Name="MA1"Storyboard.TargetName= "grid"Storyboard.TargetProperty= "Matrix"Duration= "0:1:0" />< /Storyboard>< /BeginStoryboard>< /EventTrigger>< /Grid.Triggers>< Ellipse Height= "100" HorizontalAlignment= "Left" Margin= "227".94,0,0 "Name=" ellipse1 "VerticalAlignment=" Top "Width=" 100 "ToolTip=" Earth ">";< ElLipse.Fill>< LinearGradientBrush EndPoint= "1,0.5" StartPoint= "0,0.5" >< GradientStop Color= "#FFE0DFDD" Offset= "0" />< GradientStop Color= "#FF0035FF" Offset= "0.975" />< /LinearGradientBrUsh>< /Ellipse.Fill>< Ellipse.RenderTransform>< TransformGroup>< MatrixTransform x:Name= "Earth" />< /TransformGroup>< /Ellipse.RenderTransform>< Ellipse.Triggers>< EventTrigger RoutedEvent= "Page.LoAded ">< /EventTrigger>< /Ellipse.Triggers>< /Ellipse>< Ellipse Height= "50" HorizontalAlignment= "Left" Margin= "228,40,0,0 "Name=" ellipse2 "VerticalAlignment=" Top "Width=" 50 "ToolTip=" Moon ">";< ELlipse.Fill>< LinearGradientBrush EndPoint= "1,0.5" StartPoint= "0,0.5" >< GradientStop Color= "White" Offset= "0" />≪ GradientStop Color= "#FFDDD2BE" Offset= "0.943" />< /LinearGradientBrush>< /Ellipse.Fill>< Ellipse.RenderTransform>< TransformGroup>< MatrixTransform x:Name= "Moon" />< /TransformGroup>< /Ellipse.RenderTransform>< Ellipse.Triggers>< EventTrigger RoutedEvent= "Page.Loaded">< BeginStoryboard>< Storyboard xName= "SB2" RepeatBehavior= "Forever" >< MatrixAnimationUsingPaTh x:Name= "ma2"Storyboard.TargetName= "Moon"Storyboard.TargetProperty= "Matrix"Duration= "0:0:30" >< /MatrixAnimationUsingPath>< /Storyboard>< /BeginStoryboard>< /EventTrigger>< /Ellipse.Triggers>< /Ellipse>< Path Margin= "262.522,59,0,93" HOrizontalAlignment= "Left" Width= "122" Height= "200" Stroke= "#FF00FF40" >< Path.Data>< EllipseGeometry x:Name= "ellipseGeometry1" Center= "50100" RadiusX="50" RadiusY= "100" >< EllipseGeometry.Transform>< SkewTransform AngleY= "-20" > < /SkewTransform>< /ELlipseGeometry.Transform>< /EllipseGeometry>< /PatH.Data>< /Path>< /Grid>< TextBox HorizontalAlignmenT = "Left" Height = "110" Margin = "891, 7, 0, 0" Text Wrapping = "Wrap" Text = "The Earth revolves around the sun, the moon revolves around the earth. The sun, the earth and the moon are all spinning. The sun is the sun.The stars of the system are stars. The earth is a planet in the solar system, and the moon is a natural satellite of the earth. The earth revolves around the sun, and the moon revolves around the earth. The sun can not be located between the earth and the moon. "VerticalAlignment=" Top "Width="448 "Background=" {x:Null} "Foreground=" #FF009DFF "BorderBrush=" #FF0012FF "/>";< /Grid>≪ /Window>

The final effect is as follows:

Leave a Reply

Your email address will not be published. Required fields are marked *