{{ message }}

Instantly share code, notes, and snippets.

Ben Bartlett bencbartlett

Created Sep 21, 2021
Mathematica code for this animation: https://twitter.com/bencbartlett/status/1440039445261029377
View lorenz_many_particles.nb
This file contains 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
 SetDirectory[NotebookDirectory[]]; \[Sigma] = 10; \[Rho] = 28; \[Beta] = 8/3; Tmax = 10; eqn = { x'[t] == \[Sigma] (-x[t] + y[t]), y'[t] == \[Rho]* x[t] - y[t] - x[t]*z[t],
Created Mar 10, 2021
Electromagnetic simulation at various timescales: https://twitter.com/bencbartlett/status/1369396941730312193
View coherent_incoherent_light.jl
This file contains 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
 # Electromagnetic simulation at varying timescales - simulation code to make this animation: # https://twitter.com/bencbartlett/status/1369396941730312193 # # Animation idea was inspired by u/cenit997's (Twitter: @__cenit) Reddit post: # https://www.reddit.com/r/Python/comments/hxmhai/a_simulation_of_how_an_incoherent_light_source/ #--- using LinearAlgebra, Base.Threads, BenchmarkTools, LoopVectorization, CSV, DataFrames, Printf, Plots
Created Jan 20, 2021
Code to make the animation for https://twitter.com/bencbartlett/status/1351967463609491458
View ring_computer_animation.nb
This file contains 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
 SetDirectory[NotebookDirectory[]]; \[Theta]0 = -.1 \[Pi]; \[Phi]0 = .35*\[Pi]; \[Psi]0 = {Cos[\[Theta]0] Cos[\[Phi]0], Sin[\[Theta]0] Cos[\[Phi]0], Sin[\[Phi]0]}; Clear[BlochSphereVector]; BlochSphereVector[\[Psi]_, imSize_ : 1000, color_ : Gray, opacity_ : 1, \[Phi]view_ : \[Pi]/4, viewdist_ : 100] := Module[{ tubeball, pointline,
Last active Nov 27, 2021
Mathematica code for this animation of transitions in hydrogen wavefunctions: https://twitter.com/bencbartlett/status/1287802625602117632
View hydrogen_orbitals.nb
This file contains 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
 << MaTeX` SetOptions[MaTeX, "Preamble" -> {"\\usepackage{color,txfonts}"}]; SetDirectory[NotebookDirectory[]]; Clear[drawLadder]; drawLadder[n_, l_, m_, imsize_: 500] := Module[{maxrungs = 5, mag = 4}, Graphics[{ White, Opacity[1], Thickness[.02], Dashing[None], Table[Line[{{0, k}, {1, k}}], {k, maxrungs}], (*draw n lines*)
Created Oct 6, 2019
Mathematica code for photon pulse animation
View pulse.nb
This file contains 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
 << MaTeX` SetOptions[MaTeX, "Preamble" -> {"\\usepackage{color,txfonts}"}]; SetDirectory[NotebookDirectory[]]; c = 1; \[Alpha] = .7; \[Beta] = .05; k0 = 7; \[Omega]0 = 2 c; vg = c;
Created Jan 2, 2019
Inspecting
View ClassStringify.js
This file contains 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
 class Foo { constructor() { this.bar = "baz"; } } console.log('' + Foo); // > "class Foo {\n constructor()...z\";\n }\n\n}"
Last active Dec 20, 2018
GlobalCache.ts
View GlobalCache.ts
This file contains 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
 export class \$ { // \$ = cash = cache... get it? :D static set(thing: T, key: K, callback: () => (T[K] & (undefined | HasID | HasID[])), timeout = CACHE_TIMEOUT): void { const cacheKey = thing.ref + '\$' + key; if (!_cache.things[cacheKey] || Game.time > _cache.expiration[cacheKey]) { // Recache if new entry or entry is expired _cache.things[cacheKey] = callback(); _cache.expiration[cacheKey] = getCacheExpiration(timeout, Math.ceil(timeout / 10));
Last active Dec 20, 2018
Hatchery: build() vs refresh()
View Hatchery.ts
This file contains 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 {\$} from '../caching/GlobalCache'; export class Hatchery extends HiveCluster { // constructor gets run only on ticks with build() phase constructor(colony: Colony, headSpawn: StructureSpawn) { super(colony, headSpawn, 'hatchery'); this.memory = Mem.wrap(this.colony.memory, 'hatchery', HatcheryMemoryDefaults, true); // Register physical structure components this.spawns = colony.spawns;
Created Jun 20, 2016
Very simple second-order Markov text generator. Train on whatever sources you want.
View MarkovText.py
This file contains 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 random normalizeLengths = True # Set the length of the two input sources to be equal. # Generate transition matrix A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ " charnums = len(A) # Read through text and index transition matrix trainingText = " ".join(open("KingJamesBible.txt",'r').read().splitlines()) trainingText2 = " ".join(open("GriffithsQuantumMechanics.txt",'r').read().splitlines())
Created Jun 20, 2016
Code to make 2D evolving multiplot histogram with side plots, like this one: https://gfycat.com/PersonalGraciousAfricanharrierhawk
View LayerPlot.py
This file contains 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
 # Importations import os, shutil import numpy as np import matplotlib import matplotlib.pyplot as plt import matplotlib.mlab as mlab import pylab import warnings from mpl_toolkits.mplot3d import Axes3D, art3d from matplotlib.offsetbox import TextArea, VPacker, AnnotationBbox