Skip to content

Instantly share code, notes, and snippets.

View marmakoide's full-sized avatar

Devert Alexandre marmakoide

View GitHub Profile
@marmakoide
marmakoide / antialiased_disk_mask.py
Created July 18, 2022 15:24
Generates a very accurate antialiased disk, without super sampling a very large bitmap. Works correctly only for even values of N.
import numpy
import scipy.integrate as integrate
def get_disk_mask(N):
def F(x):
return (1 - x ** 2) ** .5
# Build a quarter
M = N // 2
quarter = numpy.zeros((M, M))
@marmakoide
marmakoide / voxelize.py
Last active February 21, 2022 18:24
Voxelize a watertight mesh as a Numpy NxNxN array. All the mesh interior is filled, no spatial acceleration structures, as vectorized as I could make it. Works only if all the triangles are within the cube 0x0x0 => NxNxN
def get_z_line_triangles_intersections_generator(triangles):
# Precompute everything that is independent from the ray origin
Z = numpy.array([0., 0., 1.])
tri_AB = triangles[:, 1] - triangles[:, 0]
tri_AC = triangles[:, 2] - triangles[:, 0]
tri_H = numpy.cross(Z, tri_AC)
tri_a = numpy.sum(tri_AB * tri_H, axis = 1) # dot product along axis 0
# Remove all triangles on a plane parallel to the ray
@marmakoide
marmakoide / zyx-quaternion.py
Created February 10, 2022 08:04
Quaternion from ZYX intrisic Euler angles (Z rot, then local -Y rot, then local X rot)
import numpy
def zyx_to_quaternion(z_angle, y_angle, x_angle):
cos_x, sin_x = numpy.cos(x_angle / 2), numpy.sin(x_angle / 2)
cos_y, sin_y = numpy.cos(y_angle / 2), numpy.sin(y_angle / 2)
cos_z, sin_z = numpy.cos(z_angle / 2), numpy.sin(z_angle / 2)
return numpy.array([
cos_x * cos_y * cos_z - sin_x * sin_y * sin_z,
@marmakoide
marmakoide / base16_rgb_map.py
Created March 17, 2021 07:12
The base16 color scheme as a Python map associating a color name to a RGB triplet
base16_rgb_map = {
"base00" : (0x15, 0x15, 0x15), # Default Background
"base01" : (0x20, 0x20, 0x20), # Lighter Background (Used for status bars, line number and folding marks)
"base02" : (0x30, 0x30, 0x30), # Selection Background
"base03" : (0x50, 0x50, 0x50), # Comments, Invisibles, Line Highlighting
"base04" : (0xb0, 0xb0, 0xb0), # Dark Foreground (Used for status bars)
"base05" : (0xd0, 0xd0, 0xd0), # Default Foreground, Caret, Delimiters, Operators
"base06" : (0xe0, 0xe0, 0xe0), # Light Foreground (Not often used)
"base07" : (0xf5, 0xf5, 0xf5), # Light Background (Not often used)
"base08" : (0xac, 0x41, 0x42), # Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted
@marmakoide
marmakoide / nord_rgb_map.py
Last active March 17, 2021 06:46
The nord color scheme as a Python map associating a color name to a RGB triplet
nord_rgb_map = {
"nord0" : (0x2e, 0x34, 0x40), # dark 1 (darkest)
"nord1" : (0x3b, 0x42, 0x52), # dark 2
"nord2" : (0x43, 0x4c, 0x5e), # dark 3
"nord3" : (0x4c, 0x56, 0x6a), # dark 4
"nord4" : (0xd8, 0xde, 0xe9), # bright 1
"nord5" : (0xe5, 0xe9, 0xf0), # bright 2
"nord6" : (0xec, 0xef, 0xf4), # bright 3 (brightest)
"nord7" : (0x8f, 0xbc, 0xbb), # blue 1 (closest to green)
"nord8" : (0x88, 0xc0, 0xd0), # blue 2
@marmakoide
marmakoide / solarized_rgb_map.py
Last active March 17, 2021 06:46
The solarized color scheme as a Python map associating a color name to a RGB triplet
solarized_rgb_map = {
"base03" : (0x00, 0x2b, 0x36),
"base02" : (0x07, 0x36, 0x42),
"base01" : (0x58, 0x6e, 0x75),
"base00" : (0x65, 0x7b, 0x83),
"base0" : (0x83, 0x94, 0x96),
"base1" : (0x93, 0xa1, 0xa1),
"base2" : (0xee, 0xe8, 0xd5),
"base3" : (0xfd, 0xf6, 0xe3),
"yellow" : (0xb5, 0x89, 0x00),
@marmakoide
marmakoide / network.sh
Last active January 4, 2021 11:02
Shell script that generates a string describing network connection status, to use with dwmblocks and Font Awesome
#!/bin/sh
ETH_IT=enp3s0
WLAN_IT=wlan0
is_eth_used=$(cat /sys/class/net/${ETH_IT}/carrier)
is_wlan_used=$(cat /sys/class/net/${WLAN_IT}/carrier)
if [ "$is_eth_used" -eq 1 ]; then # wired network is carrying
icon="" #uF6FF
@marmakoide
marmakoide / power.sh
Last active January 1, 2021 17:27
Shell script that generates a string describing power supply status, to use with dwmblocks and Font Awesome
#!/bin/sh
is_ac_powered=$(cat /sys/class/power_supply/AC0/online)
batt_capacity=$(cat /sys/class/power_supply/BAT0/capacity)
if [ "$is_ac_powered" -eq 1 ]; then
icon="" #uF1E6
else
if [ "$batt_capacity" -gt 80 ]; then
icon="" #uF240
@marmakoide
marmakoide / memory.sh
Last active January 1, 2021 12:43
Shell script that generates a string describing RAM usage, to use with dwmblocks and Font Awesome
#!/bin/sh
icon=""
mem_str=$(free -h | awk '/^Mem/ { print $3 "/" $2 }' | sed s/i//g)
echo $icon $mem_str
@marmakoide
marmakoide / README.md
Last active December 11, 2020 14:05
Circle intersection with lines

Circle intersection with (many) (oriented) lines with optimal runtime complexity

This code sample demonstrates how to compute the intersection with a circle of radius 1, and many oriented lines. Technically, oriented lines are equivalent to half-planes.

The function circle_line_intersection is doing all the work. The lines are specified as the 3 parameters of a 2d line equation, ax + by + c = 0. The function returns a list of pairs of points : the extremities of each arcs in counterclock wise order.