Created
December 12, 2010 21:50
-
-
Save rngtng/738368 to your computer and use it in GitHub Desktop.
Mapping the Rainbowduino Matrix to the Cube
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
def xy2xyz( x, y ) | |
x2 = 2 + x/4 - 2 * (y/4).floor #3 + x/4 - y/4 | |
y2 = (x - 3.5).abs.ceil - 1 | |
z2 = y % 4 | |
[x2, y2, z2] | |
end | |
def xyz2xy( x, y, z ) | |
x2 = y + 4 - (2*y + 1) * ((x + 1) % 2) | |
y2 = z + 4 - 4*(x / 2).floor | |
[x2, y2] | |
end | |
def x2xy(x) | |
x2 = x % 8 | |
y2 = x / 8 | |
[x2, y2] | |
end | |
def xy2x(x, y) | |
x2 = y * 8 + x | |
[x2] | |
end | |
def x2xyz(x) | |
z2 = x / 16 | |
y2 = (x - (z2 * 4 * 4)) / 4 | |
x2 = x - (z2 * 4 * 4) - y2 * 4 | |
[x2, y2, z2] | |
end | |
def xyz2x(x, y, z) | |
x2 = z * 4 * 4 + y * 4 + x | |
[x2] | |
end | |
def plain2cube(x) | |
xy2x(*xyz2xy(*x2xyz(x))) | |
end | |
def cube2plain(x) | |
xyz2x(*xy2xyz(*x2xy(x))) | |
end | |
64.times do |y| | |
puts plain2cube(*cube2plain(y)) | |
end | |
#8.times do |x| | |
# 8.times do |y| | |
# x2, y2, z2 = xy2xyz( x, y ) | |
# x3, y3 = xyz2xy( x2, y2, z2 ) | |
# puts "#{x},#{y} => #{x2},#{y2},#{z2} => #{x3},#{y3} " | |
# end | |
#end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment