Skip to content

Instantly share code, notes, and snippets.

@PM2Ring
PM2Ring / 6x6_faultline_counts.txt
Last active August 10, 2023 23:57
Domino tiling
(0, 1) : 50
(1, 0) : 50
(0, 2) : 258
(1, 1) : 600
(2, 0) : 258
(0, 3) : 186
(1, 2) : 1086
(2, 1) : 1086
(3, 0) : 186
(0, 4) : 5
@PM2Ring
PM2Ring / KeplerEllipse2.svg
Created November 12, 2020 10:56
Kepler's Laws Ellipse
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PM2Ring
PM2Ring / tk_bezier_track.py
Last active April 10, 2023 23:08
Cubic Bezier tracks with constant speed animation, using Tkinter
#!/usr/bin/env python3
''' Create a closed track from cubic Bezier curves, and animate a circle
following the track at constant speed.
https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B%C3%A9zier_curves
https://gist.github.com/PM2Ring/d6a19f5062b39467ac669a4fb4715779
Press the Add button to add black control dots to the Canvas. The first
@PM2Ring
PM2Ring / PIL_bitmap_bug.py
Created July 14, 2017 17:30
Demonstrate the PIL .fromarray bitmap bug
#! /usr/bin/env python3
''' Demonstrate the PIL .fromarray bitmap bug
PIL's Image.fromarray function has a bug with mode '1' images
See
https://stackoverflow.com/questions/2761645/error-converting-pil-bw-images-to-numpy-arrays
Written by PM 2Ring 2017.06.26
@PM2Ring
PM2Ring / julian_day.py
Created March 6, 2022 08:13
Julian Day Number conversion, Gregorian & Julian
""" Julian day number to date conversion
Proleptic Gregorian and Julian, with Astronomical years
i.e., 1 AD = year 1, 1 BC = year 0, 2 BC = year -1, etc
Derived from RG Tantzen (1963), ACM.
Algorithm 199: conversions between calendar date and Julian day number.
https://en.wikipedia.org/wiki/Julian_day
Julian day number 0 assigned to the day starting at noon on
January 1, 4713 BC, proleptic Julian calendar
@PM2Ring
PM2Ring / MaxwellBoltzmann.py
Created January 19, 2023 10:32
Plot a Maxwell Boltzmann distribution graph using Sage
""" Maxwell–Boltzmann distribution
See https://en.m.wikipedia.org/wiki/Maxwell%E2%80%93Boltzmann_distribution
Written by PM 2Ring 2021.06.20
"""
# Gas constant g⋅m^2⋅s^−2⋅K^−1⋅mol^−1
R = 8314.46261815324
@interact
def _(T=('temp (°C)', 20), mass=('mass (g/mol)', 29),
auto_update=False):
@PM2Ring
PM2Ring / lorenz.py
Created January 4, 2023 11:59
Lorenz attractor
""" Lorenz attractor
From https://en.wikipedia.org/wiki/Lorenz_system
Modified for Sagemath by PM 2Ring 2023.01.04
"""
import numpy as np
from scipy.integrate import odeint
# Build Bezier curves
@PM2Ring
PM2Ring / borwein_pi.py
Created January 2, 2023 07:11
Borwein quadratic pi
""" Borwein + Borwein quadratic pi
Algorithm 2.1 from "Pi and the AGM" (Wiley, 1987)
Written by PM 2Ring 2023.1.2
"""
from math import floor, log, pi
from decimal import Decimal as D, getcontext
def borwein_pi(loops):
x = D(2).sqrt()
@PM2Ring
PM2Ring / solar.txt
Created December 6, 2022 04:06
Standard Solar Model
Standard Solar Model (BP2004)
https://www.sns.ias.edu/~jnb/SNdata/Export/BP2004/bp2004stdmodel.dat
astro-ph/0402114
Columns in the Standard Model table (below) represent:
1) Mass fraction in units of the solar mass
2) Radius of the zone in units of one solar radius
3) Temperature in units of deg (K)
4) Density in units of g/cm^3
@PM2Ring
PM2Ring / cheney.py
Last active August 28, 2022 13:18
Generalization of the 'Fitch' Cheney card trick
#! /usr/bin/env python3
''' Generalization of the 'Fitch' Cheney card trick
Written by PM 2Ring 2003.02.13
Converted to Python 2018.06.27
'''
import sys
import readline