Python Forum
need help with floodfill
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help with floodfill
#1
Hello, i'm having some difficulty at a college task and I wonder if you can help me. It is the realization of a floodfill algorithm in python 3 using the queue structure in an array of any dimension. I was following this tutorial, but I do not quite understand what that color of node is. But I know that i have to use pop and append on lines 5 and 8.

Floodfill_with_queue (image, node, target_color, replacement_color):
1. If target_color is equal to replacement_color, return image.
2. If color of node is not equal to target_color, return image.
3. Set the color of node to replacement_color.
4. Set Q to the empty queue.
5. Add node to the end of Q.
6. While Q is not empty:
7. Set n equal to the first element of Q.
8. Remove first element from Q.
9. If the color of the node to the west of n is target_color,
set the color of that node to replacement_color and add that node to the end of Q.
10. If the color of the node to the east of n is target_color,
set the color of that node to replacement_color and add that node to the end of Q.
11. If the color of the node to the north of n is target_color,
set the color of that node to replacement_color and add that node to the end of Q.
12. If the color of the node to the south of n is target_color,
set the color of that node to replacement_color and add that node to the end of Q.
13. Continue looping until Q is exhausted.
14. Return image.
Reply


Messages In This Thread
need help with floodfill - by rfdv - Jul-02-2019, 08:21 PM
RE: need help with floodfill - by perfringo - Jul-03-2019, 08:44 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020