Skip to content

Instantly share code, notes, and snippets.

@PM2Ring
PM2Ring / tensegrity.py
Created August 30, 2024 15:17
Tensegrity twisted prism in 3D, using SageMath
# Tensegrity twisted prism. PM 2Ring 2024.08.31
def ball(radius, **kwargs):
var('u,v')
kw = dict(plot_points=40) | kwargs
return spherical_plot3d(radius, (u, 0, 2*pi), (v, 0, pi), **kw)
def axis_matrix(W):
a, b, c = W
if abs(c) == 1:
@PM2Ring
PM2Ring / map320.txt
Last active August 1, 2024 18:46
Plain equirectangular world map
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQE
CAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKC
gr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo
KCgoKCgoKCgoKCgoKCgoKCgr/wAARCACgAUADASIAAhEBAxEB/8QAHAABAAIDAQEBAAAAA
AAAAAAAAAUGAgMEAQcJ/8QASRAAAgEDAwIFAgIFCAYIBwAAAQIDBAURABIhBjEHEyJBURR
hMnEVQnKBkSMzNFJigqGxCBckJbLCQ1NVlKLR0/Fzg5LB0uHw/8QAGwEAAgMBAQEAAAAAA
AAAAAAAAAUDBAYBAgf/xAA6EQABAwIEAwUGBAUFAQAAAAABAAIDBBEFITFBElGBYXGRobE
GEyLB0fAVI0LxFjJSguEkM0NTwqL/2gAMAwEAAhEDEQA/AP2M0001uF83TTTTQhNNNNCE0
1xXg9UUttN9orfSx284WOtrpiqu+ccAc4+DjB+fmuRXzr2qnpTcIIaJklHnJDVRrDKNw9J
85PNBKc4Cr3A3DuI2zQvvwuBtlkQfRde2SO3E059iuGtFXdLZQOI664wQsUZwssyqSq925
@PM2Ring
PM2Ring / globe_anim.svg
Created July 14, 2024 12:34
Animated globe, using cubic Bezier curves.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PM2Ring
PM2Ring / mandel.html
Created June 9, 2024 11:32
Simple Mandelbrot set, in JavaScript
<!DOCTYPE html>
<html>
<head>
<title>Mandelbrot</title>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<style type="text/css">
h { text-align: center; }
#mycanvas { border: 1px solid black; cursor: crosshair;
margin-left: 1%; margin-right: 1%; }
</style>
@PM2Ring
PM2Ring / fpe_feistel.py
Created January 17, 2024 11:01
Format preserving encryption using a Feistel network
""" Format preserving encryption using a Feistel network
See https://stackoverflow.com/a/51429458/4014959
Written by PM 2Ring 2016.08.22
Version using Blake2 hashing 2021.06.14
Added pair permutation 2024.01.17
"""
from hashlib import blake2s as blake
from random import Random
@PM2Ring
PM2Ring / ellipse3d.py
Created November 2, 2023 04:17
Plot filled ellipse in 3D
""" Plot filled ellipse in 3D.
With major axis and line of nodes
Written by PM 2Ring 2023.9.24
"""
var('th')
deg = n(pi / 180)
def ellipse(a, ec):
@PM2Ring
PM2Ring / hyper.svg
Created November 1, 2023 23:12
Hyperbolic color demo
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PM2Ring
PM2Ring / AGM_pi.py
Created October 31, 2023 18:39
The Salamin / Brent / Gauss Arithmetic-Geometric Mean pi formula, using fixed point arithmetic
""" Gauss / Salamin / Brent true AGM pi
Binary fixed point
Written by PM 2Ring 2023.11.1
"""
from math import isqrt
def AGM_pi(loops, bits):
a, b = 1 << bits, isqrt(1 << 2*bits-1)
s = 1 << bits-2
@PM2Ring
PM2Ring / chromostereo_blue.py
Created October 27, 2023 16:48
Chromostereopsis illusion, with blue noise
""" Chromostereopsis illusion
With generated blue noise dither (void & cluster),
Poisson disk, white noise, checks, and undithered.
See https://mathematica.stackexchange.com/q/289992
"""
import numpy as np
from scipy import ndimage
from sage.repl.image import Image
@PM2Ring
PM2Ring / bberg32.py
Last active September 8, 2023 04:47
Fast primality for 32 bit integers, using a single SPRP test
""" BBerg32
Primality test for 32 bit integers using a single SPRP test.
The SPRP base comes from a hash table.
Hash and bases by Bradley Berg
See https://techneon.com/download/is.prime.32.base.data
"""
bases = [