{"id":16125574,"url":"https://github.com/semibran/tetromino","last_synced_at":"2025-03-18T13:30:47.871Z","repository":{"id":65374717,"uuid":"81174234","full_name":"semibran/tetromino","owner":"semibran","description":"model tetrominos using minimal data structures","archived":false,"fork":false,"pushed_at":"2017-06-27T06:58:36.000Z","size":25,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T09:43:03.380Z","etag":null,"topics":["game","tetris","tetromino"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/semibran.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-07T06:24:40.000Z","updated_at":"2024-04-23T16:11:49.000Z","dependencies_parsed_at":"2023-01-20T01:25:20.797Z","dependency_job_id":null,"html_url":"https://github.com/semibran/tetromino","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Ftetromino","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Ftetromino/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Ftetromino/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Ftetromino/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/semibran","download_url":"https://codeload.github.com/semibran/tetromino/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243928156,"owners_count":20370243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["game","tetris","tetromino"],"created_at":"2024-10-09T21:30:01.351Z","updated_at":"2025-03-18T13:30:47.481Z","avatar_url":"https://github.com/semibran.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tetromino\n![The seven tetrominos](img/tetrominos.png)\n\nModel [tetrominos](https://en.wikipedia.org/wiki/Tetromino) using minimal data structures, especially for use in Tetris clones.\n```js\nvar tetromino = {\n  type: 'L',\n  position: [3, 0],\n  rotation: 0\n}\n```\n\n## usage\n[![NPM](https://nodei.co/npm/tetromino.png?mini)](https://www.npmjs.com/package/tetromino)\n```js\nconst { types, states, blocks } = require('tetromino')\n```\n\n### `blocks(tetromino)`\nA 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.\n```js\n\u003e blocks(tetromino)\n[ [ 3, 1 ], [ 4, 1 ], [ 5, 1 ], [ 5, 0 ] ]\n```\n\n### `type`\nThe `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`:\n```js\n\u003e types\n[ 'I', 'J', 'L', 'O', 'S', 'T', 'Z' ]\n```\nA common use case for this array is choosing a random tetromino to spawn.\n```js\n\u003e types[Math.floor(Math.random() * types.length)]\n'S'\n```\n\n### `position`\nThe `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.\n\n![S tetromino demonstrating position](img/position.png)\n\n### `rotation`\nA 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.\n```js\n\u003e states.T.length\n4\n\n\u003e states.O.length\n1\n```\n\n![J tetromino demonstrating rotation](img/rotation.gif)\n\n### `states[type][rotation]`\nThe `states` object details the locations of each cell of a tetromino with a given type and rotation in compliance with the [SRS](http://tetris.wikia.com/wiki/SRS). It is used internally in the `blocks` function mentioned above.\n\nUse `states` by specifying both [a tetromino type](#type) and [a rotation index](#rotation).\n```js\n\u003e states.J[0]\n[ [ 0, 1 ], [ 1, 1 ], [ 2, 1 ], [ 2, 0 ] ]\n```\n\n## see also\n- [`semibran/vector`](https://github.com/semibran/vector): move tetrominos with `add(tetromino.position, delta)`\n- [`semibran/wrap-around`](https://github.com/semibran/wrap-around): manage rotation indexes inline\n\n## license\n[MIT](https://opensource.org/licenses/MIT) © [Brandon Semilla](https://git.io/semibran)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemibran%2Ftetromino","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsemibran%2Ftetromino","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemibran%2Ftetromino/lists"}