Set a pixel to the current color.
#include <graph.h>
short __far _setpixel( short x, short y );
short __far _setpixel_w( double wx, double wy );
x, y | Target pixel | |
wx, wy | Target pixel |
The _setpixel and the _setpixel_w functions set a pixel at a specified location to the current color.
The _setpixel function sets the pixel at the view-coordinate point (x, y) to the current color.
The _setpixel_w function sets the pixel at the window-coordinate point (wx, wy) to the current color.
The function returns the previous value of the target pixel. If the function fails (for example, the point lies outside of the clipping region), it will return –1.
Standards:None
16-Bit:DOS
32-Bit:None
_getpixel functions, _setcolor
/* 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 );
}