Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cfset matrixWidth = 8>
- <cfset matrixHeight = 58>
- <cfset matrixOrientation = 'rows'>
- <cfset matrixOrigin = 'bottomRight'>
- <cfset serpentine = true>
- <cffunction name='mapXY'>
- <cfargument name='row' default="">
- <cfargument name='col' default="">
- <!--- COLUMNS LAYOUT --->
- <cfif matrixOrientation eq 'columns'>
- <!--- ORIGIN BOTTOM LEFT --->
- <cfif matrixOrigin EQ 'bottomLeft'>
- <cfif col mod 2 EQ 0 OR serpentine EQ false>
- <cfreturn ((col + 1) * matrixHeight) - row - 1>
- <cfelse>
- <cfreturn ((col) * matrixHeight) + row>
- </cfif>
- </cfif>
- <!--- ORIGIN TOP LEFT --->
- <cfif matrixOrigin EQ 'topLeft'>
- <cfif col mod 2 EQ 0 OR serpentine EQ false>
- <cfreturn (col * matrixHeight) + row>
- <cfelse>
- <cfreturn ((col + 1) * matrixHeight) - row - 1>
- </cfif>
- </cfif>
- <!--- ORIGIN BOTTOM RIGHT --->
- <!--- GOING BACKWARDS --->
- <cfif matrixOrigin EQ 'bottomRight'>
- <cfset invertCol = matrixWidth - col>
- <cfif invertCol mod 2 EQ 1 OR serpentine EQ false>
- <cfreturn ((invertCol) * matrixHeight) - row - 1>
- <cfelse>
- <cfreturn ((invertCol - 1) * matrixHeight) + row>
- </cfif>
- </cfif>
- <!--- ORIGIN TOP RIGHT --->
- <!--- GOING BACKWARDS --->
- <cfif matrixOrigin EQ 'topRight'>
- <cfset invertCol = matrixWidth - col>
- <cfif invertCol mod 2 EQ 1 OR serpentine EQ false>
- <cfreturn ((invertCol - 1) * matrixHeight) + row>
- <cfelse>
- <cfreturn (invertCol * matrixHeight) - row - 1>
- </cfif>
- </cfif>
- <!--- ROWS LAYOUT --->
- <cfelseif matrixOrientation eq 'rows'>
- <!--- ORIGIN TOP LEFT --->
- <cfif matrixOrigin EQ 'topLeft'>
- <cfif row mod 2 EQ 0 OR serpentine EQ false>
- <cfreturn (row * matrixWidth) + col>
- <cfelse>
- <cfreturn ((row + 1) * matrixWidth) - col - 1>
- </cfif>
- </cfif>
- <!--- ORIGIN TOP RIGHT --->
- <cfif matrixOrigin EQ 'topRight'>
- <cfif row mod 2 EQ 0 OR serpentine EQ false>
- <cfreturn ((row + 1) * matrixWidth) - col - 1>
- <cfelse>
- <cfreturn ((row) * matrixWidth) + col>
- </cfif>
- </cfif>
- <!--- ORIGIN BOTTOM LEFT --->
- <!--- GOING BACKWARDS --->
- <cfif matrixOrigin EQ 'bottomLeft'>
- <cfset invertRow = matrixHeight - row>
- <cfif invertRow mod 2 EQ 1 OR serpentine EQ false>
- <cfreturn ((invertRow-1) * matrixWidth) + col>
- <cfelse>
- <cfreturn ((invertRow) * matrixWidth) - col - 1>
- </cfif>
- </cfif>
- <!--- ORIGIN BOTTOM RIGHT --->
- <!--- GOING BACKWARDS --->
- <cfif matrixOrigin EQ 'bottomRight'>
- <cfset invertRow = matrixHeight - row>
- <cfif invertRow mod 2 EQ 1 OR serpentine EQ false>
- <cfreturn ((invertRow) * matrixWidth) - col - 1>
- <cfelse>
- <cfreturn ((invertRow - 1) * matrixWidth) + col>
- </cfif>
- </cfif>
- </cfif>
- </cffunction>
Advertisement
Add Comment
Please, Sign In to add comment