Skip to main content

Setting Color Palette

The Default Color Palette#

In WASM-4, you can set 4 colors to your liking. The default color palette looks like this:

Color 1: #e0f8cf
Color 2: #86c06c
Color 3: #306850
Color 4: #071821

It's inspired by the color palette of the original Gameboy. But you can set your own palette too.

Picking a Color Palette#

There are a lot of different color palettes available. One of the most famous is probably https://lospec.com/palette-list.

You can set the number of colors to 4 and get a lot of palettes presented. For this tutorial, I'll pick the EN4 Palette.

Color 1: #fbf7f3
Color 2: #e5b083
Color 3: #426e5d
Color 4: #20283d

This palette provides enough "green" for the snake and a "not green" for the fruit. Also the background is fine.

Setting in source#

Unlike most other fantasy consoles, pretty much everything is done in code. Setting the color palette belongs to this category. But before you go and mess with the code, you should remove most of the existing code.

import * as w4 from "./wasm4";
export function update(): void {}

The update function is required. Or WASM-4 won't be able to show anything. To set up the color palette, it's usually enough to do this once at the start of the game.

So in most cases, you'd add a "start" function and export it too. WASM-4 will execute it once at the start.

export function start(): void {    store<u32>(w4.PALETTE, 0xfbf7f3, 0 * sizeof<u32>())    store<u32>(w4.PALETTE, 0xe5b083, 1 * sizeof<u32>())    store<u32>(w4.PALETTE, 0x426e5d, 2 * sizeof<u32>())    store<u32>(w4.PALETTE, 0x20283d, 3 * sizeof<u32>())}