Get pixel values.
#include <graph.h>
short __far _getpixel( short x, short y );
short __far _getpixel_w( double wx, double wy );
x, y | Pixel position | |
wx, wy | Pixel position |
The functions in the _getpixel family return the pixel value (a color index) at a specified location. The _getpixel function uses the view coordinate (x, y). The _getpixel_w function uses the window coordinate (wx, wy). The range of possible pixel values is determined by the current video mode. The color translation of pixel values is determined by the current palette.
If successful, the function returns the color index. If the function fails (for example, the point lies outside the clipping region, or the program is in a text mode), it returns –1.
Standards:None
16-Bit:DOS
32-Bit:None
_getvideoconfig, _grstatus, _remapallpalette, _remappalette, _selectpalette, _setpixel functions, _setvideomode
/* GPIXEL.C: This program assigns different colors to randomly
* selected pixels.
*/
#include <conio.h>
#include <stdlib.h>
#include <graph.h>
void main( void )
{
short xvar, yvar;
struct _videoconfig vc;
/* Find a valid graphics mode. */
if( !_setvideomode( _MAXCOLORMODE ) )
exit( 1 );
_getvideoconfig( &vc );
/* Draw filled ellipse to turn on certain pixels. */
_ellipse( _GFILLINTERIOR, vc.numxpixels / 6, vc.numypixels / 6,
vc.numxpixels / 6 * 5, vc.numypixels / 6 * 5 );
/* Draw random pixels in random colors... */
while( !_kbhit() )
{
/* ...but only if they are already on (inside the ellipse). */
xvar = rand() % vc.numxpixels;
yvar = rand() % vc.numypixels;
if( _getpixel( xvar, yvar ) != 0 )
{
_setpixel( xvar, yvar );
}
}
_getch(); /* Throw away the keystroke. */
_setvideomode( _DEFAULTMODE );
exit( 0 );
}