{"id":13599673,"url":"https://github.com/dulnan/lazy-brush","last_synced_at":"2025-05-15T08:08:53.525Z","repository":{"id":65228922,"uuid":"145379450","full_name":"dulnan/lazy-brush","owner":"dulnan","description":"Smooth drawing with mouse, finger or other pointing device","archived":false,"fork":false,"pushed_at":"2024-09-14T12:27:29.000Z","size":173,"stargazers_count":822,"open_issues_count":5,"forks_count":23,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T17:09:07.440Z","etag":null,"topics":["brush","canvas","drawing","javascript","lazy","painting","typescript"],"latest_commit_sha":null,"homepage":"https://lazybrush.dulnan.net/","language":"TypeScript","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/dulnan.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-20T07:04:17.000Z","updated_at":"2025-04-01T21:44:45.000Z","dependencies_parsed_at":"2024-06-09T20:34:27.611Z","dependency_job_id":"6f9b4a62-1306-415e-a2cf-4bbeeed5393f","html_url":"https://github.com/dulnan/lazy-brush","commit_stats":{"total_commits":33,"total_committers":3,"mean_commits":11.0,"dds":"0.33333333333333337","last_synced_commit":"5c5f5534764d0eef72ca9272828e55357745f87b"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulnan%2Flazy-brush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulnan%2Flazy-brush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulnan%2Flazy-brush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulnan%2Flazy-brush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dulnan","download_url":"https://codeload.github.com/dulnan/lazy-brush/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248439806,"owners_count":21103684,"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":["brush","canvas","drawing","javascript","lazy","painting","typescript"],"created_at":"2024-08-01T17:01:08.792Z","updated_at":"2025-04-11T16:26:48.152Z","avatar_url":"https://github.com/dulnan.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","JavaScript"],"sub_categories":[],"readme":"# lazy-brush - smooth drawing with a mouse, finger or any pointing device\n\n[![lazy-brush banner](public/og.png?raw=true \"Lazy Brush in action\")](https://lazybrush.dulnan.net)\n\n**[Demo](https://lazybrush.dulnan.net)** - **[NPM](https://npmjs.com/package/lazy-brush)** - **[CodePen Examples](https://codepen.io/collection/wayKwv)**\n\n__The demo app also uses\n[catenary-curve](https://github.com/dulnan/catenary-curve) to draw the little\n\"rope\" between mouse and brush.__\n\nThis library provides the math required to implement a \"lazy brush\".\nIt takes a radius and the {x,y} coordinates of a mouse/pointer and calculates\nthe position of the brush.\n\nThe brush will only move when the pointer is outside the \"lazy area\" of the\nbrush. With this technique it's possible to freely draw smooth lines and curves\nwith just a mouse or finger.\n\n## How it works\n\nWhen the position of the pointer is updated, the distance to the brush is\ncalculated. If this distance is larger than the defined radius, the brush will\nbe moved by `distance - radius` pixels in the direction where the pointer is.\n\n## Usage\n\nlazy-brush is on npm so you can install it with your favorite package manager.\n\n```bash\nnpm install --save lazy-brush\n```\n\nlazy-brush can be easily added in any canvas drawing scenario. It acts like a\n\"proxy\" between user input and drawing.\n\nIt exports a `LazyBrush` class. Create a single instance of the class:\n\n```javascript\nconst lazy = new LazyBrush({\n  radius: 30,\n  enabled: true,\n  initialPoint: { x: 0, y: 0 }\n})\n```\n\nYou can now use the `update()` method whenever the position of the mouse (or\ntouch) changes:\n\n```javascript\n// Move mouse 20 pixels to the right.\nlazy.update({ x: 20, y: 0 })\n// Brush is not moved, because 20 is less than the radius (30).\nconsole.log(lazy.getBrushCoordinates()) // { x: 0, y: 0 }\n\n// Move mouse 40 pixels to the right.\nlazy.update({ x: 40, y: 0 })\n// Brush is now moved by 10 pixels because 40 (mouse X) - 30 (radius) = 10.\nconsole.log(lazy.getBrushCoordinates()) // { x: 10, y: 0 }\n```\n\nThe function returns a boolean to indicate whether any of the values (brush or\npointer) have changed. This can be used to prevent unneccessary canvas\nredrawing.\n\nIf you need to know if the position of the brush was changed, you can get that\nboolean via `LazyBrush.brushHasMoved()`. Use this information to decide if you\nneed to redraw the brush on the canvas.\n\nTo get the current brush coordinates, use `LazyBrush.getBrushCoordinates()`.\nFor the pointer coordinates use `LazyBrush.getPointerCoordinates()`. This will\nreturn a `Point` object with x and y properties.\n\nThe functions `getBrush()` and `getPointer()` will return a `LazyPoint`, which\nhas some additional functions like `getDistanceTo`, `getAngleTo` or `equalsTo`.\n\n### With Friction\n\nYou can also pass a friction value (number between 0 and 1) when calling `update()`:\n\n```javascript\nlazy.update({ x: 40, y: 0 }, { friction: 0.5 })\n```\n\nThis will reduce the speed at which the brush moves towards the pointer. A\nvalue of 0 means \"no friction\", which is the same as not passing a value. 1\nmeans \"inifinte friction\", the brush won't move at all.\n\nYou can define a constant value or make it dynamic, for example using a pressur\nvalue from a touch event.\n\n### Updating both values\n\nYou can also update the pointer and the brush coordinates at the same time:\n\n```javascript\nlazy.update({ x: 40, y: 0 }, { both: true })\n```\n\nThis can be used when supporting touch events: On touch start you would update\nboth the pointer and the brush so that the pointer can be \"moved\" away from the\nbrush until the lazy radius is reached. This is how it's implemented in the\ndemo page.\n\n## Examples\n\nCheck out the [basic example](examples/basic.html) for a simple starting point\non how to use this library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdulnan%2Flazy-brush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdulnan%2Flazy-brush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdulnan%2Flazy-brush/lists"}