Skip to content

Instantly share code, notes, and snippets.


David Amos somacdivad

View GitHub Profile
View permutations.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View involute.jl
using Base.Iterators
RIGHT = (0, 1)
DOWN = (1, 0)
LEFT = (0, -1)
UP = (-1, 0)
function involute(n::Int)::Matrix{Int}
directions = cycle((RIGHT, DOWN, LEFT, UP))
repeats = pushfirst!(collect(flatten(zip(n-1:-1:1, n-1:-1:1))), n-1)
somacdivad / lilac_chaser.jl
Created Feb 14, 2022
Julia code that reproduces Jeremy Hinton's "Lilac Chaser" illusion. See for more information on how the illusion works.
View lilac_chaser.jl
using Javis
video = Video(500, 500)
N = 12
frames = 4(N+1)
Background(1:frames, (args...) -> background("grey70"))
# Draw crosshairs
Object(@JShape begin
View circle_illusion_with_actions.jl
using Animations
using ColorSchemes
using Javis
N = 6 # number of circles
radius = 20 # Radius of each circles
speed = 5 # degrees per frame
colors = ColorSchemes.rainbow1
video = Video(500, 500)
View circle_illusion.jl
using ColorSchemes
using Javis
N = 6 # Number of dots
radius = 20 # Radius of each dot
colors = ColorSchemes.rainbow1 # Color palette
speed = 10 # Degrees per frame
function draw_circle(frame, i, radius, speed)
# Angle of the direction vector for the dot
somacdivad / circles.jl
Created Feb 8, 2022
Makes an animation of four circle growing and shrinking while changing color.
View circles.jl
using Javis
using ColorSchemes
# Set the color scheme
# More options:
colors =
function circ(radius, color="white")
sethue(color) # Set the color of the circle
somacdivad / musical_graphs.jl
Last active Feb 2, 2022
Six graphs on four vertices and their musical chords
View musical_graphs.jl
import LinearAlgebra as LinAlg
import SparseArrays
import Graphs
import GraphRecipes: graphplot
import Plots: savefig
import WAV
function normalized_laplacian_matrix(g::Graphs.SimpleGraph)
somacdivad / graph_music.jl
Created Jan 31, 2022
Create music from graphs by converting the eigenvalues of the normalized Laplacian matrix to frequencies
View graph_music.jl
import LinearAlgebra as LinAlg
import SparseArrays
import Graphs
import WAV
function normalized_laplacian_matrix(g::Graphs.SimpleGraph)
A = Graphs.CombinatorialAdjacency(Graphs.adjacency_matrix(g).+ 0.0)
 = Graphs.NormalizedAdjacency(A)
somacdivad /
Last active May 27, 2018
Shuffling an iterator with itertools vs. random.shuffle().
import itertools as it
import random
import timeit
def shuffle(deck):
"""Return iterator over shuffled deck."""
deck = list(deck)
return iter(tuple(deck))

Keybase proof

I hereby claim:

  • I am somacdivad on github.
  • I am somacdivad ( on keybase.
  • I have a public key ASBLJLQAvzm-joiPvv1HxlcD8LeRadySvwU0iGkoh-BNEQo

To claim this, I am signing this object: