Created
December 8, 2015 22:44
-
-
Save psqq/332e1164e0e960fdceb4 to your computer and use it in GitHub Desktop.
This 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 characters
"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