Skip to content

Instantly share code, notes, and snippets.

@salt-die
salt-die / terminal_raycaster2d.py
Last active May 30, 2020 21:23
2d raycaster that runs in your terminal!
from collections import defaultdict
import os
import time
import numpy as np
from pynput import keyboard
from pynput.keyboard import Key
TERMX, TERMY = os.get_terminal_size()
"""
A simple Mandlebrot explorer in Kivy! Drag mouse to translate, multitouch-zoom to zoom, and scroll to increase/decrease number of iterations.
"""
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.effectwidget import AdvancedEffectBase
from kivy.lang import Builder
from kivy.vector import Vector
SHADER = """
@salt-die
salt-die / prelude_2.py
Last active April 25, 2020 18:30
various songs from numpy arrays
from itertools import chain, product, repeat, starmap
from more_itertools import interleave
from functools import lru_cache
import numpy as np
import sounddevice as sd
SAMPLE_RATE = 44100
sd.default.samplerate = SAMPLE_RATE
@salt-die
salt-die / meatballs.py
Last active January 2, 2022 23:20
poke metaballs with this metaball shader written for kivy
"""Scroll with the mouse to enable auto-poking."""
from random import random
from kivy.app import App
from kivy.clock import Clock
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.effectwidget import AdvancedEffectBase
@salt-die
salt-die / terminal_clock.py
Created April 2, 2020 16:16
an analog clock for your terminal!
"""
An analog clock for your terminal!
The grid and base arrays in Clock are dtype=int, but this might make more sense if we just
use character arrays instead -- we may update this soon.
"""
import os
import time
import numpy as np
"""
Move bulge by dragging the mouse. Scale with multitouch.
"""
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.effectwidget import AdvancedEffectBase
from kivy.lang import Builder
EFFECT = AdvancedEffectBase()
EFFECT.glsl = """
@salt-die
salt-die / kivy_custom_console.py
Last active June 18, 2020 13:19
python console in kivy
"""TODO: ctrl + left/right (move past word), ctrl + backspace/del (del word), shift + del (del line)
...: Smart movement through leading indentation.
...: Except for first line, up/down to work normally on multi-line console input.
"""
from code import InteractiveConsole
from collections import deque
from dataclasses import dataclass
from io import StringIO
from itertools import chain, takewhile
from more_itertools import ilen
@salt-die
salt-die / dispatcher.py
Last active May 13, 2020 10:31
observers and dispatchers
from more_itertools import always_iterable
from sys import modules
from weakref import WeakKeyDictionary
from types import FunctionType
class WeakDefaultDict(WeakKeyDictionary):
def __init__(self, default_factory=lambda: None, **kwargs):
self._default_factory = default_factory
super().__init__(**kwargs)
@salt-die
salt-die / ast_prettiest.py
Last active July 20, 2020 11:01
ast pretty printer!
import ast
import re
NAME_RE = re.compile('[.]([A-Za-z]+)[ ]')
DEFAULT = 3
LINE_CHRS = '├─', '│ ', '╰─', ' '
def flatten(iterable):
for item in iterable:
if isinstance(item, list):
@salt-die
salt-die / wobblywidget.py
Last active June 21, 2020 19:42
Make any widget wobble with wobbly widget!
"""For this to work, WobblyEffect should be parent to WobblyScatter.
"""
from kivy.clock import Clock
from kivy.uix.effectwidget import AdvancedEffectBase, EffectWidget
from kivy.uix.scatter import Scatter
from itertools import product
FRICTION = .95
K = 8