speed Infinity
picture = picture = 'http://goo.gl/Y1UncS' # from Wikimedia

# First sprite
c1 = new Sprite
c1.fd 150
c1.wear picture
await c1.done defer() # Load image

# Get raw image data bits and convert data into
# 32-bit integer array.
d = c1.imagedata()
source = new Uint32Array(d.data.buffer)

# Second Sprite, empty to start.
c2 = new Sprite # fold
  width: d.width
  height: d.height
c2.bk 150

n = c2.imagedata()
target = new Uint32Array(n.data.buffer)

# Apply the bitmask.
for j in [0...source.length]
  target[j] = source[j] & 0xFFFFFFFF

# Set the altered imagedata to sprite 2.
c2.imagedata(n)

# Finally we encode each image using PNG
# compression and then label each image
# with its number of bytes as a PNG file.
labelBytes = (c) -> # fold
  b64 = c.canvas().toDataURL().replace /^.*,/, ''
  bytecount = atob(b64).length
  c.label bytecount + ' bytes',
    font: 'bold 32px Arial', color: yellow
    textShadow: '0 0 7px black'

labelBytes c1
labelBytes c2
ht()