"use strict";
class TWO {
  constructor(canvas,mode) {
    this.a = canvas;
    this.m = mode; // switch between `2d` and `webgl`
    this.c = canvas.getContext(mode);
  }
  clear() {
    if (this.m === '2d')
      this.c.clearRect(0, 0, this.c.canvas.width, this.c.canvas.height);
    if (this.m === 'webgl') {
      this.c.clearColor(0.0, 0.0, 0.0, 0.0);
      this.c.clearDepth(1.0);
      this.c.enable(this.g.DEPTH_TEST);
      this.c.depthFunc(this.g.LEQUAL);
      this.c.clear(this.g.COLOR_BUFFER_BIT | this.g.DEPTH_BUFFER_BIT);
    }
  }
  draw(s, m, c, x, y, p1, p2) {
    if (this.m === '2d') {
      this.c.beginPath();
      switch (s) {
        case 'rect': this.c.rect(x, y, p1, p2); break;
        default:
          console.error('Invalid shape to draw: ' + s);
      }
      switch (m) {
        case 'fill':   this.c.fillStyle = c;   this.c.fill();   break;
        case 'stroke': this.c.strokeStyle = c; this.c.stroke(); break;
        // no default for non-fill/stroke shapes
      }
      this.c.closePath();
    }
    if (this.m === 'webgl') // TODO
      console.log(arguments);
  }
  
  // // // //
  
  // draw text on the screen
  drawText(color, x, y, text) {
    if (this.m === '2d') {
      this.c.fillStyle = color;
      this.c.fillText(text, x, y);
    }
    if (this.m === 'webgl') // TODO
      console.log(arguments);
  };
  // draw an image to the screen
  drawImage(img, a, b, c, d, e, f, g, h) {
    if (this.m === '2d') {
    // error prevention
    if (img !== null) {
      // make it one big function by scanning for parameters
      switch (arguments.length) {
        case 3:
          // image, x, y
          this.c.drawImage(img, a, b);
          break;
        case 5:
          // image, x, y, w, h
          this.c.drawImage(img, a, b, c, d);
          break;
        case 9:
          // image, sx, sy, sw, sh, dx, dy, dw, dh
          this.c.drawImage(img, a,b,c,d,e,f,g,h);
          break;
        default:
          console.error("Invalid amount of parameters: " + arguments.length);
      }
    }
    }
    if (this.m === 'webgl') // TODO
      console.log(arguments);
  }
}

@@ -165,16 +165,66 @@
 e);%0A  %7D%0A
+  // reset the canvas to be transparent and blank%0A
   clear(
@@ -223,24 +223,24 @@
   clear() %7B%0A
-
     if (this
@@ -590,16 +590,63 @@
   %7D%0A  %7D%0A
+  // shape, mode, color, x, y, extra params...%0A
   draw(s
@@ -1201,28 +1201,8 @@
   %7D%0A
-  %0A  // // // //%0A  %0A
   //
@@ -1536,16 +1536,18 @@
 ) %7B%0A    
+  
 // error
@@ -1558,24 +1558,26 @@
 vention%0A    
+ 
+ 
 if (img !== 
@@ -1590,16 +1590,18 @@
 %7B%0A      
+ 
+ 
 // make 
@@ -1649,24 +1649,26 @@
 eters%0A      
+  
 switch (argu
@@ -1679,24 +1679,26 @@
 s.length) %7B%0A
+  
         case
@@ -1703,32 +1703,34 @@
 se 3:%0A          
+  
 // image, x, y%0A 
@@ -1728,16 +1728,18 @@
 e, x, y%0A
+  
         
@@ -1771,39 +1771,43 @@
 , b);%0A          
+  
 break;%0A
+  
         case 5:%0A
@@ -1806,16 +1806,18 @@
 case 5:%0A
+  
         
@@ -1841,32 +1841,34 @@
  w, h%0A          
+  
 this.c.drawImage
@@ -1888,32 +1888,34 @@
 , d);%0A          
+  
 break;%0A        c
@@ -1917,16 +1917,18 @@
     
+ 
+ 
 case 9:%0A
     
@@ -1923,16 +1923,18 @@
 case 9:%0A
+  
         
@@ -1976,16 +1976,18 @@
  dw, dh%0A
+  
         
@@ -2030,39 +2030,43 @@
 g,h);%0A          
+  
 break;%0A
+  
         default:
@@ -2058,32 +2058,34 @@
        default:%0A
+  
           consol
@@ -2148,26 +2148,30 @@
 gth);%0A      
-%7D%0A
+  %7D%0A  
     %7D%0A    %7D%0A

Update Two.js