Skip to content

Instantly share code, notes, and snippets.

@scriptype
Last active January 31, 2019 09:42
Show Gist options
  • Save scriptype/62a521c771293aefe89b3228ac98aa45 to your computer and use it in GitHub Desktop.
Save scriptype/62a521c771293aefe89b3228ac98aa45 to your computer and use it in GitHub Desktop.
Overlap bitmaps (WIP)
var colors = {
0: 'transparent',
1: 'white',
2: '#aaa'
}
var planetMap = [
[ 0, 0, 1, 9, 1 ],
[ 0, 0, 1, 8, 1 ],
[ 1, 1, 1, 7, 1 ],
[ 0, 0, 1, 6, 1 ],
[ 1, 1, 1, 5, 1 ]
]
var craterMap = [
[ 2, 3 ],
[ 0, 5 ]
]
function overlap(map1, map2, x, y) {
return map1.map((row, bitY) => {
return row.map((col, bitX) => {
if (y > bitY || x > bitX || !map2[bitY - y]) {
return col
}
return map2[bitY - y][bitX - x] || col
})
})
}
overlap(planetMap, craterMap, 3, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment