Last active
December 11, 2015 18:29
-
-
Save RayViljoen/293566e1eaeb278e1170 to your computer and use it in GitHub Desktop.
ZigZag array iteration for use with isometric arrays.
This file contains 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
# Isometric map | |
### | |
Produces: | |
00 | |
10 , 01 | |
20 , 11 , 2 | |
30 , 21 , 12 , 03 | |
31 , 22 , 13 | |
32 , 23 | |
33 | |
### | |
#From: | |
map = [ | |
['00','01','02','03'] | |
['10','11','12','13'] | |
['20','21','22','23'] | |
['30','31','32','33'] | |
] | |
# Size | |
size = map.length | |
# Top half of array | |
for i in [0...size] | |
for j in [0...(i + 1)] | |
console.log "#{j}, #{i-j}" | |
# Bottom half of array | |
for i in [1...(size + 1)] | |
for j in [0...(size - i)] | |
console.log "#{i+j}, #{map.length-j-1}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very good man... thanks for sharing