├── requirements.txt ├── explainer.png ├── season22.png ├── LICENSE ├── README.md ├── .gitignore └── image_viewer.py /requirements.txt: -------------------------------------------------------------------------------- 1 | blaseball-mike 2 | Pillow 3 | requests -------------------------------------------------------------------------------- /explainer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dlareau/paint-by-blaseball/main/explainer.png -------------------------------------------------------------------------------- /season22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dlareau/paint-by-blaseball/main/season22.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Dillon Lareau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # paint-by-blaseball 2 | 3 | ## What is this? 4 | Paint-by-Blaseball is an entry into the [SIBR cursed viewer contest](https://cursed.sibr.dev). It is a way of fitting a whole season of blaseball (every single update from every single game) into a single image viewable all at once on a large enough monitor. 5 | 6 | ## Please show me an example. 7 | Okay here, this is all of season 22: 8 | ![An example rendered season](/season22.png) 9 | 10 | ## What am I looking at? 11 | The image is made up of "cells" each representing a single game update. Every game from the season is represented as a column of cells with the game progressing from the top of the column to the bottom of the column in order. Each cell has enough information to reasonably re-construct the general state as it would have been shown on www.blaseball.com (the only loss of data is just having the feed type of an update instead of the exact game update text). 12 | 13 | Here is a close up of a cell and what each part of it means: 14 | ![An image explaining a single update tile](/explainer.png) 15 | 16 | ## What is the most cursed part of this? 17 | I'm glad you asked, when needing to show a player for some part of the cell, they are represented by taking the first six digits of their playerID as a hex code. This is in fact unique across all players. 18 | 19 | ## Why does the image look red? 20 | To better distinguish individual cells when zoomed in, each cell has a red border around it. 21 | 22 | ## Why red as a border color? 23 | 🩸🩸🩸 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | # Data files 132 | *.json -------------------------------------------------------------------------------- /image_viewer.py: -------------------------------------------------------------------------------- 1 | from PIL import Image, ImageColor 2 | import json 3 | from blaseball_mike import chronicler 4 | import requests 5 | from os import path 6 | 7 | COLORS = [ 8 | ImageColor.getrgb("#000000"), 9 | ImageColor.getrgb("#996633"), 10 | ImageColor.getrgb("#FF0000"), 11 | ImageColor.getrgb("#FF9900"), 12 | ImageColor.getrgb("#FFFF00"), 13 | ImageColor.getrgb("#00FF00"), 14 | ImageColor.getrgb("#0000FF"), 15 | ImageColor.getrgb("#FF00FF"), 16 | ImageColor.getrgb("#CCCCCC"), 17 | ImageColor.getrgb("#FFFFFF"), 18 | ] 19 | 20 | MOD_COLORS = { 21 | "": ImageColor.getrgb("#000000"), 22 | "COFFEE_RALLY": ImageColor.getrgb("#44c97c"), 23 | "MAGNIFY_2X": ImageColor.getrgb("#041a29"), 24 | "SUBTRACTOR": ImageColor.getrgb("#420000"), 25 | "TIRED": ImageColor.getrgb("#511c00"), 26 | "WIRED": ImageColor.getrgb("#ffffff"), 27 | "BLASERUNNING": ImageColor.getrgb("#570026"), 28 | "TRIPLE_THREAT": ImageColor.getrgb("#5dbcd2"), 29 | "UNDERHANDED": ImageColor.getrgb("#362236"), 30 | } 31 | 32 | DIVIDER_COLOR = (255, 0, 0) 33 | BOOLEAN_COLOR = (255, 255, 255) 34 | CELL_WIDTH = 6 35 | CELL_HEIGHT = 8 36 | 37 | SEASON = 22 # 1-indexed 38 | 39 | max_play_counts = [] 40 | 41 | 42 | def write_square(x, y, packet): 43 | # Home team color/score 44 | img.putpixel((x, y), ImageColor.getrgb(team_colors[packet["homeTeam"]])) 45 | home_score = packet["homeScore"] 46 | if(home_score < 0): 47 | img.putpixel((x+1, y), BOOLEAN_COLOR) 48 | home_score *= -1 49 | img.putpixel((x+2, y), COLORS[int((home_score / 10) % 10)]) 50 | img.putpixel((x+3, y), COLORS[int((home_score) % 10)]) 51 | img.putpixel((x+4, y), COLORS[int((home_score * 10) % 10)]) 52 | 53 | # Away team color/score 54 | img.putpixel((x, y+1), ImageColor.getrgb(team_colors[packet["awayTeam"]])) 55 | away_score = packet["awayScore"] 56 | if(away_score < 0): 57 | img.putpixel((x+1, y+1), BOOLEAN_COLOR) 58 | away_score *= -1 59 | img.putpixel((x+2, y+1), COLORS[int((away_score / 10) % 10)]) 60 | img.putpixel((x+3, y+1), COLORS[int((away_score) % 10)]) 61 | img.putpixel((x+4, y+1), COLORS[int((away_score * 10) % 10)]) 62 | 63 | # Inning 64 | b_inning = [bool(int(i)) for i in list('{0:05b}'.format(packet["inning"] + 1))] 65 | for i in range(5): 66 | if(b_inning[i]): 67 | img.putpixel((x, y+2+i), BOOLEAN_COLOR) 68 | if(not packet["topOfInning"]): 69 | img.putpixel((x, y+7), BOOLEAN_COLOR) 70 | 71 | # packet feed type 72 | b_feed = [bool(int(i)) for i in list('{0:08b}'.format(packet["type"]))] 73 | for i in range(8): 74 | if(b_feed[i]): 75 | img.putpixel((x+5, y+i), BOOLEAN_COLOR) 76 | 77 | # Balls / Strikes / Outs 78 | for i in range(4): 79 | if(packet["atBatBalls"] > i): 80 | img.putpixel((x+(4-i), y+2), BOOLEAN_COLOR) 81 | if(packet["atBatStrikes"] > i): 82 | img.putpixel((x+(4-i), y+3), BOOLEAN_COLOR) 83 | if(packet["halfInningOuts"] > 0): 84 | img.putpixel((x+(4-i), y+4), BOOLEAN_COLOR) 85 | 86 | # Bases / Mods 87 | for i in range(len(packet["basesOccupied"])): 88 | base = packet["basesOccupied"][i] 89 | img.putpixel((x+4-base, y+5), ImageColor.getrgb("#" + packet["baseRunners"][i][0:6])) 90 | # if(MOD_COLORS[packet["baseRunnerMods"][i]] != (0, 0, 0)): 91 | # print("runner", x+4-base, y+6, MOD_COLORS[packet["baseRunnerMods"][i]]) 92 | img.putpixel((x+4-base, y+6), MOD_COLORS[packet["baseRunnerMods"][i]]) 93 | 94 | # Pitcher/Batter/Mods 95 | if(packet["topOfInning"]): 96 | pitcher = packet["homePitcher"] 97 | pitcher_mod = packet["homePitcherMod"] 98 | batter = packet["awayBatter"] 99 | batter_mod = packet["awayBatterMod"] 100 | else: 101 | pitcher = packet["awayPitcher"] 102 | pitcher_mod = packet["awayPitcherMod"] 103 | batter = packet["homeBatter"] 104 | batter_mod = packet["homeBatterMod"] 105 | 106 | if(pitcher is not None): 107 | img.putpixel((x+1, y+7), ImageColor.getrgb("#" + pitcher[0:6])) 108 | img.putpixel((x+2, y+7), MOD_COLORS[pitcher_mod]) 109 | if(batter is not None): 110 | img.putpixel((x+3, y+7), ImageColor.getrgb("#" + batter[0:6])) 111 | img.putpixel((x+4, y+7), MOD_COLORS[batter_mod]) 112 | 113 | for i in range(CELL_HEIGHT + 1): 114 | img.putpixel((x+CELL_WIDTH, y+i), DIVIDER_COLOR) 115 | 116 | for i in range(CELL_WIDTH + 1): 117 | img.putpixel((x+i, y+CELL_HEIGHT), DIVIDER_COLOR) 118 | 119 | 120 | # get team colors: 121 | r = requests.get(f"https://api.sibr.dev/corsmechanics/time/season/{SEASON-1}/day/1") 122 | start_time = r.json()[0]["startTime"] 123 | teams = list(chronicler.v2.get_entities("team", at=start_time)) 124 | team_colors = {} 125 | for team in teams: 126 | team_colors[team["entityId"]] = team["data"]["mainColor"] 127 | 128 | packets = {} 129 | 130 | if(path.exists(f"data_{SEASON}.json")): 131 | with open(f"data_{SEASON}.json", "r") as f: 132 | packets = json.load(f) 133 | 134 | else: 135 | print("No packets file found for the selected season, generating...") 136 | print("This may take a few minutes.") 137 | games = chronicler.get_games(SEASON) 138 | print(f"There are {len(games)} games to fetch") 139 | i = 0 140 | for game in games: 141 | if(i % 100 == 0): 142 | print(f"Fetched {i} games.") 143 | game_id = game["gameId"] 144 | r = requests.get(f'https://api.sibr.dev/eventually/sachet/packets?id={game_id}') 145 | packets[game_id] = r.json() 146 | i += 1 147 | 148 | print("Fetched all games, saving to file.") 149 | with open(f"data_{SEASON}.json", "w") as f: 150 | json.dump(packets, f) 151 | 152 | for game_id in packets: 153 | max_play_counts.append(len(packets[game_id])) 154 | 155 | # Create the image 156 | width = len(packets)*(CELL_WIDTH + 1) 157 | height = max(max_play_counts)*(CELL_HEIGHT + 1)+50 158 | img = Image.new(mode="RGB", size=(width, height)) 159 | 160 | x = 0 161 | for game_id in packets: 162 | y = 0 163 | for packet in packets[game_id]: 164 | if(not packet["_sachet_packet_incomplete"]): 165 | write_square(x, y, packet) 166 | y += CELL_HEIGHT + 1 167 | x += CELL_WIDTH + 1 168 | 169 | img.show() 170 | --------------------------------------------------------------------------------