Overclock.net banner

Coloring in regions C++.

494 Views 2 Replies 2 Participants Last post by  xHassassin
Hey guys, I'm pretty new to the whole programming scheme... Just wondering if you guys have any tips for how to do this.

Basically, you're given a .txt file with an image on it, like this:

...XXXXXXXX....
..X..............X..
.X..........XXXX..
.X......XXX........
XXX........XXXX.
.....XXXXX........

X will stand for black, . for white.

Now, you want to read this file, and then have the user choose a point, and fill that region in with black.

For example, suppose I choose the point marked with *

...XXXXXXXX....
..X..............X..
.X..........XXXX..
.X......XXX...*....
XXX........XXXX.
.....XXXXX........

The resulting output should be:

...XXXXXXXXXX
..X..............XX
.X..........XXXXX
.X......XXXXXXX
XXX........XXXXX
.....XXXXXXXXX

Apparently I should be using recursive functions for this... Anyone have some tips?
See less See more
1 - 3 of 3 Posts
Read the file in as a map where each node is connected to four others (the node representing the pixels above, below, left and right). Then use either DFS or BFS. Instead of searching for a goal node you stop each branch when it encounters a colored node.
  • Rep+
Reactions: 1
2
Quote:


Originally Posted by rabidgnome229
View Post

Read the file in as a map where each node is connected to four others (the node representing the pixels above, below, left and right). Then use either DFS or BFS. Instead of searching for a goal node you stop each branch when it encounters a colored node.

Thanks, I just thought up that on my walk home today.
My main problem is actually reading the darn thing... Can't figure out how to add a row to a vector... Apparently push_back doesn't work for me.
See less See more
1 - 3 of 3 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top