Skip to content

Instantly share code, notes, and snippets.

@bbbradsmith
Created December 27, 2019 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbbradsmith/ce66f701f14d3d82f7dd79371a9a58c4 to your computer and use it in GitHub Desktop.
Save bbbradsmith/ce66f701f14d3d82f7dd79371a9a58c4 to your computer and use it in GitHub Desktop.
Phillips CD-i rule 90 demonstration
# this program generates the "rule 90" fill bitstream
# seen at the start of many Phillips CD-i disc images
import PIL.Image
filename = "cdi90.png"
width = 29
height = 645
# first valid parent row starts at bit 188
seed = [0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1]
# rule 90
rule = [[1,1,0],[0,1,1],[0,0,1],[1,0,0]]
img = PIL.Image.new('1',(width,height),color=0)
# draw seed row
for i in range(width):
p = len(seed)-width
img.putpixel((i,0),1-seed[p+i])
# generate subsequent bits
for i in range(width*(height-1)):
p = len(seed)-width-1
parents = seed[p:p+3]
c = 1 if parents in rule else 0
seed = seed[1:] + [c]
x = i % width
y = 1 + (i // width)
img.putpixel((x,y),1-c)
img.save(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment