This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import random | |
from typing import NamedTuple, Literal, Callable | |
import pygame | |
from PIL import Image | |
import numpy as np | |
type Pos = tuple[int, int] | |
type Color = tuple[int, int, int] | str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import threading | |
import pygame | |
USER_EV1 = pygame.event.custom_type() | |
def pygame_loop(async_stopper): | |
pygame.init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass, field | |
import struct | |
from typing import BinaryIO | |
import zlib | |
import typing | |
""" | |
TFG1 Data files desired to be extracted (data directory) | |
https://gitea.xanax.lol/root/tfg-client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from PIL import Image, ImageDraw | |
COLORS = [ | |
(0x5e, 0x1f, 0x1d), (0xaa, 0x38, 0x37), (0x41, 0x2c, 0x33), (0xb3, 0x5a, 0x48), (0xfd, 0x63, 0x65), | |
(0xa0, 0xa5, 0xa9), (0x6c, 0x6e, 0x68), (0xb2, 0x00, 0x2a), (0xc0, 0x12, 0x26), (0xe1, 0x53, 0x85), | |
(0x93, 0x37, 0x4e), (0xe6, 0xa0, 0xc5), (0xe3, 0xb4, 0xa4), (0x00, 0x00, 0x00), (0x24, 0x27, 0x28), | |
(0x3f, 0x41, 0x41), (0x67, 0x1b, 0x56), (0x90, 0x00, 0x45), (0x34, 0x21, 0x50), (0x83, 0x58, 0x8b), | |
(0xa1, 0x89, 0xae), (0xd1, 0xb4, 0xc8), (0x87, 0x8e, 0x90), (0xa2, 0xa8, 0xab), (0xff, 0xff, 0xff), | |
(0x0a, 0x1a, 0x19), (0x23, 0x28, 0x1c), (0x34, 0x3b, 0x22), (0x61, 0x5c, 0x3d), (0x4f, 0x73, 0x6e), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def choose(text, options="Yn"): | |
""" | |
text: prompt to the user. | |
options: set of characters. one upper case may be | |
used to indicate a default value. | |
Examples: | |
answer = choose("Continue?") | |
# outputs: "Continue? (Y/n): " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import struct | |
import io | |
import json | |
def pack_varint(val): | |
total = b'' | |
if val < 0: | |
val = (1 << 32) + val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import textwrap | |
from collections import deque | |
import pygame | |
class TextBox: | |
NUM_LINES = 5 | |
TEXT_FONT = 'VT323-Regular.ttf' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def main(): | |
coord_and_names = np.genfromtxt('coordinates.txt', | |
dtype=[('lat', 'float'), ('lng', 'float'), ('name', 'U20')], | |
delimiter=',', skip_header=True) | |
# make lat and lng into 2D array | |
coords = np.column_stack((coord_and_names['lat'], coord_and_names['lng'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
from PIL import Image, ImageFilter | |
import numpy as np | |
def create_highlight_surf(surf): | |
# surf should be an image in RGBA format, where anything not transparent gets highlighted. | |
data = pygame.image.tostring(surf, 'RGBA') | |
image = Image.frombytes('RGBA', surf.get_size(), data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
strs = ["eat", "tea", "tan", "ate", "nat", "bat"] | |
d = {} | |
for s in strs: | |
c = frozenset(Counter(s).items()) | |
d.setdefault(c, []).append(s) |
NewerOlder