putpixel() function in C
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.
// C Implementation for putpixel() #include <graphics.h> #include <stdio.h> // driver code int main() { // gm is Graphics mode which is // a computer display mode that // generates image using pixels. // DETECT is a macro defined in // "graphics.h" header file int gd = DETECT, gm, color; // initgraph initializes the // graphics system by loading a // graphics driver from disk initgraph(&gd;, &gm;, ""); // putpixel function 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 function closes the // graphics mode and deallocates // all memory allocated by // graphics system . closegraph(); return 0; } |
chevron_right
filter_none
Output :
Recommended Posts:
- arc function in C
- feupdateenv() function in C++
- raise() function in C++
- iswlower() function in C/C++
- Address of a function in C or C++
- strlwr() function in C
- Inline function in C
- iswpunct() function in C/C++
- iswblank() function in C/C++
- towupper() function in C/C++
- exp2() function in C++ STL
- strtod() function in C/C++
- vwprintf() function in C/C++
- vswscanf() Function in C/C++
- iswupper() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



