📜 ⬆️ ⬇️

Simple screensaver using CImg, C ++ library

Good day!
This week I published an article where I gave a brief description of the main methods of the CImg library and analyzed the simplest example. Frankly, the post was intended to invite, but nevertheless, I tried to make it as informative as possible. As a matter of fact, as it was planned earlier and considering the wish of skor , I decided to try to write an elementary screensaver using CImg . It became interesting - welcome under the cat!

Foreword

Immediately make a reservation, the program does not pretend to the "title" of a full screen saver. The goal was to try to disassemble a more complex example of using the above library.

Code

//  CImg #include "CImg.h" //   #define PI 3.14 //     std  cimg_library      using namespace cimg_library; using namespace std; //    int main (int argc, char **argv){ //  ,     //  - , ,   ,     //      CImg<float> logo, logo_layer_1 = CImg<>(800,600,1,1,0); //     //      "Welcome to CImg simple screensaver" logo_layer_1.draw_text(120,5,"Welcome to", CImg<>::vector(255).data(),CImg<>::vector(0).data(),1,128); logo_layer_1.draw_text(300,140,"CImg", CImg<>::vector(255).data(),CImg<>::vector(0).data(),1,128); logo_layer_1.draw_text(250,285, "simple", CImg<>::vector(255).data(),CImg<>::vector(0).data(),1,128); logo_layer_1.draw_text(120,425,"screensaver!", CImg<>::vector(255).data(),CImg<>::vector(0).data(),1,128); //     logo_layer_1.blur(6); //   logo_layer_1.normalize(0,255); //     CImg<float> logo_layer_2 = CImg<>(logo_layer_1.width(),logo_layer_1.height(),1,1,0); //      logo_layer_2.noise(80,1); //       2 logo_layer_2.deriche(2,0,'y',false); //      10 logo_layer_2.deriche(10,0,'x',false); //         logo logo = logo_layer_1 + logo_layer_2 + logo_layer_1; //      //  ,    ,     get_gradient(), //    "Compute the list of images, corresponding to the XY-gradients of an image" // -  "  ,  XY- " //    CimgList //    ,          CImgList<float> grad = logo.get_gradient(); //      normalize   (-140,140) cimglist_apply(grad,normalize)(-140,140); //    logo logo.normalize(0,255); //  ,   ,     "", //  ,       logo CImg<float> light = CImg<>(300 + 2*logo.width(),300 + 2*logo.height()); //       light.draw_gaussian(0.5f*light.width(),0.5f*light.height(),80,CImg<>::vector(255).data()); //    CImg<unsigned char> img(logo.width(),logo.height(),1,3,0); //  ,      CImgDisplay disp(img," ",true); //     disp.toggle_fullscreen(false); float t = 0; //  ,     'ESC'  'Q' while (!disp.is_closed() && !disp.is_keyQ() && !disp.is_keyESC()) { int pos_x, pos_y, gx, gy; float val; //      pos_x = (int)(img.width()/2 + img.width()*cos(1*t)/2); pos_y = (int)(img.height()/2 + img.height()*sin(3*t)/2); // cimg_forXY -   ,     //  - http://cimg.sourceforge.net/reference/group__cimg__loops.html cimg_forXY(img,x,y) { //   ,         gx = (int)grad[0](x,y); gy = (int)grad[1](x,y); val = 20 + (gx + gy)/2 + light(light.width()/2 + pos_x - x + gx,light.height()/2 + pos_y - y + gy); img(x,y,0) = img(x,y,1) = img(x,y,2) = (unsigned char)(val>255?255:val<0?0:val); } t = t >= 2*PI ? 0 : t+0.02f; //     disp.display(img.draw_image(0,0,0,1,logo,0.1f)); } return 0; } 

')

Observations

In my opinion, the conclusions are not very comforting.

Of the minuses:


Of the benefits:

probably only one can be distinguished:

findings

At this stage in my study of CImg, I want to allow myself to notice that CImg is not quite suitable for creating dynamic scenes. However, as long as there is a desire to continue the study, in the next article we will try to “chew” a complex example for working with statics together with you.
Waiting for comments and suggestions.
Thank you for attention!


PS Tested only under Linux

Source: https://habr.com/ru/post/141011/


All Articles