putpixel() function in C
Last Updated :
23 Jan, 2018
The header file graphics.h contains putpixel() function which plots a pixel at location (x, y) of specified color.
Syntax :
void putpixel(int x, int y, int color);
where,
(x, y) is the location at which pixel
is to be put , and color specifies
the color of the pixel.
Explanation : A RED color pixel at (50, 40) can be drawn by using putpixel(50, 40, RED). putpixel() function can be used to draw circles, lines and ellipses using various algorithms.
Below is the implementation of putpixel() function.
#include <graphics.h>
#include <stdio.h>
int main()
{
int gd = DETECT, gm, color;
initgraph(&gd, &gm, "" );
putpixel(85, 35, GREEN);
putpixel(30, 40, RED);
putpixel(115, 50, YELLOW);
putpixel(135, 50, CYAN);
putpixel(45, 60, BLUE);
putpixel(20, 100, WHITE);
putpixel(200, 100, LIGHTBLUE);
putpixel(150, 100, LIGHTGREEN);
putpixel(200, 50, YELLOW);
putpixel(120, 70, RED);
getch();
closegraph();
return 0;
}
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...