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
#2
Without effort from your side there will be no help.

Write code according to algorithm and do it as much as you can. Put comment in places where you don't know what to write and then return with your code and specific question.

Something along those lines:

def floodfill_with_queue (image, node, target_color, replacement_color):
    if target_color == replacement_color:
        return image
    /.../
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Forum Jump:

User Panel Messages

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