picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

commit 22e85b79fe7613dd6d110f99f8d924daf559062c
parent 2691dd2d51ac60c472498d25e99d1c2da248782d
Author: Alexander Burger <abu@software-lab.de>
Date:   Wed, 15 May 2013 16:47:44 +0200

Added "lib/canvas.js" and "lib/canvas.l"
Diffstat:
Alib/canvas.js | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alib/canvas.l | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 200 insertions(+), 0 deletions(-)

diff --git a/lib/canvas.js b/lib/canvas.js @@ -0,0 +1,134 @@ +/* 15may13abu + * (c) Software Lab. Alexander Burger + */ + +var DrawReq = new XMLHttpRequest(); + +function drawCanvas(id, dly) { + if (!DrawReq) + return true; + try { + DrawReq.open("POST", + document.getElementsByTagName("BASE")[0].href + SesId + + "!jsDraw?" + id ); + DrawReq.responseType = "arraybuffer"; + } + catch (e) {return true;} + DrawReq.onload = function() { + var lst = plio(new Uint8Array(DrawReq.response)); + var cmd, i, j; + + if (lst) { + var ctx = document.getElementById(id).getContext("2d"); + + for (i = 0; i < lst.length; ++i) { + switch ((cmd = lst[i])[0]) { // In sync with "@lib/canvas.l" + /*** Functions ***/ + case 1: + ctx.fillText(cmd[1], cmd[2], cmd[3]); + break; + case 2: + ctx.beginPath(); + ctx.moveTo(cmd[1], cmd[2]); + ctx.lineTo(cmd[3], cmd[4]); + ctx.closePath(); + ctx.stroke(); + break; + case 3: + ctx.clearRect(cmd[1], cmd[2], cmd[3], cmd[4]); + break; + case 4: + ctx.strokeRect(cmd[1], cmd[2], cmd[3], cmd[4]); + break; + case 5: + ctx.fillRect(cmd[1], cmd[2], cmd[3], cmd[4]); + break; + case 6: + ctx.beginPath(); + break; + case 7: + ctx.closePath(); + break; + case 8: + ctx.moveTo(cmd[1], cmd[2]); + break; + case 9: + ctx.lineTo(cmd[1], cmd[2]); + break; + case 10: + ctx.bezierCurveTo(cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6]); + break; + case 11: + ctx.moveTo(cmd[1], cmd[2]); + ctx.lineTo(cmd[3], cmd[4]); + break; + case 12: + ctx.rect(cmd[1], cmd[2], cmd[3], cmd[4]); + break; + case 13: + ctx.arc(cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6]); + break; + case 14: + ctx.stroke(); + break; + case 15: + ctx.fill(); + break; + case 16: + ctx.clip() + break; + case 17: + ctx.drawImage(cmd[1], cmd[2], cmd[3]); + break; + case 18: + ctx.translate(cmd[1], cmd[2]); + break; + case 19: + ctx.rotate(cmd[1]); + break; + case 20: + ctx.scale(cmd[1], cmd[2]); + break; + case 21: + ctx.save(); + break; + case 22: + ctx.restore(); + break; + /*** Variables ***/ + case 23: + ctx.fillStyle = cmd[1]; + break; + case 24: + ctx.strokeStyle = cmd[1]; + break; + case 25: + ctx.globalAlpha = cmd[1]; + break; + case 26: + ctx.lineWidth = cmd[1]; + break; + case 27: + ctx.lineCap = cmd[1]; + break; + case 28: + ctx.lineJoin = cmd[1]; + break; + case 29: + ctx.miterLimit = cmd[1]; + break; + case 30: + ctx.globalCompositeOperation = cmd[1]; + break; + } + } + } + setTimeout(function() {drawCanvas(id, dly)}, dly); + } + try {DrawReq.send(null);} + catch (e) { + DrawReq.abort(); + return true; + } + return false; +} diff --git a/lib/canvas.l b/lib/canvas.l @@ -0,0 +1,66 @@ +# 15may13abu +# (c) Software Lab. Alexander Burger + +(allow "!jsDraw" ) +(push1 '*JS (allow "@lib/plio.js") (allow "@lib/canvas.js")) + +(de canvasCommands Lst + (for (Opc . L) Lst + (def (car L) + (list + (cdr L) + (list 'link + (if (cdr L) + (cons 'list Opc @) + (list Opc) ) ) ) ) ) ) + +(canvasCommands # In sync with "@lib/canvas.js" + ### Functions ### + (csFillText Str X Y) + (csStrokeLine X1 Y1 X2 Y2) + (csClearRect X Y DX DY) + (csStrokeRect X Y DX DY) + (csFillRect X Y DX DY) + (csBeginPath) + (csClosePath) + (csMoveTo X Y) + (csLineTo X Y) + (csBezierCurveTo X1 Y1 X2 Y2 X Y) + (csLine X1 Y1 X2 Y2) + (csRect X Y DX DY) + (csArc X Y R A B F) + (csStroke) + (csFill) + (csClip) + (csDrawImage Img DX DY) + (csTranslate X Y) + (csRotate A) + (csScale X Y) + (csSave) + (csRestore) + ### Variables ### + (csFillStyle V) + (csStrokeStyle V) + (csGlobalAlpha V) + (csLineWidth V) + (csLineCap V) + (csLineJoin V) + (csMiterLimit V) + (csGlobalCompositeOperation V) ) + +(de canvas (Id DX DY) + (prinl + "<canvas id=\"" Id + "\" width=\"" DX + "\" height=\"" DY + "\">" Id + "</canvas>" ) ) + +(de jsDraw (Id) + (http1 "application/octet-stream" 0) + (let Lst (drawCanvas Id) + (prinl "Content-Length: " (bytes Lst) "^M") + (prinl "^M") + (pr Lst) ) ) + +# vi:et:ts=3:sw=3