Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the time step when autorun? #9

Open
patrikfejda opened this issue Mar 30, 2022 · 2 comments
Open

How to change the time step when autorun? #9

patrikfejda opened this issue Mar 30, 2022 · 2 comments

Comments

@patrikfejda
Copy link

Hello guys,

sorry that this is not an Issue, but I have one question:

How can I run the machine faster when autorunning the machine?
I coud not find the time step defined in the source code.

Thanks :)

@aepsilon
Copy link
Owner

There's not a built-in way to adjust the time step, but you can try this in the JS console to speed it up slightly:

main.controller.simulator.machine.stepInterval = 0

However, most of the animations use the default D3 transition duration. They need an explicit .duration() to be set. Here's a quick and dirty patch that does that for the causes of slowness.

diff --git a/src/TMViz.js b/src/TMViz.js
index 5e356a2..12283ef 100644
--- a/src/TMViz.js
+++ b/src/TMViz.js
@@ -16,6 +16,8 @@ var TuringMachine = require('./TuringMachine').TuringMachine,
     watchInit = require('./watch').watchInit,
     d3 = require('d3');
 
+const transition_duration_ms = 100;
+
 /**
  * Create an animated transition function.
  * @param  {StateGraph} graph
@@ -42,8 +44,10 @@ function pulseEdge(edge) {
   return edgepath
       .classed('active-edge', true)
     .transition()
+      .duration(transition_duration_ms)
       .style('stroke-width', '3px')
     .transition()
+      .duration(transition_duration_ms)
       .style('stroke-width', '1px')
     .transition()
       .duration(0)
@@ -77,7 +81,7 @@ function TMViz(div, spec, posTable) {
   if (posTable != undefined) { this.positionTable = posTable; }
 
   this.edgeAnimation = pulseEdge;
-  this.stepInterval = 100;
+  this.stepInterval = transition_duration_ms;
 
   var self = this;
   // We hook into the animation callback to know when to start the next step (when running).

The tape animations probably need to be updated as well to look similar, but this is already enough to speed things up to a blur when the duration is configured to near zero.

Feel free to leave this issue open. I think it's a good feature request.

@patrikfejda
Copy link
Author

Thanks for the solution.

I applied your changes here.

Maybe someone may find it useful.

BTW. very cool project, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants