Skip to content

Instantly share code, notes, and snippets.

@JBou
Forked from leMaik/CryptedTextAnimation.cs
Created March 31, 2014 05:28
Show Gist options
  • Save JBou/9885858 to your computer and use it in GitHub Desktop.
Save JBou/9885858 to your computer and use it in GitHub Desktop.
using System;
using System.Text;
using System.Windows;
using System.Windows.Media.Animation;
namespace leMaik.Animations {
class CryptedTextAnimation : AnimationTimeline {
static CryptedTextAnimation() {
LengthProperty = DependencyProperty.Register("Length", typeof(int), typeof(CryptedTextAnimation));
}
public static readonly DependencyProperty LengthProperty;
public int Length {
get {
return (int)GetValue(CryptedTextAnimation.LengthProperty);
}
set {
SetValue(CryptedTextAnimation.LengthProperty, value);
}
}
private const String CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+#-.?!";
private Random randomizer = new Random(Environment.TickCount);
private String previousString = String.Empty;
public override Type TargetPropertyType {
get { return typeof(String); }
}
protected override System.Windows.Freezable CreateInstanceCore() {
return new CryptedTextAnimation();
}
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock) {
if (animationClock.CurrentTime.Value.TotalSeconds % 0.5 < 0.5) {
StringBuilder str = new StringBuilder(Length);
for (int i = 0; i < Length; i++) {
str.Append(CHARACTERS[randomizer.Next(CHARACTERS.Length)]);
}
previousString = str.ToString();
}
return previousString;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment