Skip to content

Instantly share code, notes, and snippets.

View phuang1024's full-sized avatar

Patrick Huang phuang1024

  • California, USA
  • 00:44 (UTC -07:00)
View GitHub Profile
@phuang1024
phuang1024 / exp.py
Last active August 27, 2025 20:30
Visualization of taylor series definition of exp(j*theta)
import math
import cv2
import numpy as np
UNITS = np.array([
[1, 0],
[0, 1],
[-1, 0],
[0, -1],
@phuang1024
phuang1024 / TorchMotionBlur.py
Created April 25, 2025 19:48
Motion blur in 3D rendering with PyTorch autograd
import random
import cv2
import numpy as np
import torch
CAM_POS = torch.tensor([-5, 0, 2], dtype=torch.float)
FOCAL_LEN = 1
# Facing +X
@phuang1024
phuang1024 / PianoTyping.py
Created December 13, 2023 06:29
Type with a piano keyboard.
import json
import mido
import pyautogui
inputs = mido.get_input_names()
for i, inp in enumerate(inputs):
print(i, inp)
choice = int(input("Choose input: "))
@phuang1024
phuang1024 / malkus.py
Created November 9, 2023 19:20
Simulate the Malkus Waterwheel (chaotic behavior).
import argparse
import math
import time
import cv2
import numpy as np
def get_top_index(pos, n):
top_index = math.floor(n * (3/4 - pos / (2*np.pi)) + 0.5) % n
@phuang1024
phuang1024 / gravity.py
Created November 9, 2023 16:08
Gravity simulator (incl. three body problem).
import argparse
import time
import cv2
import numpy as np
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-n", type=int, default=3)
@phuang1024
phuang1024 / termtext.py
Created October 28, 2023 03:15
Create large ascii text.
#!/usr/bin/env python
import argparse
import os
os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "1"
import cv2
import numpy as np
import pygame
@phuang1024
phuang1024 / pid.py
Last active August 1, 2023 16:22
Simulate inverted pendulum PID control.
"""
Simulate inverted pendulum PID controller.
Run the python file to run; requires pygame.
Use left/right to apply angular impulse, and up/down to apply linear impulse.
"""
import random
import time
from dataclasses import dataclass
from math import sin, cos
@phuang1024
phuang1024 / tuning.py
Created July 25, 2023 02:17
Generate stretch tuning frequencies.
STRETCH = (
-20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
-8, -7, -6, -6, -5, -5, -4, -4, -4, -4, -4, -3,
-3, -3, -3, -3, -3, -3, -3, -3, -3, -2.5, -2.5, -2,
-2, -2, -2, -2, -2, -2, -1.5, -1, -1, -1, -1, -1,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2,
2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6,
6, 7, 8, 9, 10, 11, 12, 13, 15, 17, 19, 21,
23, 25, 27, 30
)
"""
Discord bot that performs semantic search.
Storage format in data directory:
For each server, there is one pytorch file (server_id.pt) with two keys:
- "embeddings": list of message embeddings
- "messages": list of message IDs, corresponding to the embeddings
"""
import argparse
import argparse
import time
import mido
import pyautogui
class Player:
keys = list("awsedftgyhuj")