A Node.js server that automatically rotates between multiple p5.js sketches using Socket.IO.
-
Install dependencies:
npm install
-
Start the server:
npm start
-
Open your browser to http://localhost:3333
public/ # Static assets served by Express
index.html # Main controller page with iframe
sketches/ # All p5.js sketches
sketch1/ # First sketch
index.html
style.css
sketch.js
sketch2/ # Second sketch
...
sketch3/ # Third sketch
...
server.js # Node.js server with Socket.IO
config.json # Configuration for sketches and timing
- Each sketch is in its own directory with index.html, style.css, and sketch.js
- Main page (index.html) contains an iframe that displays the current sketch
- The server rotates between sketches every 5 seconds (configurable)
- Socket.IO is used to send messages from server to client when it's time to switch
- The client receives these messages and updates the iframe source accordingly
The config.json
file controls the server settings and sketch rotation:
{
"port": 3333,
"switchInterval": 5000,
"sketches": [
{
"path": "sketches/sketch1",
"name": "First Last",
"title": "Rotating Square"
}
]
}
port
: Server port numberswitchInterval
: Time in milliseconds between sketch rotationssketches
: Array of sketch objects, each with:path
: Path to the sketch folder, relative to the public directoryname
: Creator's name (e.g., "First Last")title
: Title of the sketch (e.g., "Bouncing Circles")
- Create a new directory in
public/sketches/
with your sketch files - Add the sketch information to the
sketches
array inconfig.json
- Edit the content of
com.p5switcher.plist
to point to this folder on your system. - Copy the LaunchAgent file to your system
# Copy the plist file to your LaunchAgents directory
cp ./autorun-setup/com.p5switcher.plist ~/Library/LaunchAgents/
- Load the LaunchAgent
launchctl load ~/Library/LaunchAgents/com.p5switcher.plist
- Verify it's working
# Check if it's loaded
launchctl list | grep com.p5switcher
# Manually start it to test
launchctl start com.p5switcher
- To stop the service and autorun, you can unload the LaunchAgent:
launchctl unload ~/Library/LaunchAgents/com.p5switcher.plist