This file contains hidden or 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 | |
try: | |
# If available, import numba to enable compiling the functions for extra speed | |
from numba import njit, boolean | |
except ImportError: | |
print("Numba compilation not available - falling back to pure Python.") | |
def njit(func, *args, **kwargs): |
This file contains hidden or 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 fullcontrol.visualize.tube_mesh import FlowTubeMesh, go, np | |
# Display parameters | |
COLOURS = '#666' # 'black' / '#C0FFEE' / None | |
SHOW = True # if False, saves animation frames instead | |
# Geometry parameters | |
np.random.seed(sum(b'gcode')) | |
SEGMENTS_PER_CURVE = 31 | |
BASE_THICKNESS = 0.6 # 0.2 |
This file contains hidden or 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
# relevant types | |
from collections.abc import Sequence | |
from numbers import Real | |
import pathlib | |
# functionality | |
from itertools import chain, pairwise | |
import plotly.graph_objects as go | |
import numpy as np | |
This file contains hidden or 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
''' Written in response to u/thisisjusttofindajob's Reddit post | |
https://www.reddit.com/r/learnpython/comments/xnq9bv/how_to_render_objects_randomly_in_time/ | |
about random timings with an average frequency. | |
''' | |
from time import perf_counter | |
import random |
This file contains hidden or 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
''' | |
Cleans up a drawing, and creates grey, blue, and red variants. | |
Blue and red are saved with a transparent background. | |
Grey is saved as single channel. | |
Author: ES-Alexander | |
License: MIT (a.k.a. free use, but not my problem if it doesn't work for you) | |
Created in response to: | |
https://www.reddit.com/r/opencv/comments/wmyuyh/question_remove_paper_background_from_sketches/ |
This file contains hidden or 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
''' Mandelbulb.py | |
Adapted from | |
https://github.com/AstroKriel/Mandelbulb/blob/main/python/main.py | |
EXAMPLE OUTPUT: | |
https://youtube.com/shorts/f8ek83Z9SFo | |
Original author: AstroKriel | |
- Mandelbulb raymarcher |
This file contains hidden or 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
#!/usr/bin/env python3 | |
from pymavlink import mavutil, mavlink | |
class CourseAverager: | |
MSG_TYPE = 'GLOBAL_POSITION_INT' | |
def __init__(self, mavlink_connection, request_rate=1, decay_rate=0.95, initial_course=(0, 0)): | |
self.master = mavlink_connection | |
self.request_message(request_rate) |
This file contains hidden or 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.spatial import KDTree | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# SETUP | |
points = np.array([[1,2],[5,9],[-8,-2],[5,-5],[-4,-1]]) | |
xmin, xmax, ymin, ymax = -10, 10, -10, 10 | |
x_resolution = y_resolution = 300 | |
pixel_size = max((xmax-xmin)/x_resolution, (ymax-ymin)/y_resolution) | |
radius = 3 |
This file contains hidden or 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 pathlib import Path | |
from scipy.io import wavfile | |
from scipy.fft import fft, fftfreq | |
import matplotlib.pyplot as plt | |
import numpy as np | |
path = Path('.') # path to whale song files | |
files = list(path.glob('*.wav')) |
This file contains hidden or 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
#!/usr/bin/env python3 | |
from itertools import combinations_with_replacement | |
from typing import List, Tuple, Generator | |
VALID_E_SERIES = (3, 6, 12, 24, 48, 96, 192) | |
def E(m: int) -> Generator[float, None, None]: | |
""" A generator of IEEE E-series values. |
NewerOlder