Header file:
graphics.h
Synopsis:
void setallpalette(struct palettetype *palette);
struct palettetype {
unsigned char size; /* no of colors in the palette */
signed char color[MAXCOLOR + 1] /* color nos for each entry in the palette */
};
Description:
setallpalette() sets all palette colors to the values in the given palettetype structure.
setallpalette function in c graphics
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
int main(void) {
/* request auto detection */
int graphicDriver = DETECT, graphicMode;
int color, err, midx, midy, radius = 200;
struct palettetype pal;
/* initialize graphics and local variables */
initgraph(&graphicDriver, &graphicMode,
"C:/TURBOC3/BGI");
/* read result of initialization */
err = graphresult();
if (err != grOk) {
/* an error occurred */
printf("Graphics Error: %s\n",
grapherrormsg(err));
getch();
return 0;
}
/* grab a copy of the palette */
getpalette(&pal);
/* mid position in x and y-axis */
midx = getmaxx() / 2;
midy = getmaxy() / 2;
/* display the default palette colors */
for (color=1; color<=getmaxcolor(); color++) {
setcolor(color);
circle(midx, midy, radius);
radius = radius - 25;
delay(400);
}
/* black out the colors one by one */
for (color=1; color<=getmaxcolor(); color = color + 2) {
setpalette(color, BLACK);
delay(400);
}
/* restore the palette colors */
setallpalette(&pal);
/* clean up */
getch();
closegraph();
return 0;
}
Output: (setallpalette built-in function in c graphics.h)
No comments:
Post a Comment