C++ Can't Figure Out How To Shuffle Image -
i've been stuck on bit now. need break image down 9 boxes(2d array) , shuffle it. imported image twice, once src , once target, 2 arrays. need src image shuffle , output target, without repeating tile, cant figure out how that....here's code:
#include "pgmio.h" #include <iostream> #include <ctime> void shuffle_image_3(pgm src, pgm & target); int main(int argc, char ** argv) { srand(time(null)); pgm src, target; readpgm("random.pgm", src); //2d array src readpgm("random.pgm", target); //2d array target shuffle_image_3(src, target); writepgm("random_shuffled.pgm", target); system("random_shuffled.pgm"); return 0; } void shuffle_image_3(pgm src, pgm & target) { if (src.row != target.row || src.col != target.col) { return; } //if sizes aren't equal, returns nothing //"used[i][j]==true means tile in source //at row , column j has been copied target //initially, false, meaning none of //tiles in source have been copied bool used[3][3]; (int = 0; < 3; i++) { (int j = 0; j < 3; j++) { used[i][j] == false; } } (int = 0; < 3; i++) { (int j = 0; j < 3; j++) { //randomly select tile in src //copy pixel values tile target int r, c; { //randomly select tile in src r = rand() % 3; c = rand() % 3; } while (used[r][c] == true); used[r][c] == true; //dont know how move tile @ row r , col c src //to target @ row , col j } } }
Comments
Post a Comment