Guest User

Untitled

a guest
Jul 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function averageColor(image img, int start_x, int start_y, int width, int height) {
  2.     int r, g, b;
  3.     for (int x = start_x; x < start_x + width; ++x) {
  4.         for (int y = start_y; y < start_y + height; ++y) {
  5.             r, g, b += img.at(x, y);
  6.         }
  7.     }
  8.     int num_tiles = width * height;
  9.     r, g, b = (x / num_tiles for x in r, g, b)
  10.     return pixel(r, g, b);
  11. }
  12. function shrink(image largeImage, int x_tiles, int y_tiles) {
  13.     int tile_width = int(largeImage.width / x_tiles);
  14.     int tile_height = int(largeImage.height / y_tiles);
  15.     image smallImage(x_tiles, y_tiles);
  16.     for (int x = 0, sx = 0; x < largeImage.size; x += tile_width, ++sx) {
  17.         for (int y = 0, sy = 0; y < largeImage.size; y += tile_height, ++sy) {
  18.             pixel p = averageColor(largeImage, x, y, tile_width, tile_height);
  19.             smallImage.at(sx, sy) = p;
  20.         }
  21.     }
  22.     return smallImage;
  23. }
Add Comment
Please, Sign In to add comment