我是靠谱客的博主 糊涂斑马,这篇文章主要介绍WPF太阳、地球、月球运动轨迹模拟,现在分享给大家,希望可以做个参考。

原文:WPF太阳、地球、月球运动轨迹模拟

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yangyisen0713/article/details/18216803

WPF模拟太阳。月球、地球三者运动轨迹的模拟,现在还没有加上太阳自传的动画,有兴趣的可以加上。

主要是利用EllipseGeometry实现路径的绘制

xaml代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<Window x:Class="WpfApp11.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="地球、月球、太阳运动模拟" Width="1366" Height="768" WindowStartupLocation="CenterScreen"> <Grid> <Grid.Background> <ImageBrush ImageSource="earth.jpg" /> </Grid.Background> <Ellipse Name="ellipse3" Width="150" Height="150" Margin="619,321,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" ToolTip="太阳"> <Ellipse.Fill> <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5"> <GradientStop Offset="0.246" Color="#FFFFCA00" /> <GradientStop Offset="0.967" Color="#FFFF0034" /> </LinearGradientBrush> </Ellipse.Fill> </Ellipse> <!-- 通过使用EllipseGeometry实现椭圆路径的绘制 --> <Path Margin="308,136,120,81" RenderTransformOrigin="0.415,0.498" Stroke="#FFFF7900" StrokeThickness="5"> <Path.Data> <EllipseGeometry x:Name="e1" Center="400 250" RadiusX="400" RadiusY="250" /> </Path.Data> </Path> <Grid Name="grid1" Width="484" Height="352" Margin="30,-12,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"> <Grid.RenderTransform> <MatrixTransform x:Name="grid" /> </Grid.RenderTransform> <!-- Grid触发器 --> <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 Name="ellipse1" Width="100" Height="100" Margin="227,94,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" ToolTip="地球"> <Ellipse.Fill> <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5"> <GradientStop Offset="0" Color="#FFE0DFDD" /> <GradientStop Offset="0.975" Color="#FF0035FF" /> </LinearGradientBrush> </Ellipse.Fill> <Ellipse.RenderTransform> <TransformGroup> <MatrixTransform x:Name="earth" /> </TransformGroup> </Ellipse.RenderTransform> <Ellipse.Triggers> <EventTrigger RoutedEvent="Page.Loaded" /> </Ellipse.Triggers> </Ellipse> <Ellipse Name="ellipse2" Width="50" Height="50" Margin="228,40,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" ToolTip="月球"> <Ellipse.Fill> <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5"> <GradientStop Offset="0" Color="White" /> <GradientStop Offset="0.943" Color="#FFDDD2BE" /> </LinearGradientBrush> </Ellipse.Fill> <Ellipse.RenderTransform> <TransformGroup> <MatrixTransform x:Name="moon" /> </TransformGroup> </Ellipse.RenderTransform> <Ellipse.Triggers> <EventTrigger RoutedEvent="Page.Loaded"> <BeginStoryboard> <Storyboard x:Name="sb2" RepeatBehavior="Forever"> <MatrixAnimationUsingPath x:Name="ma2" Storyboard.TargetName="moon" Storyboard.TargetProperty="Matrix" Duration="0:0:30" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Ellipse.Triggers> </Ellipse> <Path Width="122" Height="200" Margin="262.522,59,0,93" HorizontalAlignment="Left" Stroke="#FF00FF40" StrokeThickness="5"> <Path.Data> <EllipseGeometry x:Name="ellipseGeometry1" Center="50 100" RadiusX="50" RadiusY="100"> <EllipseGeometry.Transform> <SkewTransform AngleY="-20" /> </EllipseGeometry.Transform> </EllipseGeometry> </Path.Data> </Path> </Grid> <TextBox Width="448" Height="110" Margin="891,7,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Background="{x:Null}" BorderBrush="#FF0012FF" BorderThickness="0" Foreground="White" Text="地球饶太阳公转,月球饶地球公转。太阳、地球、月球都在自转太阳是太阳系的主宰,是恒星。地球是太阳系的一颗行星,月球是地球的一颗天然卫星。地球绕着太阳公转,月球绕着地球公转。太阳不可能位于地球和月球之间。" TextWrapping="Wrap" /> </Grid> </Window>

 

最后效果如图:



复制代码
1
2
3
4
5
6
7
public MainWindow() { InitializeComponent(); ma2.PathGeometry = ellipseGeometry1.GetFlattenedPathGeometry(); ma1.PathGeometry = e1.GetFlattenedPathGeometry(); }

 

最后

以上就是糊涂斑马最近收集整理的关于WPF太阳、地球、月球运动轨迹模拟的全部内容,更多相关WPF太阳、地球、月球运动轨迹模拟内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部