Signup Issues have been resolved (hopefully). If you have previously had issues signing up for the forum, please try again.
0 Members and 1 Guest are viewing this topic.
#include <FL/Fl.H>#include <FL/Fl_Double_Window.H>#include <FL/fl_draw.H>#include <stdio.h>#include <time.h>#define XSIZE 640#define YSIZE 640#define UPDATE_RATE 0.01 // update speed// WINDOW CLASS TO HANDLE DRAWING IMAGEclass MyWindow : public Fl_Double_Window { unsigned char pixbuf[YSIZE][XSIZE][3]; // image buffer // FLTK DRAW METHOD void draw() { fl_draw_image((const uchar*)&pixbuf, 0, 0, XSIZE, YSIZE, 3, XSIZE*3); } // TIMER CALLBACK: CALLED TO UPDATE THE DRAWING static void RenderImage_CB(void *userdata) { MyWindow *win = (MyWindow*)userdata; win->RenderImage(); Fl::repeat_timeout(UPDATE_RATE, RenderImage_CB, userdata); }public: // CTOR MyWindow(int w, int h, const char *name=0) : Fl_Double_Window(w,h,name) { end(); RenderImage(); // show first drawing // Start timer updating Fl::add_timeout(UPDATE_RATE, RenderImage_CB, (void*)this); } // PLOT A PIXEL AS AN RGB COLOR INTO THE PIXEL BUFFER void PlotPixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) { pixbuf[y][x][2] = r; pixbuf[y][x][1] = g; pixbuf[y][x][0] = b; } // MAKE A NEW PICTURE IN THE PIXEL BUFFER, SCHEDULE FLTK TO DRAW IT void RenderImage() { static unsigned char drawcount = 0; for ( int x=0; x<XSIZE; x++ ) for ( int y=0; y<XSIZE; y++ ) PlotPixel(x, y, x+drawcount*drawcount, y+drawcount*drawcount, x*y+drawcount*drawcount); ++drawcount; redraw(); }};int main(int argc, char**argv) { Fl::visual(FL_RGB); // prevents dithering on some systems MyWindow *win = new MyWindow(XSIZE, YSIZE); win->show(); return(Fl::run());}
// PLOT A PIXEL AS AN RGB COLOR INTO THE PIXEL BUFFER void PlotPixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) { pixbuf[y][x][0] = r; pixbuf[y][x][1] = g; pixbuf[y][x][2] = b; } // MAKE A NEW PICTURE IN THE PIXEL BUFFER, SCHEDULE FLTK TO DRAW IT void RenderImage() { static unsigned char drawcount = 0; for ( int x=0; x<XSIZE; x++ ) for ( int y=0; y<XSIZE; y++ ) PlotPixel(x, y, drawcount+y/3.14, drawcount+x/3.14, x*y*.01); ++drawcount; redraw(); }};
#include <FL/Fl.H>#include <FL/Fl_Double_Window.H>#include <FL/fl_draw.H>#include <stdio.h>#include <time.h>#include <math.h>#define XSIZE 640#define YSIZE 640#define UPDATE_RATE .01 // update speedconst double PI = 4.0*atan(1.0);// WINDOW CLASS TO HANDLE DRAWING IMAGEclass MyWindow : public Fl_Double_Window { unsigned char pixbuf[YSIZE][XSIZE][3]; // image buffer // FLTK DRAW METHOD void draw() { fl_draw_image((const uchar*)&pixbuf, 0, 0, XSIZE, YSIZE, 3, XSIZE*3); } // TIMER CALLBACK: CALLED TO UPDATE THE DRAWING static void RenderImage_CB(void *userdata) { MyWindow *win = (MyWindow*)userdata; win->RenderImage(); Fl::repeat_timeout(UPDATE_RATE, RenderImage_CB, userdata); }public: // CTOR MyWindow(int w, int h, const char *name=0) : Fl_Double_Window(w,h,name) { end(); RenderImage(); // show first drawing // Start timer updating Fl::add_timeout(UPDATE_RATE, RenderImage_CB, (void*)this); } // PLOT A PIXEL AS AN RGB COLOR INTO THE PIXEL BUFFER void PlotPixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) { pixbuf[y][x][0] = r; pixbuf[y][x][1] = g; pixbuf[y][x][2] = b; } // MAKE A NEW PICTURE IN THE PIXEL BUFFER, SCHEDULE FLTK TO DRAW IT void RenderImage() { static unsigned char drawcount = 0; for ( int x=0; x<XSIZE; x++ ) for ( int y=0; y<XSIZE; y++ ) PlotPixel(x, y, ((drawcount*PI)+y)*.003*x, ((drawcount*PI)+x)*.002*y, drawcount*(PI*.001)*((x+y)/2) ); ++drawcount; redraw(); }};int main(int argc, char**argv) { Fl::visual(FL_RGB); // prevents dithering on some systems MyWindow *win = new MyWindow(XSIZE, YSIZE); win->show(); return(Fl::run());}