npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tetromino

v1.0.0

Published

Model tetrominos using minimal data structures

Downloads

4

Readme

tetromino

The seven tetrominos

Model tetrominos using minimal data structures, especially for use in Tetris clones.

var tetromino = {
  type: 'L',
  position: [3, 0],
  rotation: 0
}

usage

NPM

const { types, states, blocks } = require('tetromino')

blocks(tetromino)

A tetromino can be represented as an object with the three fields type, rotation, and position. From this information, we can easily infer the location of each of the four cells that the tetromino occupies.

> blocks(tetromino)
[ [ 3, 1 ], [ 4, 1 ], [ 5, 1 ], [ 5, 0 ] ]

type

The type of a tetromino is a single character denoting its unique name. The image at the top of this page lists the tetrominos in the order [I, J, L, O, S, T, Z] - in fact, this particular array is exposed as types:

> types
[ 'I', 'J', 'L', 'O', 'S', 'T', 'Z' ]

A common use case for this array is choosing a random tetromino to spawn.

> types[Math.floor(Math.random() * types.length)]
'S'

position

The position of a tetromino is a two-dimensional vector of the form [x, y]. Since the center point of each tetromino will vary, position is relative to the top-left point of the 4x4 region containing the piece.

S tetromino demonstrating position

rotation

A tetromino's rotation is a zero-based index corresponding to a "rotation state" found in states. Most tetrominos have 4 rotation states, with the O piece being the exception. It only has one state and therefore cannot rotate.

> states.T.length
4

> states.O.length
1

J tetromino demonstrating rotation

states[type][rotation]

The states object details the locations of each cell of a tetromino with a given type and rotation in compliance with the SRS. It is used internally in the blocks function mentioned above.

Use states by specifying both a tetromino type and a rotation index.

> states.J[0]
[ [ 0, 1 ], [ 1, 1 ], [ 2, 1 ], [ 2, 0 ] ]

see also

license

MIT © Brandon Semilla