Skip to content

Commit

Permalink
- Added support for escape key to exit in turing drawings and
Browse files Browse the repository at this point in the history
  turing turtle example programs
- Made use of SBSTP's option parser in turing turtle program
  • Loading branch information
maximecb committed Feb 1, 2015
1 parent f03e1f2 commit bc205be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions examples/turing-drawings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Maxime Chevalier-Boisvert
*/

// Import required libraries
var std = require('lib/stdlib');
var draw = require('lib/draw');
var image = require('lib/image');
var rnd = require('lib/random');
Expand Down Expand Up @@ -309,6 +310,10 @@ window.onKeypress(function(canvas, key)
{
paused = !paused;
}
else if (key === 'Escape')
{
std.exit(0);
}
});

window.onRender(function(canvas)
Expand Down
20 changes: 16 additions & 4 deletions examples/turing-turtle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ Maxime Chevalier-Boisvert
*/

// Import required libraries
var std = require('lib/stdlib');
var draw = require('lib/draw');
var image = require('lib/image');
var rnd = require('lib/random');
var Options = require('lib/options').Options;

// ===========================================================================

Expand Down Expand Up @@ -264,14 +266,20 @@ Machine.prototype.update = function (numItrs)

// ===========================================================================

/// Canvas dimensions
var canvasWidth = arguments[0]? Math.max(parseInt(arguments[0]), 400):600;
var canvasHeight = arguments[1]? Math.max(parseInt(arguments[1]), 400):600;
// Parse the command line arguments
var o = Options()
.autoHelp()
.autoVersion()
.add('width' , 600, '+int', 'canvas width', 'w')
.add('height', 600, '+int', 'canvas height', 'h');
var args = o.parse(arguments);
var canvasWidth = args.width;
var canvasHeight = args.height;

/// Current Turing machine
var machine;

// Last machine position
/// Last machine position
var lastPosX;
var lastPosY;

Expand Down Expand Up @@ -340,6 +348,10 @@ window.onKeypress(function(canvas, key)
window.canvas.clear(bgColor);
machine.reset();
}
else if (key === 'Escape')
{
std.exit(0);
}
});

window.onRender(function(canvas)
Expand Down

0 comments on commit bc205be

Please sign in to comment.