Skip to content

Instantly share code, notes, and snippets.

View maxastyler's full-sized avatar
🥜
I hate peanuts

Max Tyler maxastyler

🥜
I hate peanuts
View GitHub Profile
@maxastyler
maxastyler / hexagonal_packed_circle.py
Created February 15, 2022 11:03
Function to generate hexagonally packed points within a given radius
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,
@maxastyler
maxastyler / solving-wordle.py
Created January 31, 2022 17:44
Code from wordle blog post
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
@maxastyler
maxastyler / centering.py
Created March 23, 2021 14:08
Centering Code
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]
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]
@maxastyler
maxastyler / julia.py
Last active July 10, 2018 16:27
Matplotlib julia animation
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):
@maxastyler
maxastyler / snake.py
Last active December 7, 2018 13:03 — forked from sanchitgangwar/snake.py
Snakes Game using Python
# 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)