{"id":16218664,"url":"https://github.com/loginov-rocks/canvas-heightmap","last_synced_at":"2025-03-19T10:31:04.750Z","repository":{"id":57193724,"uuid":"121992274","full_name":"loginov-rocks/canvas-heightmap","owner":"loginov-rocks","description":"Canvas heightmap generator","archived":false,"fork":false,"pushed_at":"2021-03-13T12:16:42.000Z","size":326,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T18:05:46.371Z","etag":null,"topics":["canvas","generator","heightmap"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/canvas-heightmap","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/loginov-rocks.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":"2018-02-18T21:27:12.000Z","updated_at":"2024-10-19T02:56:14.000Z","dependencies_parsed_at":"2022-09-15T22:31:19.744Z","dependency_job_id":null,"html_url":"https://github.com/loginov-rocks/canvas-heightmap","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loginov-rocks%2Fcanvas-heightmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loginov-rocks%2Fcanvas-heightmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loginov-rocks%2Fcanvas-heightmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loginov-rocks%2Fcanvas-heightmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loginov-rocks","download_url":"https://codeload.github.com/loginov-rocks/canvas-heightmap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243982237,"owners_count":20378607,"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":["canvas","generator","heightmap"],"created_at":"2024-10-10T11:50:12.411Z","updated_at":"2025-03-19T10:31:04.478Z","avatar_url":"https://github.com/loginov-rocks.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# canvas-heightmap\n\n[![npm](https://img.shields.io/npm/v/canvas-heightmap)](https://www.npmjs.com/package/canvas-heightmap)\n[![CI](https://github.com/loginov-rocks/canvas-heightmap/actions/workflows/ci.yml/badge.svg)](https://github.com/loginov-rocks/canvas-heightmap/actions/workflows/ci.yml)\n[![CD](https://github.com/loginov-rocks/canvas-heightmap/actions/workflows/cd.yml/badge.svg)](https://github.com/loginov-rocks/canvas-heightmap/actions/workflows/cd.yml)\n[![Coverage Status](https://coveralls.io/repos/github/loginov-rocks/canvas-heightmap/badge.svg?branch=main)](https://coveralls.io/github/loginov-rocks/canvas-heightmap?branch=main)\n\nCanvas Heightmap is a package to **get images data by pixels, channels or average in different representations** that\ncan be used to build heightmaps.\n\n## Quick Start\n\n### Install\n\n```sh\nnpm install canvas-heightmap\n```\n\n### Use\n\n```js\nconst ch = new CanvasHeightmap();\n\n// At first set the source and wait until it would be loaded.\nch.use('https://raw.githubusercontent.com/loginov-rocks/canvas-heightmap/master/test/resources/black-and-white.png').\n    then(() =\u003e {\n      // Secondly invoke draw method to render image to be able to get its data.\n      ch.draw();\n      // Eventually you can get needed data.\n      const flatArray = ch.getFlatArray();\n      const rgbaArray = ch.getRgbaArray();\n    });\n```\n\n## API\n\n### `CanvasHeightmap`\n\nCanvas Heightmap class.\n\n**Kind**: global class\n\n* [CanvasHeightmap](#canvasheightmap)\n  * [new CanvasHeightmap()](#new-canvasheightmap)\n  * [use(source) ⇒ Promise.\u0026lt;HTMLImageElement|HTMLCanvasElement\u0026gt;](#usesource--promisehtmlimageelementhtmlcanvaselement)\n  * [draw() ⇒ HTMLCanvasElement](#draw--htmlcanvaselement)\n  * [getFlatArray([sx], [sy], [sw], [sh]) ⇒ Uint8ClampedArray](#getflatarraysx-sy-sw-sh--uint8clampedarray)\n  * [getFlatAverageArray([sx], [sy], [sw], [sh]) ⇒ Uint8ClampedArray](#getflataveragearraysx-sy-sw-sh--uint8clampedarray)\n  * [getFlatChannelArray(channel, [sx], [sy], [sw], [sh]) ⇒ Uint8ClampedArray](#getflatchannelarraychannel-sx-sy-sw-sh--uint8clampedarray)\n  * [getFlatRgbaArray([sx], [sy], [sw], [sh]) ⇒ Array.\u0026lt;Uint8ClampedArray\u0026gt;](#getflatrgbaarraysx-sy-sw-sh--arrayuint8clampedarray)\n  * [getAverageArray([sx], [sy], [sw], [sh]) ⇒ Array.\u0026lt;Uint8ClampedArray\u0026gt;](#getaveragearraysx-sy-sw-sh--arrayuint8clampedarray)\n  * [getChannelArray(channel, [sx], [sy], [sw], [sh]) ⇒ Array.\u0026lt;Uint8ClampedArray\u0026gt;](#getchannelarraychannel-sx-sy-sw-sh--arrayuint8clampedarray)\n  * [getRgbaArray([sx], [sy], [sw], [sh]) ⇒ Array.\u0026lt;Array.\u0026lt;Uint8ClampedArray\u0026gt;\u0026gt;](#getrgbaarraysx-sy-sw-sh--arrayarrayuint8clampedarray)\n\n---\n\n#### `new CanvasHeightmap()`\n\nCanvas Heightmap constructor.\n\n---\n\n#### `use(source)` ⇒ `Promise.\u003cHTMLImageElement|HTMLCanvasElement\u003e`\n\nSet canvas image source.\n\n**Kind**: instance method of `CanvasHeightmap`\n\n| Parameter | Type                                                          |\n| --------- | ------------------------------------------------------------- |\n| source    | `string` \u0026#124; `HTMLImageElement` \u0026#124; `HTMLCanvasElement` |\n\n---\n\n#### `draw()` ⇒ `HTMLCanvasElement`\n\nDraw image source on canvas.\n\n**Kind**: instance method of `CanvasHeightmap`\n\n---\n\n#### `getFlatArray([sx], [sy], [sw], [sh])` ⇒ `Uint8ClampedArray`\n\nGet one-dimensional array containing the data in the RGBA order, with integer values between 0 and 255 (included).\n\n**Kind**: instance method of `CanvasHeightmap`\n\n**See**:\n* https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getImageData\n* https://developer.mozilla.org/en-US/docs/Web/API/ImageData/data\n\n| Parameter | Type     | Default        | Description                                                                                       |\n| --------- | -------- | -------------- | ------------------------------------------------------------------------------------------------- |\n| [sx]      | `number` | `0`            | The x coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sy]      | `number` | `0`            | The y coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sw]      | `number` | `this._width`  | The width of the rectangle from which the data will be extracted.                                 |\n| [sh]      | `number` | `this._height` | The height of the rectangle from which the data will be extracted.                                |\n\n---\n\n#### `getFlatAverageArray([sx], [sy], [sw], [sh])` ⇒ `Uint8ClampedArray`\n\nGet one-dimensional array containing the data by pixels with average over RGB channels, with integer values between 0\nand 255 (included).\n\n**Kind**: instance method of `CanvasHeightmap`\n\n| Parameter | Type     | Default        | Description                                                                                       |\n| --------- | -------- | -------------- | ------------------------------------------------------------------------------------------------- |\n| [sx]      | `number` | `0`            | The x coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sy]      | `number` | `0`            | The y coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sw]      | `number` | `this._width`  | The width of the rectangle from which the data will be extracted.                                 |\n| [sh]      | `number` | `this._height` | The height of the rectangle from which the data will be extracted.                                |\n\n---\n\n#### `getFlatChannelArray(channel, [sx], [sy], [sw], [sh])` ⇒ `Uint8ClampedArray`\n\nGet one-dimensional array containing the data for specified channel, with integer values between 0 and 255 (included).\n\n**Kind**: instance method of `CanvasHeightmap`\n\n| Parameter | Type     | Default        | Description                                                                                       |\n| --------- | -------- | -------------- | ------------------------------------------------------------------------------------------------- |\n| channel   | `string` |                | Channel: `red`, `green`, `blue` or `alpha`.                                                       |\n| [sx]      | `number` | `0`            | The x coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sy]      | `number` | `0`            | The y coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sw]      | `number` | `this._width`  | The width of the rectangle from which the data will be extracted.                                 |\n| [sh]      | `number` | `this._height` | The height of the rectangle from which the data will be extracted.                                |\n\n---\n\n#### `getFlatRgbaArray([sx], [sy], [sw], [sh])` ⇒ `Array.\u003cUint8ClampedArray\u003e`\n\nGet two-dimensional array containing the data by pixels and RGBA array for each, with integer values between 0 and 255\n(included).\n\n**Kind**: instance method of `CanvasHeightmap`\n\n| Parameter | Type     | Default        | Description                                                                                       |\n| --------- | -------- | -------------- | ------------------------------------------------------------------------------------------------- |\n| [sx]      | `number` | `0`            | The x coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sy]      | `number` | `0`            | The y coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sw]      | `number` | `this._width`  | The width of the rectangle from which the data will be extracted.                                 |\n| [sh]      | `number` | `this._height` | The height of the rectangle from which the data will be extracted.                                |\n\n---\n\n#### `getAverageArray([sx], [sy], [sw], [sh])` ⇒ `Array.\u003cUint8ClampedArray\u003e`\n\nGet two-dimensional array containing the rows and cols data by pixels with average over RGB channels, with integer\nvalues between 0 and 255 (included).\n\n**Kind**: instance method of `CanvasHeightmap`\n\n| Parameter | Type     | Default        | Description                                                                                       |\n| --------- | -------- | -------------- | ------------------------------------------------------------------------------------------------- |\n| [sx]      | `number` | `0`            | The x coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sy]      | `number` | `0`            | The y coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sw]      | `number` | `this._width`  | The width of the rectangle from which the data will be extracted.                                 |\n| [sh]      | `number` | `this._height` | The height of the rectangle from which the data will be extracted.                                |\n\n---\n\n#### `getChannelArray(channel, [sx], [sy], [sw], [sh])` ⇒ `Array.\u003cUint8ClampedArray\u003e`\n\nGet two-dimensional array containing the rows and cols data for specified channel, with integer values between 0 and 255\n(included).\n\n**Kind**: instance method of `CanvasHeightmap`\n\n| Parameter | Type     | Default        | Description                                                                                       |\n| --------- | -------- | -------------- | ------------------------------------------------------------------------------------------------- |\n| channel   | `string` |                | Channel: `red`, `green`, `blue` or `alpha`.                                                       |\n| [sx]      | `number` | `0`            | The x coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sy]      | `number` | `0`            | The y coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sw]      | `number` | `this._width`  | The width of the rectangle from which the data will be extracted.                                 |\n| [sh]      | `number` | `this._height` | The height of the rectangle from which the data will be extracted.                                |\n\n---\n\n#### `getRgbaArray([sx], [sy], [sw], [sh])` ⇒ `Array.\u003cArray.\u003cUint8ClampedArray\u003e\u003e`\n\nGet three-dimensional array containing the rows and cols data by pixels and RGBA array for each, with integer values\nbetween 0 and 255 (included).\n\n**Kind**: instance method of `CanvasHeightmap`\n\n| Parameter | Type     | Default        | Description                                                                                       |\n| --------- | -------- | -------------- | ------------------------------------------------------------------------------------------------- |\n| [sx]      | `number` | `0`            | The x coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sy]      | `number` | `0`            | The y coordinate of the upper left corner of the rectangle from which the data will be extracted. |\n| [sw]      | `number` | `this._width`  | The width of the rectangle from which the data will be extracted.                                 |\n| [sh]      | `number` | `this._height` | The height of the rectangle from which the data will be extracted.                                |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floginov-rocks%2Fcanvas-heightmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floginov-rocks%2Fcanvas-heightmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floginov-rocks%2Fcanvas-heightmap/lists"}