Skip to content

Instantly share code, notes, and snippets.

@psqq
Created December 8, 2015 22:44
Show Gist options
  • Save psqq/332e1164e0e960fdceb4 to your computer and use it in GitHub Desktop.
Save psqq/332e1164e0e960fdceb4 to your computer and use it in GitHub Desktop.
"use strict";
var program = `d m 100 100 u m 100 0 d m 200 100`;
var x = 0, y = 0, raised = true;
var words = program.match(/\w+/g);
for (var i = 0; i < words.length; i++) {
if (words[i].toUpperCase() == 'D') raised = false;
if (words[i].toUpperCase() == 'U') raised = true;
if (words[i].toUpperCase() == 'M') {
var nx = parseInt(words[++i]), ny = parseInt(words[++i]);
if (!raised) {
var ctx = document.getElementById("c").getContext('2d');
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(nx, ny);
ctx.stroke();
}
x = nx; y = ny;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment