Skip to content

Instantly share code, notes, and snippets.

@RayViljoen
Last active December 11, 2015 18:29
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 RayViljoen/293566e1eaeb278e1170 to your computer and use it in GitHub Desktop.
Save RayViljoen/293566e1eaeb278e1170 to your computer and use it in GitHub Desktop.
ZigZag array iteration for use with isometric arrays.
# 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}"
@staltux
Copy link

staltux commented Dec 6, 2013

very good man... thanks for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment