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 hexagon(radius: float, spacing: float) -> np.ndarray: | |
"""take a circle radius and point spacing and return an | |
[N, 2] shaped array containing the hexagonal-packed points | |
""" | |
n_points = int(np.ceil(radius / spacing)) * 2 | |
basis = spacing * np.array([[1, 0], [np.cos(np.pi / 3), np.sin(np.pi / 3)]]) | |
x, y = np.mgrid[ | |
-n_points : n_points : (2 * n_points + 1) * 1j, |
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 | |
from dataclasses import dataclass, field | |
from collections import defaultdict | |
from typing import Literal, Tuple, Callable, TypeVar, Optional | |
K, V = TypeVar("K"), TypeVar("V") | |
def merge(A: dict[K, V], B: dict[K, V], f: Callable[[V, V], V]) -> dict[K, V]: | |
"""Function to merge two dictionaries, A and B. | |
If any keys are in both, apply f(a, b) to the values and put the |
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 scipy.optimize import curve_fit | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def gaussian(positions, x, y, sigma, amplitude, background): | |
return (amplitude * np.exp(-((positions[0] - x)**2 + (positions[1] - y)**2)/(2 * sigma**2)) + background) | |
def camera_coords(width, height): | |
return np.mgrid[0:(width-1):width*1j, 0:(height-1):height*1j] |
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 | |
import matplotlib.pyplot as plt | |
xb = (400, 600) | |
first_order_yb = (700, 970) | |
zero_order_yb = (320, 600) | |
grey_values = range(256) | |
first_order_sums = [np.load(f"./LUTOrders/LUTOrders_{i}.npy")[xb[0]:xb[1], first_order_yb[0]:first_order_yb[1]].sum() for i in grey_values] | |
zero_order_sums = [np.load(f"./LUTOrders/LUTOrders_{i}.npy")[xb[0]:xb[1], zero_order_yb[0]:zero_order_yb[1]].sum() for i in grey_values] |
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 | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
resolution = 400 | |
exponent = 2 | |
iterations = 400 | |
def julia(exponent, constant, size, iterations): |
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
# SNAKES GAME | |
# Use ARROW KEYS to play, SPACE BAR for pausing/resuming and Esc Key for exiting | |
import curses | |
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN | |
from random import randint | |
curses.initscr() | |
win = curses.newwin(20, 60, 0, 0) |