int main(int argc, char** argv) { //Create the scene readScene("ModernHouse"); rayTracing(); save_png_to_file("image.png"); //Create the window glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(H_RES, V_RES); glutInitWindowPosition(500, 200); glutCreateWindow("Ray tracing"); glClearColor(1.0, 1.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); gluOrtho2D(0.0, H_RES, 0.0, V_RES); //Call to callback function glutDisplayFunc(display); glutMainLoop(); display(); return (EXIT_SUCCESS); }
int main () { bitmap_t fruit; int x; int y; /* Create an image. */ fruit.width = 100; fruit.height = 100; fruit.pixels = calloc (sizeof (pixel_t), fruit.width * fruit.height); for (y = 0; y < fruit.height; y++) { for (x = 0; x < fruit.width; x++) { pixel_t * pixel = pixel_at (& fruit, x, y); pixel->red = pix (x, fruit.width); pixel->green = pix (y, fruit.height); } } /* Write the image to a file 'fruit.png'. */ save_png_to_file (& fruit, "fruit.png"); return 0; }
int main(int argc, const char* argv[]){ bitmap_t image; image.width = 100; image.height = 100; image.pixels = calloc(sizeof(pixel_t),image.width*image.height); pixel_t red={255,0,0}; pixel_t white={255,255,255}; line(&image,13, 20, 80, 40, &white); line(&image,20, 13, 40, 80, &red); line(&image,80, 40, 13, 20, &red); save_png_to_file(&image,"lesson1.png"); return 0; }
void net_to_png( net_t *n, char *file_path, int scale ) { assert( n != NULL ); bitmap_t pic; pic.width = n->cols * scale; pic.height = n->rows * scale; pic.pixels = calloc( sizeof(pixel_t), pic.width * pic.height ); if( pic.pixels == NULL ) print_error("alloc"); int i; int x1; int y1 = 0; pixel_t *pixel; // One cell is 'scale'x'scale' size for( unsigned int y = 0; y < pic.height; y+= scale ) { x1 = 0; for( unsigned int x = 0; x < pic.width; x+= scale ) { i = ( n->cols * y1 + x1 ); if( n->vec[i] == 1 ) { for( int a = 0; a < scale; a++ ) { for( int b = 0; b < scale; b++ ) { // White pixel = pixel_at( &pic, x + a, y + b ); pixel->red = 255; pixel->green = 255; pixel->blue = 255; } } } x1++; } y1++; } save_png_to_file( &pic, file_path ); free(pic.pixels); }
void ReleasedButton(Button *btn) { switch(btn->id) { case 1: btn->state = 0; TaskMngr_AppExit(0, 0, 0); break; case 2: { btn->state = 0; image_t img; img.bitmap = Graphics_GetScreenBuffer(); img.w = 240; img.h = 400; img.bit = 16; save_png_to_file (&img, "/usr/Zbin/tmp/shoot.png"); break; } } }
void MyMainWindow::keyEvent(int type, int key) { if(type == KEY_DOWN) { switch (key) { case KEY_CAMERA: { image_t img; img.bitmap = Graphics_GetScreenBuffer(); img.w = GRSYS_WIDTH; img.h = GRSYS_HEIGHT; img.bit = 16; save_png_to_file (&img, "/usr/Zbin/shoot.png"); break; } case KEY_SEND: break; case KEY_MULTI: TaskMngr_Show(); break; case KEY_END: TaskMngr_AppExit(0, 0, 0); break; case BNS_VOLUP_K: m_player->incrementVolume(); volumeTimer.timerEventSignal().clear(); volumeTimer.timerEventSignal().connect( [this](Timer*) { volumeTimer.stop(); eventManager()->notifyAfterEvent( [this]() { volumeTimer.start(100); volumeTimer.timerEventSignal().clear(); volumeTimer.timerEventSignal().connect( [this](Timer*) { m_player->incrementVolume(); }); }); }); volumeTimer.start(800); break; case BNS_VOLDOWN_K: m_player->decrementVolume(); volumeTimer.timerEventSignal().clear(); volumeTimer.timerEventSignal().connect( [this](Timer*) { volumeTimer.stop(); eventManager()->notifyAfterEvent( [this]() { volumeTimer.start(100); volumeTimer.timerEventSignal().clear(); volumeTimer.timerEventSignal().connect( [this](Timer*) { m_player->decrementVolume(); }); }); }); volumeTimer.start(800); break; } } if(type == KEY_UP) { switch (key) { case BNS_VOLUP_K: case BNS_VOLDOWN_K: volumeTimer.stop(); break; } } eventManager()->update(); }
int main ( int argc, char *argv[] ) { bitmap_t skyplot; int x; int y; int fixnum=0; // FILE *fp; char sbuf[8192]; int nlines,nline, prn,elev,azi,snr,r,g,b; char *d; double ra; unsigned ringptr=0; struct nmea_shm *sh; int sh_p=-1; struct timeval tv; int oldtv,delta; int debug=0; int shmunit_nmea=0; int interval=100; char c; while ((c=getopt(argc,argv,"i:p:u:d"))!=(char)-1) { switch (c) { case 'd': debug=1; break; case 'i': interval = atoi(optarg); break; case 'u': shmunit_nmea = atoi(optarg); break; case 'p': if (strlen(optarg)<sizeof(pngname)) strcpy(pngname,optarg); break; default: printf("usage: %s -u shmunit -p filename.png -i interval [-d]\n",argv[0]); return -1; } } sh=attach_nmea_shm(shmunit_nmea); if (!sh) { fprintf(stderr,"shm failed\n"); return -1; } skyplot.width=CTRV*2; skyplot.height=/*CTRV*2+200*/BASL+2; skyplot.pixels=calloc(sizeof(pixel_t), skyplot.width*skyplot.height); for (y=0; y<skyplot.height; y++) { for (x=0; x<skyplot.width; x++) { pixel_t *pixel=pixel_ptr(&skyplot, x, y); pixel->red=pix(x, skyplot.width); pixel->green=pix(y, skyplot.height); pixel->red=0xff*0; pixel->green=0xff*0; pixel->blue=0xff*0; } } for (ra=0; ra<(3.14159266*2); ra+=0.001) { x=CTRV+RADV*cos(ra); y=CTRV+RADV*sin(ra); pixel_t * pixel = pixel_ptr (&skyplot, x, y); pixel->red=0; pixel->green=0; pixel->blue=0xff; x=CTRV+RADV*cos(ra) * 0.5; y=CTRV+RADV*sin(ra) * 0.5; pixel = pixel_ptr (&skyplot, x, y); pixel->red=0; pixel->green=0; pixel->blue=0xff; } //fp=fopen(argv[1],"rt"); // fp=0; oldtv=0; /*while (!feof(fp))*/ for (;;) { while (nmea_gets(sbuf,sh,&sh_p,8192)<=0) { // printf("sleep %i\n",sh->head); gettimeofday(&tv,NULL); delta=tv.tv_sec-oldtv; if ((oldtv==0)||(delta<0)||(delta>interval)) { oldtv=tv.tv_sec; save_png_to_file (&skyplot, pngname); } sleep(1); } //fgets(sbuf,8192,fp); //printf("%s\n",sbuf); srcp=sbuf; //$GPGGA,170551,x,N,x,E,2,09,1.0,32.2,M,41.7,M,,*72 d=cutp(); if (strcmp("$GPGGA",d)==0) { //$GPGGA,173831,x,N,x,E,2,07,1.2,40.7,M,41.7,M,,*70 cutp(); //drop time cutp(); //lat cutp(); //lat cutp(); //lon cutp(); //lon x=atoi(cutp()); //fix y=atoi(cutp()); //sats ///printf("%i %i %i\n",++fixnum,x,y); ringdata1[ringptr]=x; ringdata2[ringptr]=y; ++ringptr; if (ringptr>=RINGSIZE) ringptr=0; } else if (strcmp("$GPGSV",d)==0) { nlines=atoi(cutp()); nline=atoi(cutp()); // printf("%i %i\n",nlines,nline); cutp(); d=cutp(); do { if (*d) { prn=atoi(d); elev=atoi(cutp()); azi=atoi(cutp()); snr=atoi(cutp()); //printf("%i %i %i %i \n",prn,elev,azi,snr); ra=azi/180.0 * 3.14159265; y=CTRV-RADV*cos(ra) * (90.0-elev)/90.0; x=CTRV+RADV*sin(ra) * (90.0-elev)/90.0; r=0; g=0; b=0; if (snr==0) r=0xFF; else if (snr<20) b=0xFF; else if (snr>50) r=g=b=0xFF; else r=g=b=255.0/50.0*snr; pixel_t *pixel; #define SINGLEPIXEL(px,py,pr,pg,pb) \ pixel= pixel_ptr(&skyplot, px, py); \ pixel->red=pr; \ pixel->green=pg; \ pixel->blue=pb; #define FATPIXEL(px,py,pr,pg,pb) \ SINGLEPIXEL(px-1,py-1,pr,pg,pb); SINGLEPIXEL(px ,py-1,pr,pg,pb); SINGLEPIXEL(px+1,py-1,pr,pg,pb); \ SINGLEPIXEL(px-1,py ,pr,pg,pb); SINGLEPIXEL(px ,py ,pr,pg,pb); SINGLEPIXEL(px+1,py ,pr,pg,pb); \ SINGLEPIXEL(px-1,py+1,pr,pg,pb); SINGLEPIXEL(px ,py+1,pr,pg,pb); SINGLEPIXEL(px+1,py+1,pr,pg,pb); FATPIXEL(x,y,r,g,b); if (snr<10) pixel->red=0xFF; y=BASL-SCAL*elev; x=CTRV+RADV*((azi/180.0)-1.0); r=g=b=255.0/50.0*snr; if (snr>=50) g=255; FATPIXEL(x,y,r,g,b); } d=cutp(); } while (*d); } } // fclose(fp); // save_png_to_file (&skyplot, argv[2]); return 0; }