create-p5jsboiler
v2.0.3
Published
A modular p5.js boilerplate project featuring a double pendulum physics simulation. This project demonstrates advanced p5.js concepts including ES6 modules, scene management, event-driven architecture, and game object patterns.
Maintainers
Readme
P5.js Modular Boilerplate
A modular p5.js boilerplate project featuring a double pendulum physics simulation. This project demonstrates advanced p5.js concepts including ES6 modules, scene management, event-driven architecture, and game object patterns.
Features
- Modular Architecture: Clean separation of concerns with core, entities, scenes, and utilities
- Event System: Custom event handling for keyboard input and game loop
- Scene Management: Flexible scene system for managing different game states
- Pause/Resume: Spacebar controls to pause and resume the simulation
Getting Started
Prerequisites
- A modern web browser with ES6 module support
- No build tools required - runs directly in the browser
Installation
Clone the repository:
git clone https://github.com/ZKitcher/p5js-Boilerplate.git cd p5js-BoilerplateOpen
index.htmlin your web browser or serve the project on a local server for live reloading. For example, using live-server:
npx live-serverOR
- To create a clone, run
npx create-p5jsboiler+app-name.
npx create-p5jsboiler app-name
cd app-nameUsage
- Start: Open
index.htmlin a web browser - Pause/Resume: Press the spacebar to pause or resume the simulation
- Observe: Watch the double pendulum's chaotic motion and color changes
Project Structure
src/
├── main.js # Application entry point
├── core/
│ ├── Background.js # Background rendering
│ ├── events.js # Event system
│ ├── GameObject.js # Base game object class
│ ├── loop.js # Game loop management
│ ├── Scene.js # Base scene class
│ └── SceneManager.js # Scene management
├── entities/
│ └── DoublePendulum.js # Double pendulum implementation
├── scenes/
│ └── MainScene.js # Main simulation scene
└── utility/
└── keyCode.js # Keyboard constantsArchitecture
This boilerplate implements several design patterns:
- Observer Pattern: Event system for decoupling components
- Component Pattern: GameObject base class for reusable entities
- Scene Graph: Hierarchical scene management
- Module Pattern: ES6 modules for clean imports/exports
Customization
Adding New Entities
- Create a new class extending
GameObjectin theentities/folder - Implement
update()andrender()methods - Add the entity to a scene in the scene's constructor
Creating New Scenes
- Create a new class extending
Scenein thescenes/folder - Add entities using
this.add(entity) - Switch scenes using
SceneManager.set(newScene)
Dependencies
- p5.js v1.9.3 - Creative coding library
License
This project is part of the p5js-Boilerplate repository. See the original repository for licensing information.
