Skip to content
Snippets Groups Projects
Select Git revision
  • ba9f69b6dc041218550817ab60e8c7953fa561e5
  • master default protected
2 results

graphics.js

Blame
  • graphics.js 1008 B
    document.body.setAttribute("style", "margin: 0;");
    var canvas = document.getElementById('stage');
    
    canvas.width = window.innerWidth
        || document.documentElement.clientWidth
        || document.body.clientWidth;
    canvas.height = window.innerHeight
        || document.documentElement.clientHeight
        || document.body.clientHeight;
    var g = canvas.getContext("2d");
    
    g.getmaxx = function () { return canvas.width; };
    g.getmaxy = function () { return canvas.height; };
    
    g.putpixel = function (x, y) {
        g.fillRect(x, y, 1, 1);
    };
    
    g.line = function (x1, y1, x2, y2) {
        g.beginPath();
        g.moveTo(x1, y1);
        g.lineTo(x2, y2);
        g.stroke();
    };
    
    g.rectangle = function (x1, y1, x2, y2) {
        g.strokeRect(x1, y1, x2-x1, y2-y1);
    };
    
    g.circle = function (cx, cy, r) {
        g.beginPath();
        g.arc(cx, cy, r, 0, 2*Math.PI);
        g.stroke();
    };
    
    g.cleardevice = function () {
        g.clearRect(0,0,g.getmaxx(),g.getmaxy());
    };
    g.delay = function (ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
      }