Search⌘ K
AI Features

Tetrominoes

Explore how Tetrominoes, the Tetris game pieces made of four blocks, are defined and managed in JavaScript. Understand their shapes, colors, positioning on the board, and how to draw and update them within a game canvas, preparing you to implement moving pieces in your Tetris game.

A piece in Tetris is a shape consisting of four blocks moving as a unit. They are often called tetrominoes and come in seven different patterns and colors. The names I, J, L, O, S, T, and Z resemble their shape.

The seven Tetris pieces
The seven Tetris pieces

Tetromino matrix

We represent the J tetromino as a matrix where the number two represents the colored cells. We add a row of zeros to get a center to rotate around:

 ...