Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Imlib2.h>
- #include <time.h>
- #include <stdlib.h>
- #include <stdint.h>
- typedef uint32_t Color;
- int abs(int n)
- {
- return (n > 0 ? n : -n);
- }
- int sign(int n)
- {
- return (n == 0 ? 0 : (n > 0 ? 1 : -1));
- }
- Color blend_add(Color u, Color v)
- {
- int r = ((u >> 16) & 0xFF) + ((v >> 16) & 0xFF);
- int g = ((u >> 8 ) & 0xFF) + ((v >> 8 ) & 0xFF);
- int b = ((u ) & 0xFF) + ((v ) & 0xFF);
- r = (r > 0xFF ? 0xFF : r);
- g = (g > 0xFF ? 0xFF : g);
- b = (b > 0xFF ? 0xFF : b);
- return (Color)((0xFF << 24) | (r << 16) | (g << 8) | b);
- }
- Color blend_mix(Color u, Color v, int i)
- {
- int r = ((u >> 16) & 0xFF) * (255-i) / 255 + ((v >> 16) & 0xFF) * i / 255;
- int g = ((u >> 8 ) & 0xFF) * (255-i) / 255 + ((v >> 8 ) & 0xFF) * i / 255;
- int b = ((u ) & 0xFF) * (255-i) / 255 + ((v ) & 0xFF) * i / 255;
- return (Color)((0xFF << 24) | (r << 16) | (g << 8) | b);
- }
- void put(Color *tex, int w, int h, int x, int y, Color c)
- {
- if (x < 0 || x >= w || y < 0 || y >= h)
- return;
- tex[y*w+x] = blend_add(tex[y*w+x], c);
- }
- void gradient(Color *tex, int w, int h, Color a, Color b)
- {
- int i, j;
- for (i=0; i<h; i++)
- {
- for (j=0; j<w; j++)
- {
- put(tex, w, h, j, i, blend_mix(a, b, i*255/h));
- }
- }
- }
- void random_noise(Color *tex, int w, int h, Color c, int n)
- {
- int i;
- for (i=0; i<n; i++)
- {
- int x = rand() % w;
- int y = rand() % h;
- put(tex, w, h, x, y, c);
- }
- }
- // ****
- // ####****
- // ########****
- // #########****
- // ##########****
- void tape(Color *tex, int w, int h, Color c, int y, int l, int r)
- {
- int i, j, k;
- for (i=0; i<h; i++)
- {
- for (j=(i-l+1)*abs(r); j<i*abs(r); j++)
- {
- put(tex, w, h, j, y+i*sign(r), c);
- }
- }
- }
- void draw(Color *tex, int w, int h)
- {
- random_noise(tex, w, h, 0xAAFFAA, 424242);
- random_noise(tex, w, h, 0xBCABAD, 242424);
- tape(tex, w, h, 0x2F3F30, -700, 100, 3);
- tape(tex, w, h, 0x2F3F30, -800, 42, 3);
- tape(tex, w, h, 0x8FEF30, 300, 100, -3);
- tape(tex, w, h, 0x2534FF, 500, 100, -3);
- tape(tex, w, h, 0x700023, 900, 100, -4);
- tape(tex, w, h, 0x561134, 950, 50, -5);
- tape(tex, w, h, 0x002300, 975, 25, -6);
- tape(tex, w, h, 0x424242, 1300, 50, 1);
- gradient(tex, w, h, 0x3732FF, 0x0);
- }
- int main()
- {
- Imlib_Image img;
- Imlib_Image scaled_img;
- Color *tex;
- srand(time(NULL));
- img = imlib_create_image(4*851, 4*315);
- imlib_context_set_image(img);
- draw(imlib_image_get_data(), 4*851, 4*315);
- scaled_img = imlib_create_cropped_scaled_image(
- 0, 0, 4*851, 4*315, 2*851, 2*315
- );
- imlib_free_image();
- imlib_context_set_image(scaled_img);
- imlib_save_image("out.png");
- imlib_free_image();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement