Repository navigation
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
64 lines (55 loc) · 2.04 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
64 lines (55 loc) · 2.04 KB
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
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SolarSystemMultiThread
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private ViewModel.CanvasViewModel ViewModel = null;
/// <summary>
/// Initializes a new instance of the <see cref="MainWindow"/> class.
/// </summary>
/// <remarks>This constructor sets up the main application window by initializing its components,
/// creating the starfield effect, and setting the data context
public MainWindow()
{
InitializeComponent();
CreateStarfield();
ViewModel = new ViewModel.CanvasViewModel();
this.DataContext = ViewModel;
}
/// <summary>
/// Generates a starfield by creating and adding a collection of randomly sized, positioned, and styled stars
/// to the canvas.
/// </summary>
private void CreateStarfield()
{
Random random = new Random();
for (int i = 0; i < 150; i++) // Create 150 stars
{
Ellipse star = new Ellipse()
{
Width = random.Next(2, 4), // Random size between 2-5
Height = random.Next(2, 4),
Fill = Brushes.White,
Opacity = random.Next(50, 100) / 100.0 // Random opacity between 0.5-1.0
};
// Random position within canvas bounds
Canvas.SetLeft(star, random.Next(0, 800));
Canvas.SetTop(star, random.Next(0, 800));
Canvas.SetZIndex(star, -1); // Set ZIndex to ensure stars are in the background
canvasUniverse.Children.Add(star);
}
}
}
}