Skip to content

Instantly share code, notes, and snippets.

View ES-Alexander's full-sized avatar

ES-Alexander

View GitHub Profile
@ES-Alexander
ES-Alexander / random_drops.py
Created September 25, 2022 23:10
Random events with an average frequency
''' 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
@ES-Alexander
ES-Alexander / tube_mesh.py
Last active June 9, 2023 10:04
Generates a tubular triangle mesh that follows a path of points.
# 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
@ES-Alexander
ES-Alexander / projective_perspective.py
Last active March 24, 2024 11:45
Projective Perspective
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
@ES-Alexander
ES-Alexander / point_in_polygon.py
Last active March 30, 2024 14:29
Some tools to (reasonably efficiently) fill shapes with infill patterns, as is common in 3D printing
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):