turing-machine-viz icon indicating copy to clipboard operation
turing-machine-viz copied to clipboard

How to change the time step when autorun?

Open patrikfejda opened this issue 3 years ago â€ĸ 2 comments

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 :)

patrikfejda avatar Mar 30 '22 20:03 patrikfejda

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.

aepsilon avatar Mar 31 '22 06:03 aepsilon

Thanks for the solution.

I applied your changes here.

Maybe someone may find it useful.

BTW. very cool project, thanks :)

patrikfejda avatar Mar 31 '22 09:03 patrikfejda