Advertisement
GeeckoDev

cover

Nov 4th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.96 KB | None | 0 0
  1. #include <Imlib2.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5.  
  6. typedef uint32_t Color;
  7.  
  8. int abs(int n)
  9. {
  10.     return (n > 0 ? n : -n);
  11. }
  12.  
  13. int sign(int n)
  14. {
  15.     return (n == 0 ? 0 : (n > 0 ? 1 : -1));
  16. }
  17.  
  18. Color blend_add(Color u, Color v)
  19. {
  20.     int r = ((u >> 16) & 0xFF) + ((v >> 16) & 0xFF);
  21.     int g = ((u >> 8 ) & 0xFF) + ((v >> 8 ) & 0xFF);
  22.     int b = ((u      ) & 0xFF) + ((v      ) & 0xFF);    
  23.    
  24.     r = (r > 0xFF ? 0xFF : r);
  25.     g = (g > 0xFF ? 0xFF : g);
  26.     b = (b > 0xFF ? 0xFF : b);
  27.    
  28.     return (Color)((0xFF << 24) | (r << 16) | (g << 8) | b);
  29. }
  30.  
  31. Color blend_mix(Color u, Color v, int i)
  32. {
  33.     int r = ((u >> 16) & 0xFF) * (255-i) / 255 + ((v >> 16) & 0xFF) * i / 255;
  34.     int g = ((u >> 8 ) & 0xFF) * (255-i) / 255 + ((v >> 8 ) & 0xFF) * i / 255;
  35.     int b = ((u      ) & 0xFF) * (255-i) / 255 + ((v      ) & 0xFF) * i / 255;    
  36.    
  37.     return (Color)((0xFF << 24) | (r << 16) | (g << 8) | b);
  38. }
  39.  
  40. void put(Color *tex, int w, int h, int x, int y, Color c)
  41. {
  42.     if (x < 0 || x >= w || y < 0 || y >= h)
  43.         return;
  44.    
  45.     tex[y*w+x] = blend_add(tex[y*w+x], c);
  46. }
  47.  
  48. void gradient(Color *tex, int w, int h, Color a, Color b)
  49. {
  50.     int i, j;
  51.    
  52.     for (i=0; i<h; i++)
  53.     {
  54.         for (j=0; j<w; j++)
  55.         {
  56.             put(tex, w, h, j, i, blend_mix(a, b, i*255/h));
  57.         }
  58.     }
  59. }
  60.  
  61. void random_noise(Color *tex, int w, int h, Color c, int n)
  62. {
  63.     int i;
  64.    
  65.     for (i=0; i<n; i++)
  66.     {
  67.         int x = rand() % w;
  68.         int y = rand() % h;
  69.        
  70.         put(tex, w, h, x, y, c);
  71.     }
  72. }
  73.  
  74. // ****
  75. // ####****
  76. // ########****
  77. //    #########****
  78. //       ##########****
  79.  
  80. void tape(Color *tex, int w, int h, Color c, int y, int l, int r)
  81. {
  82.     int i, j, k;
  83.    
  84.     for (i=0; i<h; i++)
  85.     {
  86.         for (j=(i-l+1)*abs(r); j<i*abs(r); j++)
  87.         {
  88.             put(tex, w, h, j, y+i*sign(r), c);
  89.         }
  90.     }
  91. }
  92.  
  93. void draw(Color *tex, int w, int h)
  94. {
  95.     random_noise(tex, w, h, 0xAAFFAA, 424242);
  96.     random_noise(tex, w, h, 0xBCABAD, 242424);
  97.    
  98.     tape(tex, w, h, 0x2F3F30, -700, 100, 3);
  99.     tape(tex, w, h, 0x2F3F30, -800, 42, 3);
  100.     tape(tex, w, h, 0x8FEF30, 300, 100, -3);
  101.     tape(tex, w, h, 0x2534FF, 500, 100, -3);
  102.     tape(tex, w, h, 0x700023, 900, 100, -4);
  103.     tape(tex, w, h, 0x561134, 950, 50, -5);
  104.     tape(tex, w, h, 0x002300, 975, 25, -6);
  105.     tape(tex, w, h, 0x424242, 1300, 50, 1);
  106.    
  107.     gradient(tex, w, h, 0x3732FF, 0x0);
  108. }
  109.  
  110. int main()
  111. {
  112.     Imlib_Image img;
  113.     Imlib_Image scaled_img;
  114.     Color *tex;
  115.    
  116.     srand(time(NULL));
  117.    
  118.     img = imlib_create_image(4*851, 4*315);
  119.     imlib_context_set_image(img);
  120.    
  121.     draw(imlib_image_get_data(), 4*851, 4*315);
  122.    
  123.     scaled_img = imlib_create_cropped_scaled_image(
  124.         0, 0, 4*851, 4*315, 2*851, 2*315
  125.     );
  126.     imlib_free_image();
  127.     imlib_context_set_image(scaled_img);
  128.     imlib_save_image("out.png");
  129.     imlib_free_image();
  130.     return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement