-
-
Save JBou/9885858 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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