Last active
March 7, 2016 16:07
-
-
Save poemdexter/225a98fd94eaba07aa29 to your computer and use it in GitHub Desktop.
flipping pixels something something for ian
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
/* | |
a 2D array can easily be represented by a standard array. given an array that has a size equal to a square number, | |
reverse the order of the "rows" into a new array without changing the order of the elementes in each row. | |
example: | |
oldArray newArray | |
row 1 [0,1,2 row 3 [6,7,8 | |
row 2 3,4,5 --> row 2 3,4,5 | |
row 3 6,7,8] row 1 0,1,2] | |
*/ | |
int x = width; // known size | |
int size = width * width; // always a square | |
int[] newArray = new int[size]; | |
for (int i = 0; i < width; i++) { | |
for (int j = 0; j < width; j++) { | |
int oldArrayPos = size - width * (i + 1); | |
newArray[i * width + j] = oldArray[oldArrayPos + j]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment