Last active
January 31, 2019 09:42
-
-
Save scriptype/62a521c771293aefe89b3228ac98aa45 to your computer and use it in GitHub Desktop.
Overlap bitmaps (WIP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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