A p5-like canvas library for quick web graphics and games. Simple API, no framework—just include the script and define setup() and draw().
Include popps.js before your script. Your script defines setup() and draw().
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://js.cadenpopps.com/popps.js"></script>
<script src="your_script.js"></script>
</head>
Important: popps.js runs draw() at a fixed 60 fps by default. This keeps game physics and frame-based logic consistent across different displays (60Hz, 120Hz, 144Hz). Without throttling, higher-refresh monitors would run games 2x or more too fast.
setup() or later.function setup() {
createCanvas(400, 400);
loop(); // or loop(30) for 30 fps
}
function draw() {
background(0);
if (frameCount % 60 == 0) { /* every second at 60fps */ }
}
initPoppsJS() runs.preload() and setup(), preload runs first; when assets are ready, setup runs.setup() runs immediately.loop() in setup (or when ready). draw() is then called ~60 times per second.Call loadImage() / loadJSON() inside preload() to have popps.js wait for them before running setup(). Outside of preload(), they just fetch immediately (image loads async, JSON loads synchronously).
var sprite, levelData;
function preload() {
sprite = loadImage("sprite.png");
levelData = loadJSON("level1.json");
}
function setup() {
createCanvas(400, 400);
loop();
}
Image you can pass to image(). In preload(), setup waits for it.Load a sound once, then play it as many times as you like — each playSound() call is an independent, overlappable instance.
var jumpSound;
function preload() {
jumpSound = loadAudio("jump.wav");
}
function keyPressed() {
if (key === " ") playSound(jumpSound);
}
playSound()..volume(v), .loop(), .noloop(), .pauseSound(), .resumeSound(), and .stop().parentId is given, use that element; otherwise append to body. Returns the 2D context.createCanvas(800, 600); createCanvas(400, 400, "gameContainer");
fill(255) gray, fill(255,0,0) red, fill(255,0,0,0.5) half-transparent.stroke() is called again.strokeArc(...) draws the outline only.strokePoint(x, y [, r]) draws the outline only.strokeText(str, x, y) draws the outline only. Use textSize(n) or fontSize("npx") to set size.text(), e.g. font("serif"). Aliases for the same setter.random() to pick a random element. randomInt floors the result.oneIn(n) is true with 1-in-n odds. fiftyFifty() is a 50% coin flip.