title: Using p5.js, is it possible to draw a class that draws sub-classes within itself? For example, a 4x4 block made up of 1x1 blocks
body: <p>I'm attempting to make a Tetris-like game, where the game's pieces are all made up of smaller pieces that share properties. </p>
  
  <p>Currently I have:</p>
  
  <pre><code>    export class SquareTetromino {
        [x: string]: any;
        constructor(x, y, w, h) {
        ...
        }
  
        show(p5) {
           p5.push();
           p5.translate(this.posX, this.posY);
           p5.fill("#D8B6FF")
           p5.rect(0,0,this.w, this.h);
           p5.pop();
  
        }
       ...
      }
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>    export class BlockTetromino {
        [x: string]: any;
        constructor(x, y, w, h) {
        ...
        }
  
        test(p5) {
            this.testArray.push(new SquareTetromino(this.posX,this.posY,this.w,this.h));
            this.testArray.push(new SquareTetromino(this.posX - 50,this.posY,this.w,this.h));
            this.testArray.push(new SquareTetromino(this.posX - 50,this.posY + 50,this.w,this.h));
            this.testArray.push(new SquareTetromino(this.posX,this.posY + 50,this.w,this.h));
        }
  
        show(p5) {
            p5.push();
            this.testArray.forEach((block) =&gt; {
              block.show(p5)
            })
            p5.pop();
  
        }
      }
  </code></pre>
  
  <p>And from my main component:</p>
  
  <pre><code>  s.setup = () =&gt; {
  
    ...
  
              bodies.push(new BlockTetromino(200,-50,50,50))
              bodies[0].test(s);
    ...
            }
  
    s.draw = () =&gt; {
           ...
  
  
            for (let i = 0; i &lt; bodies.length; i++) {
              bodies[i].show(s)
            }
  </code></pre>
  
  <p>I'd like to be able to have a class Block which draws a small block, and then call that Block within a class Square, which draws 4 small blocks. Then, by instantiating Square I'll have 4 blocks chained together as one object. </p>
  
  <p>I think I'm missing a for loop somewhere. </p>