picolisp

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

canvas.js (3710B)


      1 /* 06aug13abu
      2  * (c) Software Lab. Alexander Burger
      3  */
      4 
      5 function drawCanvas(id, dly) {
      6    var req = new XMLHttpRequest();
      7 
      8    try {
      9       req.open("POST",
     10          document.getElementsByTagName("BASE")[0].href + SesId +
     11          "!jsDraw?" + id + "&+" + dly);
     12       req.responseType = "arraybuffer";
     13    }
     14    catch (e) {return true;}
     15    req.onload = function() {
     16       var lst = plio(new Uint8Array(req.response));
     17       var cmd, i;
     18 
     19       if (lst) {
     20          var ctx = document.getElementById(id).getContext("2d");
     21 
     22          for (i = 0; i < lst.length; ++i) {
     23             switch ((cmd = lst[i])[0]) {  // In sync with "@lib/canvas.l"
     24             /*** Functions ***/
     25             case 1:
     26                ctx.fillText(cmd[1], cmd[2], cmd[3]);
     27                break;
     28             case 2:
     29                ctx.beginPath();
     30                ctx.moveTo(cmd[1], cmd[2]);
     31                ctx.lineTo(cmd[3], cmd[4]);
     32                ctx.closePath();
     33                ctx.stroke();
     34                break;
     35             case 3:
     36                ctx.clearRect(cmd[1], cmd[2], cmd[3], cmd[4]);
     37                break;
     38             case 4:
     39                ctx.strokeRect(cmd[1], cmd[2], cmd[3], cmd[4]);
     40                break;
     41             case 5:
     42                ctx.fillRect(cmd[1], cmd[2], cmd[3], cmd[4]);
     43                break;
     44             case 6:
     45                ctx.beginPath();
     46                break;
     47             case 7:
     48                ctx.closePath();
     49                break;
     50             case 8:
     51                ctx.moveTo(cmd[1], cmd[2]);
     52                break;
     53             case 9:
     54                ctx.lineTo(cmd[1], cmd[2]);
     55                break;
     56             case 10:
     57                ctx.bezierCurveTo(cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6]);
     58                break;
     59             case 11:
     60                ctx.moveTo(cmd[1], cmd[2]);
     61                ctx.lineTo(cmd[3], cmd[4]);
     62                break;
     63             case 12:
     64                ctx.rect(cmd[1], cmd[2], cmd[3], cmd[4]);
     65                break;
     66             case 13:
     67                ctx.arc(cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6]);
     68                break;
     69             case 14:
     70                ctx.stroke();
     71                break;
     72             case 15:
     73                ctx.fill();
     74                break;
     75             case 16:
     76                ctx.clip()
     77                break;
     78             case 17:
     79                ctx.drawImage(cmd[1], cmd[2], cmd[3]);
     80                break;
     81             case 18:
     82                ctx.translate(cmd[1], cmd[2]);
     83                break;
     84             case 19:
     85                ctx.rotate(cmd[1]);
     86                break;
     87             case 20:
     88                ctx.scale(cmd[1], cmd[2]);
     89                break;
     90             case 21:
     91                ctx.save();
     92                break;
     93             case 22:
     94                ctx.restore();
     95                break;
     96             /*** Variables ***/
     97             case 23:
     98                ctx.fillStyle = cmd[1];
     99                break;
    100             case 24:
    101                ctx.strokeStyle = cmd[1];
    102                break;
    103             case 25:
    104                ctx.globalAlpha = cmd[1];
    105                break;
    106             case 26:
    107                ctx.lineWidth = cmd[1];
    108                break;
    109             case 27:
    110                ctx.lineCap = cmd[1];
    111                break;
    112             case 28:
    113                ctx.lineJoin = cmd[1];
    114                break;
    115             case 29:
    116                ctx.miterLimit = cmd[1];
    117                break;
    118             case 30:
    119                ctx.globalCompositeOperation = cmd[1];
    120                break;
    121             }
    122          }
    123       }
    124       if (dly >= 0)
    125          setTimeout(function() {drawCanvas(id, dly)}, dly);
    126    }
    127    try {req.send(null);}
    128    catch (e) {
    129       req.abort();
    130       return true;
    131    }
    132    return false;
    133 }