{"id":16533836,"url":"https://github.com/kchapelier/jittered-hexagonal-grid-sampling","last_synced_at":"2025-09-22T01:31:30.052Z","repository":{"id":57280975,"uuid":"270640456","full_name":"kchapelier/jittered-hexagonal-grid-sampling","owner":"kchapelier","description":"Jittered Hexagonal Grid Sampling","archived":false,"fork":false,"pushed_at":"2022-05-21T08:56:38.000Z","size":74,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-03T05:05:47.982Z","etag":null,"topics":["javascript","procedural-generation","sampling"],"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/kchapelier.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":"2020-06-08T11:20:47.000Z","updated_at":"2024-06-29T13:59:41.000Z","dependencies_parsed_at":"2022-09-06T01:00:35.896Z","dependency_job_id":null,"html_url":"https://github.com/kchapelier/jittered-hexagonal-grid-sampling","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fjittered-hexagonal-grid-sampling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fjittered-hexagonal-grid-sampling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fjittered-hexagonal-grid-sampling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fjittered-hexagonal-grid-sampling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kchapelier","download_url":"https://codeload.github.com/kchapelier/jittered-hexagonal-grid-sampling/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233814463,"owners_count":18734531,"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":["javascript","procedural-generation","sampling"],"created_at":"2024-10-11T18:15:58.920Z","updated_at":"2025-09-22T01:31:24.696Z","avatar_url":"https://github.com/kchapelier.png","language":"JavaScript","readme":"# jittered-hexagonal-grid-sampling\n\n[![Build Status](https://travis-ci.org/kchapelier/jittered-hexagonal-grid-sampling.svg)](https://travis-ci.org/kchapelier/jittered-hexagonal-grid-sampling) [![NPM version](https://badge.fury.io/js/jittered-hexagonal-grid-sampling.svg)](http://badge.fury.io/js/jittered-hexagonal-grid-sampling)\n\nJittered Hexagonal Grid Sampling\n\n\u003cimg src=\"https://github.com/kchapelier/jittered-hexagonal-grid-sampling/raw/master/img/debugview.png\" style=\"image-rendering:pixelated; width:500px;\"\u003e\u003c/img\u003e\n\n## Installing\n\nWith [npm](https://www.npmjs.com/) do:\n\n```\nnpm install jittered-hexagonal-grid-sampling\n```\n\nWith [yarn](https://yarnpkg.com/) do:\n\n```\nyarn add jittered-hexagonal-grid-sampling\n```\n\nA compiled version for web browsers is also available on a CDN:\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/kchapelier/jittered-hexagonal-grid-sampling@1.0.1/build/jittered-hexagonal-grid-sampling.min.js\"\u003e\u003c/script\u003e\n```\n\n## Features\n\n- Can be used with a custom RNG function.\n- Similar general API as [poisson-disk-sampling](https://github.com/kchapelier/poisson-disk-sampling) and [fast-2d-poisson-disk-sampling](https://github.com/kchapelier/fast-2d-poisson-disk-sampling).\n\n## Basic example\n\n```js\nvar p = new JitteredHexagonalGridSampling({\n    shape: [500, 200],\n    radius: 5\n});\nvar points = p.fill();\n\nconsole.log(points); // array of sample points, themselves represented as simple arrays\n```\n\n### Result as an image\n\n\u003cimg src=\"https://github.com/kchapelier/jittered-hexagonal-grid-sampling/raw/master/img/example1.png\" style=\"image-rendering:pixelated; width:500px;\"\u003e\u003c/img\u003e\n\n## Public API\n\n### Constructor\n\n**new JitteredHexagonalGridSampling(options[, rng])**\n\n- *options :*\n  - *shape :* Size/dimensions of the grid to generate points in, required.\n  - *radius :* Radius of the circumcircle of the regular hexagon, required.\n  - *jitter :* Jitter amount, defaults to 0.666.\n- *rng :* A function to use as random number generator, defaults to Math.random.\n\nThe following code will allow the generation of points where both coordinates will range from *0 up to 50* (including 0, but not including 50, **0 \u003c= c \u003c 50**).\n\n```js\nvar sampling = new JitteredHexagonalGridSampling({\n    shape: [50, 50],\n    radius: 4\n});\n```\n\n### Methods\n\n**sampling.fill()**\n\nFill the grid with jittered points.\n\nReturns the entirety of the points in the grid as an array of coordinate arrays. The points are sorted in their generation order.\n\n```js\nvar points = sampling.fill();\n\nconsole.log(points[0]);\n// prints something like [30, 16]\n```\n\n**sampling.getAllPoints()**\n\nGet all the points present in the grid without trying to generate any new points.\n\nReturns the entirety of the points in the grid as an array of coordinate arrays. The points are sorted in their generation order.\n\n```js\nvar points = sampling.getAllPoints();\n\nconsole.log(points[0]);\n// prints something like [30, 16]\n```\n\n**sampling.next()**\n\nTry to generate a new point in the grid.\n\nReturns a coordinate array when a point is generated, null otherwise.\n\n```js\nvar point;\n\nwhile(point = sampling.next()) {\n    console.log(point); // [x, y]\n}\n```\n\n**sampling.reset()**\n\nReinitialize the grid as well as the internal state.\n\n## History\n\n### [1.0.1](https://github.com/kchapelier/jittered-hexagonal-grid-sampling/tree/1.0.1) (2022-05-21) :\n\n- Update dev dependencies\n\n### [1.0.0](https://github.com/kchapelier/jittered-hexagonal-grid-sampling/tree/1.0.0) (2020-06-08) :\n\n- First release\n\n## Roadmap\n\nNone.\n\n## How to contribute ?\n\nFor new features and other enhancements, please make sure to contact me beforehand, either on [Twitter](https://twitter.com/kchplr) or through an issue on Github.\n\n## License\n\nMIT","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkchapelier%2Fjittered-hexagonal-grid-sampling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkchapelier%2Fjittered-hexagonal-grid-sampling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkchapelier%2Fjittered-hexagonal-grid-sampling/lists"}