Постепенное затемнение
реализации: C++, количество: 1
реализации(исходники)
+добавить
Алгоритм и пример постепенного затмения
Реализации: C++(1) +добавить реализацию
заполните необходимые поля!
1) Постепенное затмение, code #134[автор:-]
Пример кода, алгоритм постепенного затмения области, C++, code #134
ссылка
+
рейтинг: 7/3,4.85(938), управление:
рейтинг: 7/3,4.85(938), управление:
#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <math.h> #include <dos.h> // this function initializes graphics mode // it will work only if you're using Borland C++ compiler & BGI drivers // if you're using another compiler you should overwrite body of this function void init_gr(void) { /* request autodetection */ int gdriver = DETECT, gmode, errorcode; /* initialize graphics mode */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* return with error code */ } } // this function shuts graphics mode down // it will work only if you're using Borland C++ compiler & BGI drivers // if you're using another compiler you should overwrite body of this function void end_gr(void) { closegraph(); } // this function set filling style // it will work only if you're using Borland C++ compiler & BGI drivers // if you're using another compiler you should overwrite body of this function void SetFillStyle(int pattern,int color) { setfillstyle(pattern,color); } // this function draws a bar // it will work only if you're using Borland C++ compiler & BGI drivers // if you're using another compiler you should overwrite body of this function void Bar(int x1, int y1, int x2, int y2) { bar(x1,y1,x2,y2); } // this function sets palette entry using RGB color coding // it will work only if you're using Borland C++ compiler & BGI drivers // if you're using another compiler you should overwrite body of this function void SetRGBPalette(int colornum, int red, int green, int blue) { setrgbpalette(colornum,red,green,blue); } // this function reads palette // it will work only if you're using Borland C++ compiler & BGI drivers // if you're using another compiler you should overwrite body of this function void GetPalette(struct palettetype far *palette) { getpalette(palette); } #define N 30 // steps of fading to black struct palettetype pal; struct {int R;int G;int B;} colors[16]; int main(void) { // initializing graphics mode init_gr(); // creating palette GetPalette(&pal); for(int i=0;i<pal.size-1;i++) { colors[i+1].R=0; colors[i+1].G=30-2*i; colors[i+1].B=15+i*2; SetRGBPalette(pal.colors[i+1],colors[i+1].R,colors[i+1].G,colors[i+1].B); } // drawing picture for (i=1;i<16;i++) { SetFillStyle(SOLID_FILL,i); Bar((i-1)*43,0,i*43,479); } // fading to balck for (int j=0;j<N;j++) { //delay(50); for (i=1;i<pal.size;i++) SetRGBPalette(pal.colors[i], colors[i].R*(1-(float)j/N), colors[i].G*(1-(float)j/N), colors[i].B*(1-(float)j/N)); } // and back to the light for (j=0;j<N;j++) { //delay(50); for (i=1;i<pal.size;i++) SetRGBPalette(pal.colors[i], colors[i].R*(float)j/N, colors[i].G*(float)j/N, colors[i].B*(float)j/N); } /* clean up */ getch(); end_gr(); return 0; }
//////////////////////////////////////////////////////////////////////////////
//
// Fade to black (slowly turning the light off)
// (c) Johna Smith, 1996
//
// Method description:
// We need only to decrease Red, Green and Blue components for each color
// in palette. For example, if Red component of the first color was
// initially 60 and we want to turn the light off in 30 steps we should
// decrease Red component by 60/30=2 by step.
// To increase productivity of this program you shouldn't use standart
// BGI functions. Use direct methods instead.
//
//////////////////////////////////////////////////////////////////////////////
//
// Fade to black (slowly turning the light off)
// (c) Johna Smith, 1996
//
// Method description:
// We need only to decrease Red, Green and Blue components for each color
// in palette. For example, if Red component of the first color was
// initially 60 and we want to turn the light off in 30 steps we should
// decrease Red component by 60/30=2 by step.
// To increase productivity of this program you shouldn't use standart
// BGI functions. Use direct methods instead.
//
//////////////////////////////////////////////////////////////////////////////



