|
PH Logo
Logo intepreter modeled after UCB Logo.
|
#include <Turtle.h>
The turtle outputs graphics in the form of JSON data with operations that operate directly on a canvas in HTML.
Operations are:
"m:[x, y]" -> moveTo(x, y) "l:[x, y]" -> lineTo(x, y) "s:0" -> stroke()
Here is a driver program in JavaScript that will draw this data, given a canvas in the html called "canvas".
function canvas() { var ctx = document.getElementsByTagName('canvas')[0].getContext('2d'); ctx.strokeStyle = "#00CC00"; ctx.lineWidth = 1; return ctx; }
function doop(ctx, op) { if (typeof(op.m) != "undefined") { ctx.moveTo(op.m[0], op.m[1]); } else if (typeof(op.l) != "undefined") { ctx.lineTo(op.l[0], op.l[1]); } else if (typeof(op.s) != "undefined") { ctx.stroke(); } }
var ctx = canvas(); for (l in gdata) { doop(ctx, gdata[l]); }
1.7.4