Created
          May 22, 2023 09:22 
        
      - 
      
- 
        Save otac0n/ef99be255d7c001b39ed9740c220e66c to your computer and use it in GitHub Desktop. 
Revisions
- 
        otac0n created this gist May 22, 2023 .There are no files selected for viewingThis file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ // 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)); }