Skip to content

Instantly share code, notes, and snippets.

@sdenchev
Created December 20, 2013 23:35
Show Gist options
  • Select an option

  • Save sdenchev/8063358 to your computer and use it in GitHub Desktop.

Select an option

Save sdenchev/8063358 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
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 Rin
{
public static class Aid
{
public static int min = 10;
public static int max = 25;
public static int Width = 1366;
public static int Height = 768;
public static Random RNG = new Random();
}
}
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
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 Rin
{
public class Flake : INotifyPropertyChanged
{
private int x;
public int X
{
get { return x; }
set
{
x = value;
Notify("X");
}
}
private int y;
public int Y
{
get { return y; }
set
{
y = value;
Notify("Y");
}
}
Timer Speed = new Timer(Aid.RNG.Next(Aid.min, Aid.max));
Timer Delay = new Timer(Aid.RNG.Next(10, Aid.Height*20));
public Flake()
{
this.X = Aid.RNG.Next(Aid.Width);
this.Y = 0;
Speed.Elapsed += Move;
Delay.Elapsed += Delay_Elapsed;
Delay.Start();
}
void Delay_Elapsed(object sender, ElapsedEventArgs e)
{
Speed.Start();
Delay.Stop();
}
void Move(object sender, ElapsedEventArgs e)
{
this.Y++;
if (this.Y > Aid.Height)
{
this.X = Aid.RNG.Next(Aid.Width);
this.Y = 0;
this.Speed.Interval = Aid.RNG.Next(10, 25);
}
}
public void Notify(string name = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
<Window x:Class="Rin.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:Rin"
Title="Rin" Height="350" Width="525" AllowsTransparency="True"
WindowStyle="None" WindowState="Maximized" Background="{x:Null}" Topmost="True" ShowInTaskbar="False">
<Window.Resources>
<l:VM x:Key="vm"/>
</Window.Resources>
<Grid DataContext="{StaticResource ResourceKey=vm}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ItemsControl ItemsSource="{Binding Flakes}" Grid.ColumnSpan="10" Grid.RowSpan="10">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Path=X}"/>
<Setter Property="Canvas.Top" Value="{Binding Path=Y}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Ellipse Fill="WhiteSmoke" Width="5" Height="5"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
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 Rin
{
public class VM
{
private ObservableCollection<Flake> flakes;
public ObservableCollection<Flake> Flakes
{
get { return flakes; }
set { flakes = value; }
}
public int Total { get; set; }
public VM()
{
Flakes = new System.Collections.ObjectModel.ObservableCollection<Flake>();
Total = 150;
for (int i = 0; i < Total; i++)
Flakes.Add(new Flake());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment