[Oberon] FPGA - Simple Graph Fill

Wim Niemann niemannw at xs4all.nl
Fri Nov 9 16:16:47 CET 2018


Hi,

bug solved.
The trace says '0 303 201  north start'. Now the color must become the fill color 8 but a few lines further on the trace prints again '0 303 201'.

Like Jörg says, the order of S, E, N, W is not relevant. I'm sorry for the confusion but the directions East and South-East stemmed from the outline algorithm and were not related to a flood fill.

The recursion can be replaced by iteration but a quick internet search indicated you still push new candidate pixels on a stack. For larger images, this is really memory and cpu intensive. From memory, I believe it is possible to iterate top down and do two scans left and right to prevent a pixel stack but I don't have an example by hand.

Here's another approach which draws a filled circle in a single color without flood-fill:

The 'Bresenham circle' version in 'Foley and van Dam' differs slightly from the Oberon version and is presented in C:  (kudos for keeping it human readable)

void MidpointCircle(int radius, int color)
/* Assumes the center of circle is at origin. */
{
	int	x = 0;
	int	y = radius;
	int	d = 1 - radius;
	CirclePoints(x, y, color);	/* draw eight-fold symmetric points */
	while (y > x) {
		if (d < 0) {	/* Select E */
			d += 2*x + 3;
		} else {	/* Select SE */
			d += 2*(x-y) + 5;
			y--;
		}
		x++;
		CirclePoints(x, y, color);
	}
}

This version either draws pixels at the same horizontal line or decreases y to a new scanline. Instead of drawing the eight pixels you can fill a horizontal line section when y is decreased to obtained a filled circle.

A border color can then be achieved by drawing an outline in the border color.

Wim


More information about the Oberon mailing list