Thanks alot. This is great.
________________________________
From: %%email.bounce%% on behalf of Luc Le Blanc
Sent: Mon 17/09/2007 4:36 PM
To: Palm Developer Forum
Subject: RE: Drawing and filling in shapes
Tang, Diana wrote:
> Thanks. Do you know anything about filling in and drawing
> triangle shapes?
Note: DrawLine() is a wrapper to either call WinDrawLine (regular PalmOS API)
or HRWinDrawLine (Sony hi res API).
// *** WinFillTriangle ***
// Adapted from Tom Z. Meinlschmidt's code ([EMAIL PROTECTED])
// -> points : pointer to array of 3 PointType structs (Int16 x, y)
void WinFillTriangle( PointType *points )
{
PointType *top = NULL;
PointType *down = NULL;
PointType *middle = NULL;
float xStart, xEnd, dTopDown, dTopMiddle, dMiddleDown;
Int16 i, y;
for ( i = 3; i--; )
{
if ( ( top == NULL ) || ( top->y > points[ i ].y ) )
top = &points[ i ];
if ( ( down == NULL ) || ( down->y < points[ i ].y ) )
down = &points[ i ];
}
for ( i = 3; i--; )
{
if ( ( top == &points[ i ] ) || ( down == &points[ i ] ) )
continue;
middle = &points[i];
break;
}
dTopDown = ( y = ( down->y - top->y ) ) == 0 ? 1.0 : ( float ) (
down->x - top->x ) / ( float ) y; // compute slopes
dTopMiddle = ( y = ( middle->y - top->y ) ) == 0 ? 1.0 : ( float ) (
middle->x - top->x ) / ( float ) y; // but set slope = 1.0 if
dMiddleDown = ( y = ( down->y - middle->y ) ) == 0 ? 1.0 : ( float ) (
down->x - middle->x ) / ( float ) y; // divisor is 0
for ( i = top->y; i <= down->y; i++ )
{
y = i - top->y;
xStart = top->x + ( dTopDown * y );
if ( i < middle->y )
xEnd = top->x + ( dTopMiddle * y );
else
xEnd = middle->x + ( dMiddleDown * ( i - middle->y ) );
DrawLine( ( Int16 ) xStart, i, ( Int16 ) xEnd, i );
// draw horizontal lines starting
}
// from top of triangle
}
--
Luc Le Blanc
--
For information on using the ACCESS Developer Forums, or to unsubscribe, please
see http://www.access-company.com/developers/forums/
--
For information on using the ACCESS Developer Forums, or to unsubscribe, please
see http://www.access-company.com/developers/forums/