Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function averageColor(image img, int start_x, int start_y, int width, int height) {
- int r, g, b;
- for (int x = start_x; x < start_x + width; ++x) {
- for (int y = start_y; y < start_y + height; ++y) {
- r, g, b += img.at(x, y);
- }
- }
- int num_tiles = width * height;
- r, g, b = (x / num_tiles for x in r, g, b)
- return pixel(r, g, b);
- }
- function shrink(image largeImage, int x_tiles, int y_tiles) {
- int tile_width = int(largeImage.width / x_tiles);
- int tile_height = int(largeImage.height / y_tiles);
- image smallImage(x_tiles, y_tiles);
- for (int x = 0, sx = 0; x < largeImage.size; x += tile_width, ++sx) {
- for (int y = 0, sy = 0; y < largeImage.size; y += tile_height, ++sy) {
- pixel p = averageColor(largeImage, x, y, tile_width, tile_height);
- smallImage.at(sx, sy) = p;
- }
- }
- return smallImage;
- }
Add Comment
Please, Sign In to add comment