Flood fill?


#21

Right, let’s start again.

Before you #include <Pokitto.h>,
make sure to #define DISABLEAVRMIN.

Then #include <stack>.

Then this:

class Point
{
public:
	unsigned x;
	unsigned y;

public:
	// C++03
	Point(void) : x(0), y(0) {}
	// C++11
	//Point(void) = default;
	
	Point(unsigned x, unsigned y) : x(x), y(y) {}
};

void floodFill(unsigned x, unsigned y, uint8_t fillColour)
{
	std::stack<Point> stack = std::stack<Point>();

	// If you're using C++11, replace all uses of stack.push(Point(x, y) with stack.emplace(x, y);
	stack.push(Point(x, y));
	
	while(!stack.empty())
	{
		Point point = stack.top();


		if((x % 10) == 0)
		{
			// so I can watch the fill...
			Pokitto::Display::update();
		}
	
		if((point.x >= Pokitto::Display::width) || (point.y >= Pokitto::Display::height))
			return;
			
		unsigned colour = Pokitto::Display::getPixel(point.x, point.y);
		if(colour != fillColour)
		{
			Pokitto::Display::drawPixel(point.x, point.y, fillColour);
			
			if(point.x < Pokitto::Display::width)
				stack.push(Point(point.x + 1, point.y));
				
			if(point.x > 0)
				stack.push(Point(point.x - 1, point.y));
				
			if(point.y < Pokitto::Display::height)
				stack.push(Point(point.x, point.y + 1));
				
			if(point.y > 0)
				stack.push(Point(point.x, point.y - 1));
		}

		// Almost forgot this bit
		stack.pop();
	}	
}

And now there should probably be no compiler errors I hope.


#22

This should probably be in the loop. :stuck_out_tongue:


#23

It is now.
(Clearly I’m trying to do too much at once again.)


#24

@FManga is debugging you @Pharap


#25

@spinal, did you get this working in the end?


#26

Nope, unfortunately I have been completely distracted by useless things again. :frowning: