Skip to content

Instantly share code, notes, and snippets.

@otac0n
Created May 22, 2023 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otac0n/ef99be255d7c001b39ed9740c220e66c to your computer and use it in GitHub Desktop.
Save otac0n/ef99be255d7c001b39ed9740c220e66c to your computer and use it in GitHub Desktop.
// Set up Animations
var chain = new MarkovChain<string>(1);
chain.Add(new[] { "Sitting" }, "Sitting", 50);
chain.Add(new[] { "Sitting" }, "Grooming", 20);
chain.Add(new[] { "Sitting" }, "Sleeping", 20);
chain.Add(new[] { "Sitting" }, "Playing", 10);
chain.Add(new[] { "Playing" }, "Sitting", 100);
chain.Add(new[] { "Sleeping" }, "Sleeping", 60);
chain.Add(new[] { "Sleeping" }, "Sitting", 40);
chain.Add(new[] { "Grooming" }, "Grooming", 20);
chain.Add(new[] { "Grooming" }, "Sitting", 80);
// Set up Images
var framesPerState = new Dictionary<string, int>
{
{ "Sitting", 5 },
{ "Playing", 12 },
{ "Sleeping", 3 },
{ "Grooming", 8 },
};
var cancelSource = new CancellationTokenSource();
var cancel = cancelSource.Token;
// Allow for 1 minute, by default.
// You can change this to only cancel when the user requests, etc.
cancelSource.CancelAfter(TimeSpan.FromMinutes(1));
foreach (var state in chain.Chain(new[] { "Sitting" }))
{
if (cancel.IsCancellationRequested)
{
break;
}
var frames = framesPerState[state];
for (var i = 0; i < frames; i++)
{
Console.WriteLine($"Show Frame: {state}-{i}.png");
// You can do this any number of ways, depending on your rendering platform.
}
Thread.Sleep(TimeSpan.FromSeconds(1.0 / 30));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment