|
| 1 | +# Copyright (C) 2019 - UMons |
| 2 | +# |
| 3 | +# This library is free software; you can redistribute it and/or |
| 4 | +# modify it under the terms of the GNU Lesser General Public |
| 5 | +# License as published by the Free Software Foundation; either |
| 6 | +# version 2.1 of the License, or (at your option) any later version. |
| 7 | +# |
| 8 | +# This library is distributed in the hope that it will be useful, |
| 9 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | +# Lesser General Public License for more details. |
| 12 | +# |
| 13 | +# You should have received a copy of the GNU Lesser General Public |
| 14 | +# License along with this library; if not, write to the Free Software |
| 15 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 | + |
| 17 | +import argparse |
| 18 | +from simulation import board |
| 19 | +import pygame |
| 20 | +from pygame.locals import QUIT |
| 21 | + |
| 22 | + |
| 23 | +def main(): |
| 24 | + ap = argparse.ArgumentParser() |
| 25 | + ap.add_argument("--first", required=True, help="first board file") |
| 26 | + ap.add_argument("--second", required=True, help="second board file") |
| 27 | + ap.add_argument("-s", "--scale", type=float, default=10, help="scale display (default: x10") |
| 28 | + ap.add_argument("-o", "--output", type=str, help="give a name to save the jpeg file") |
| 29 | + args = ap.parse_args() |
| 30 | + |
| 31 | + board_1 = board.Board(0,0) |
| 32 | + board_1.load(args.first) |
| 33 | + |
| 34 | + board_2 = board.Board(0,0) |
| 35 | + board_2.load(args.second) |
| 36 | + |
| 37 | + board_comp = board_1.compare(board_2) |
| 38 | + |
| 39 | + if board_comp is None: |
| 40 | + return |
| 41 | + |
| 42 | + pygame.init() |
| 43 | + |
| 44 | + width = int(board_1.width * args.scale) |
| 45 | + height = int(board_1.height * args.scale) |
| 46 | + window = pygame.display.set_mode((width, height)) |
| 47 | + |
| 48 | + game_surface = pygame.Surface((board_1.width, board_1.height)) |
| 49 | + pixel_array = pygame.PixelArray(game_surface) |
| 50 | + for x in range(board_1.width): |
| 51 | + for y in range(board_1.height): |
| 52 | + pixel_array[x,y] = (0, 0, 0) |
| 53 | + |
| 54 | + val = max(-255, min(board_comp.get_blob(x, y), 255)) |
| 55 | + if val < 0: |
| 56 | + val = - val # int(-val/2) + 125 |
| 57 | + pixel_array[x, y] = (val/4, val/4, val) |
| 58 | + elif val > 0: |
| 59 | + val = val # int(val/2) + 125 |
| 60 | + pixel_array[x, y] = (val, val/4, val/4) |
| 61 | + else: |
| 62 | + if not board_comp.is_touched(x, y): |
| 63 | + if board_1.is_touched(x, y): |
| 64 | + pixel_array[x, y] = (75, 75, 125) |
| 65 | + else: |
| 66 | + pixel_array[x, y] = (125, 75, 75) |
| 67 | + |
| 68 | + if board_comp.has_food(x, y): |
| 69 | + pixel_array[x, y] = (0, board_comp.foods[x, y], 0) |
| 70 | + |
| 71 | + del pixel_array |
| 72 | + |
| 73 | + game_window = pygame.transform.scale(game_surface, (width, height)) |
| 74 | + |
| 75 | + window.blit(game_window, (0, 0)) |
| 76 | + pygame.display.flip() |
| 77 | + |
| 78 | + ended = False |
| 79 | + while not ended: |
| 80 | + pygame.time.wait(10) |
| 81 | + for event in pygame.event.get(): |
| 82 | + if event.type == QUIT: |
| 83 | + ended = True |
| 84 | + |
| 85 | + if args.output is not None: |
| 86 | + pygame.image.save(window, args.output) |
| 87 | + |
| 88 | + |
| 89 | +if __name__ == "__main__": |
| 90 | + main() |
0 commit comments