Skip to main content
assetsforwordpress

Pong Game Background

A self-playing Pong game that runs quietly in the background, where two AI paddles rally a glowing ball back and forth forever. It’s fully customizable with colors, shapes, speed, and layout, and it respects the user’s `prefers-reduced-motion` setting by showing a calm static frame instead of constant movement.

Instructions

Nobody Plays. Everybody Watches

Two AIs rally forever behind your content. Your visitors just enjoy the show.

Zero Players, Infinite Rally

No winner, no loser, no login. Just physics and vibes.

Vintage Arcade, Zero Bloat

Pong shipped in 1972 and still runs everywhere. Your JS stack won't survive the next dependency update.

Older Than the Web, Younger Than Your Framework

Left paddle, right paddle, forever equals. The most balanced matchup in web history.

Instructions

Open the JS script in the Supa Code Block element and edit the options at the end of the script. Each option is explained below:

Here's a breakdown of every option you can pass to pongBackground() (or pongEngine()). All of them are optional — anything you omit falls back to the default shown in the Object.assign block.

speed (default: 1) The overall game speed multiplier. It scales the ball's base velocity — the engine calculates a base speed from the canvas size and multiplies it by this value. 1 is normal, 2 makes everything twice as fast, 0.5 makes it slower and calmer. Paddle movement speed is also tied to this value.

ballCount (default: 1) How many balls are in play simultaneously. The engine keeps an internal array of balls synchronized with this number — if you ask for 3, it spawns 3 balls, each served in a random direction. More balls means more chaos and more work for the AI paddles, which track the closest incoming ball.

ballSize (default: 9) The diameter of the ball in pixels. Internally it's halved to get the radius used for drawing and collision detection. Note that the "square" ball shape actually draws it about 1.7× larger than this value, so visual size differs between shapes.

paddleWidth (default: 10) The thickness of each paddle, in pixels. In horizontal orientation this is the paddle's horizontal width; in vertical orientation it becomes the paddle's vertical thickness.

paddleHeight (default: 90) The length of each paddle along the wall it slides on. This gets clamped so it never exceeds the court's shorter dimension. It also affects gameplay: the AI's aim wobble is calculated as a fraction of this value, so taller paddles wander more.

paddleDistance (default: 20) How far the paddles sit from the edges of the canvas, in pixels. It's clamped to at most 35% of the smaller canvas dimension so paddles can never drift into the middle of the court. Set it to 0 to pin the paddles right against the edges.

background (default: '#0b0e14') The court's background color. Any valid CSS color works. If you pass the string 'transparent' (or a falsy value), the canvas is cleared instead of filled, so a page background or gradient behind the canvas shows through.

foreground (default: '#e6edf3') The color used for the paddles, the center line, and the score digits. This should contrast with your background.

accent (default: #4cc9f0) The color of the ball and its trail. Pick something that pops against both the background and the paddles.

glow (default: true) When enabled, paddles, the ball, and the center line are drawn with a canvas shadow blur behind them, creating a soft neon glow effect. It looks nice but costs some rendering performance, so turning it off helps on low-powered devices.

trail (default: true) When enabled, each ball keeps a history of its last ~18 positions and draws fading circles behind it — a comet-tail motion effect. The trail fades and shrinks toward the oldest position.

centerLine (default: true) Draws the classic dashed-looking divider line across the middle of the court — horizontally in horizontal orientation, vertically in vertical orientation. It's drawn at low opacity so it stays subtle.

score (default: false) When enabled, large semi-transparent score numbers (left/right paddle scores) are drawn faded into the middle of the court, like the classic Pong look. The scores increment whenever a ball escapes past a paddle and gets re-served. Off by default since this is meant as a decorative background.

respectReducedMotion (default: true) Accessibility feature. When true, the engine checks the user's prefers-reduced-motion: reduce system setting. If the user has requested reduced motion, the animation never starts — instead a single static frame is drawn once. The engine also listens for changes to that setting live, so toggling it mid-session starts/stops the animation accordingly.

paddleShape (default: 'auto') Controls the paddle's visual style. Three values are recognized:

  • 'auto' — uses the built-in default, which is 'round'.
  • 'round' — a rounded rectangle (pill shape).
  • 'line' — a thin stroked line with rounded caps, more minimal.
  • anything else (e.g. 'square') — falls through to a plain sharp-cornered rectangle.

ballShape (default: 'auto') Controls the ball's visual style:

  • 'auto' — uses the built-in default, which is 'circle'.
  • 'circle' — a filled circle.
  • anything else (e.g. 'square') — a filled square, drawn slightly larger than the circle radius would suggest.

orientation (default: 'horizontal') Which way the game is laid out:

  • 'horizontal' — classic Pong: paddles on the left and right walls, ball moves horizontally.
  • 'vertical' — paddles on the top and bottom, ball moves vertically.
  • 'auto' — picks vertical on small screens (< 768px wide) and horizontal otherwise, so the game always matches the canvas's natural shape.

disableOnMobile (default: false) If true, the animation is completely disabled on viewports narrower than 768px — nothing runs, and the canvas is just cleared. Useful to save battery/CPU on phones. Note this is checked dynamically, so resizing across the 768px boundary starts/stops the game.

grid (default: false) Draws a faint square grid across the entire court, giving it a subtle "blueprint" or retro-arcade texture. Off by default.

gridColor (default: '#8b98a9') The color of the grid lines, only used when grid is true. It's drawn at 14% opacity regardless, so it's always quite subtle.

gridSize (default: 40) The spacing between grid lines in pixels. Clamped to a minimum of 8 so the grid can't become an overwhelming dense mesh.

One thing to note: everything is decorative — this is a fully self-playing simulation. Both paddles are AI-controlled (they chase the nearest incoming ball with a bit of random aim error so they occasionally miss), and scoring just resets the ball with a new serve.