Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A tiny class to make strange crypted animated text as you know it from Minecraft. Sounds useless? It is useless! :D
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;
}
}
}
@leMaik
Copy link
Author

leMaik commented Nov 23, 2013

Use it like this:

//This will animate the window title (put it inside your window's class)
BeginAnimation(Window.TitleProperty, new CryptedTextAnimation() { Length = this.Title.Length, Duration = Duration.Forever });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment