{"id":13417158,"url":"https://github.com/makinteract/p5js-vite","last_synced_at":"2025-12-24T06:56:47.138Z","repository":{"id":44582599,"uuid":"438851152","full_name":"makinteract/p5js-vite","owner":"makinteract","description":"Template for P5.js with Vite","archived":false,"fork":false,"pushed_at":"2023-06-11T09:53:32.000Z","size":31,"stargazers_count":45,"open_issues_count":0,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-31T22:37:55.529Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/makinteract.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}},"created_at":"2021-12-16T03:44:01.000Z","updated_at":"2024-07-13T23:27:11.000Z","dependencies_parsed_at":"2024-01-07T18:04:10.820Z","dependency_job_id":"f1a5b4ee-08de-49f4-a800-a4a7a83060cb","html_url":"https://github.com/makinteract/p5js-vite","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/makinteract%2Fp5js-vite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makinteract%2Fp5js-vite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makinteract%2Fp5js-vite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makinteract%2Fp5js-vite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/makinteract","download_url":"https://codeload.github.com/makinteract/p5js-vite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243671670,"owners_count":20328664,"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":[],"created_at":"2024-07-30T22:00:33.218Z","updated_at":"2025-12-24T06:56:47.067Z","avatar_url":"https://github.com/makinteract.png","language":"JavaScript","readme":"# P5.js-vite Starter Template 🚀\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n[Vite](https://vitejs.dev/) starter template to scaffold a new [p5.js](https://p5js.org) project.\n\nThis is an unopinionated template; aside from P5.js and Vite, the rest of your project's tools are entirely up to you.\n\n## Live demo\n\nFor a live demo please [visit this page](https://p5js-vite-demo.surge.sh).\n\n## Installation\n\nPull the template files with [degit](https://github.com/Rich-Harris/degit) and install dependencies.\n\n```\nnpx degit makinteract/p5js-vite my-project\n\ncd my-project\nnpm install\nnpm run dev\n```\n\n## npm scripts\n\n- `npm run dev` - Starts the development server at port [3000](http://localhost:3000/)\n- `npm run build` - Builds the application in a `dist` folder\n- `npm run preview` - Serves the build files (`dist` folder) locally at port [5000](http://localhost:3000/)\n\nNote that if after this last command you do not see anything, you can use instead this other command:\n\n- `npm run preview --host` - You should then be able to see your files locally at port [5000](http://localhost:3000/)\n\n## A single p5.js sketch\n\n```js\nimport '../css/style.css';\nimport { sketch } from 'p5js-wrapper';\n\nsketch.setup = function () {\n  createCanvas(800, 600);\n};\n\nsketch.draw = function () {\n  background(127); // grey\n  fill(255, 0, 0); // red\n  noStroke();\n  rectMode(CENTER);\n  rect(width / 2, height / 2, 50, 50);\n};\n\nsketch.mousePressed = function () {\n  console.log(`I am here at ${mouseX}:${mouseY}`);\n};\n```\n\nAnd here the body of the html file:\n\n```html\n\u003cbody\u003e\n  \u003cscript type=\"module\" src=\"/src/single_sketch.js\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n```\n\n## Multiple p5.js sketches\n\nIf you want to use multiple sketches, you need to use a different syntax.\n\n```js\nimport '../css/style.css';\nimport { p5 } from 'p5js-wrapper';\n\nlet sketch1 = new p5((p) =\u003e {\n  p.setup = () =\u003e {\n    const one = document.getElementById('one');\n    p.createCanvas(one.clientWidth, one.clientHeight);\n  };\n\n  p.draw = () =\u003e {\n    p.background(100);\n  };\n}, 'one');\n\n// Sketch2\nlet sketch2 = new p5((p) =\u003e {\n  p.setup = () =\u003e {\n    const two = document.getElementById('two');\n    p.createCanvas(two.clientWidth, two.clientHeight);\n  };\n\n  p.draw = () =\u003e {\n    p.background(170);\n  };\n}, 'two');\n```\n\nThis file is expecting two divs in the html file:\n\n```html\n\u003cbody\u003e\n  \u003cscript type=\"module\" src=\"/src/multi_sketch.js\"\u003e\u003c/script\u003e\n  \u003cdiv id=\"one\"\u003e\u003c/div\u003e\n  \u003cdiv id=\"two\"\u003e\u003c/div\u003e\n\u003c/body\u003e\n```\n\n## Adding sound\n\nSound is an [experimental feature](https://github.com/makinteract/p5js-wrapper/blob/main/README_SOUND.md).\n\nExamples usage:\n\n```js\nimport { sketch } from 'p5js-wrapper';\nimport 'p5js-wrapper/sound';\n\nimport mysound from './mysound.mp3';\n\nlet soundEffect;\n\nsketch.setup = function () {\n  createCanvas(100, 100);\n  soundEffect = loadSound(mysound);\n};\n\nsketch.draw = function () {\n  background('#eeeeee');\n};\n\n// Play sound on click\nsketch.mousePressed = function () {\n  soundEffect.play();\n};\n```\n\nThis example assumes you have a file _mysound.mp3_ in the _src_ folder.\n\n## License\n\nThis project is open source and available under the [MIT License](LICENSE).\n","funding_links":[],"categories":["Get Started"],"sub_categories":["Templates"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakinteract%2Fp5js-vite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmakinteract%2Fp5js-vite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakinteract%2Fp5js-vite/lists"}