 # Playing with FEX Lynx again

I got a little time this evening to pickup the FEZ Lynx again and I was looking through the code for the N18 display module. I have a few suggestions

[ol]The routines lack a good clipping algorithm, the result is that the mix of int and unsigned char types can actually get the code to run in an endless loop or terminate early if for example a line is drawn horizontally or vertically and extends beyond 255 pixels in length.
There are ways to improve performance significantly, for example the fill circle routing is not optimally implemented. The code below is a quick and dirty implementation based on the current code that is much faster than the current solution. The video below demonstrates the speed difference, the blue circle is drawn with the faster code and the red with the current implementation.[/ol]

``````
void display_n18::fill_circle(int x, int y, int radius, unsigned short fore_color)
{
int f = 1 - radius;
int dd_f_x = 1;
int dd_f_y = -2 * radius;
int x1 = 0;

while (x1 < y1)
{
if (f >= 0)
{
y1--;
dd_f_y += 2;
f += dd_f_y;
}

x1++;
dd_f_x += 2;
f += dd_f_x;

this->draw_line(x + x1, y - y1, x + x1, y + y1 + 1, fore_color);
this->draw_line(x - x1, y - y1, x - x1, y + y1 + 1, fore_color);

this->draw_line(x + y1, y - x1, x + y1, y + x1 + 1, fore_color);
this->draw_line(x - y1, y - x1, x - y1, y + x1 + 1, fore_color);
}
}

``````
6 Likes

Thanks for the tips. The displayN18 driver is something we would like to improve a lot, so we will look into them.

Keep the suggestions coming!!!