Skip to content

Instantly share code, notes, and snippets.

@amb
amb / test.py
Created October 9, 2022 21:33
Motion-diffusion to Blender
import numpy as np
import mathutils as mu
import bmesh
import bpy
ndir = "F:\ml\motion-diffusion-model\save\humanml_trans_enc_512\samples_humanml_trans_enc_512_000200000_seed10\\results.npy"
data = np.load(ndir, allow_pickle=True)
motions = data[()]['motion']
@amb
amb / upscale.bat
Created August 23, 2022 21:39
ESRGAN auto upscale
@echo %*
@echo off
magick %* input.jpg
F:\apps\esrgan\realesrgan-ncnn-vulkan.exe -i input.jpg -o esr_output.jpg -n realesrgan-x4plus
magick esr_output.jpg -scale 50%% esr\\%~n1.jpg
del input.jpg
del esr_output.jpg
@amb
amb / ms_abc_cams.py
Created June 17, 2022 20:18
Meshroom cameras, with images, into Blender
import bpy
from pathlib import Path
#selo = bpy.context.selected_objects
#assert len(selo) > 0, "Need to select the camera root"
#mroot = selo[0]
#assert mroot.name == "mvgRoot"
mroot = bpy.data.objects['mvgRoot']
image_folder = Path("D:\\art\\photo\\2022.6\\16")
@amb
amb / fft.nim
Created May 12, 2022 12:43
Simple Nim FFT
# OTFFT library
# http://wwwa.pikara.ne.jp/okojisan/otfft-en/optimization1.html
# This is +20-50% improvement
const thetaLutSize = 2048
const thetaLut = static:
var arr: array[thetaLutSize, Complex[float]]
let step = 2.0*PI/float(thetaLutSize)
for k, v in mpairs(arr):
v = complex(cos(step * float(k)), -sin(step * float(k)))
@amb
amb / wav.nim
Last active May 9, 2022 22:57
Simple Nim wav library
import streams, std/base64, std/strformat
type
WavFile* = object
data*: seq[uint8]
size*: int
freq*: int
bits*: int
channels*: int
https://news.ycombinator.com/item?id=26746537
godmode2019 3 hours ago [–]
I think everyone was a txt file on their computer filled with FFmpeg commands.
Care to share yours?
stevens37 0 minutes ago [–]
from mido import MidiFile
import mido
from collections import defaultdict
import time
import sys
filename = "Space Harrier.mid"
# filename = "Shovel.mid"
if len(sys.argv) == 2:
@amb
amb / gen_sin_table_fpga.py
Created March 17, 2021 12:19
Generate 7-bit sin table for FPGA/Verilog
import math
for i in range(16):
print(
f"@{(i*16):08x} "
+ " ".join(f"{int(-math.cos((j+i*16)*math.pi*2/255)*127.1+128):02x}" for j in range(16))
)
# for Xilinx Vivado FPGA purposes
# sin_table.mem
@amb
amb / l3.py
Created March 6, 2021 09:58
Ron Garret l.py Python 3 conversion
# l.py - A tiny interpreter for a lisp-like language with full
# lexical closures in Python
#
# Written by Ron Garret. Contributed to the public domain
# The global environment
# modification 2021 ambi, also public domain
globalenv = {}
"""
https://bottosson.github.io/posts/oklab/
Lab
L=lightness
a=green/red
b=blue/yellow
Lab to lightness, chroma, hue (LCh)
C=sqrt(a**2+b**2)