Skip to content

Instantly share code, notes, and snippets.

@scambier
Created September 24, 2023 17:18
Show Gist options
  • Save scambier/9c6fe468b6414b291e6a84d113917b5d to your computer and use it in GitHub Desktop.
Save scambier/9c6fe468b6414b291e6a84d113917b5d to your computer and use it in GitHub Desktop.
Bayer dithering in PICO-8
-- https://www.lexaloffle.com/dl/docs/pico-8_manual.html#FILLP
local dither={
0b0000000000000000,
0b1000000000000000,
0b1000000000100000,
0b1010000000100000,
0b1010000010100000,
0b1010010010100000,
0b1010010010100001,
0b1010010110100001,
0b1010010110100101,
0b1110010110100101,
0b1110010110110101,
0b1111010110110101,
0b1111010111110101,
0b1111110111110101,
0b1111110111110111,
0b1111111111110111,
0b1111111111111111,
}
local p=0
local col1=0
local col2=1
function _draw()
cls()
p+=1
if p%17==0 then
col1+=1
col2+=1
end
col1=col1%16
col2=col2%16
local col=(col2<<4)|col1
fillp(dither[p%17])
rectfill(16,16,32,32,col)
for l=0,128 do
fillp(dither[(l/(120/16))\1+1])
line(40,l,56,l,col)
end
end
@scambier
Copy link
Author

bayer_0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment