Skip to content

Instantly share code, notes, and snippets.

# draw pi digits up to Feynman point to give illusion of rounding at 999999
using Luxor
function pidigits(n)
result = Int[]
k, a::BigInt, b::BigInt, a1::BigInt, b1::BigInt = 2, 4, 1, 12, 4
while n > 0
p, q, k = k * k, 2k + 1, k + 1
a, b, a1, b1 = a1, b1, p * a + q * a1, p * b + q * b1
@cormullion
cormullion / julia-bouncing-balls-animation.jl
Last active September 17, 2022 13:23
julia bouncing balls
using Luxor, Colors, Combinatorics, Random
mutable struct Ball
id::Int
position::Point
velocity::Point
color::Union{NTuple, Colorant, String}
ballradius::Float64
end
@cormullion
cormullion / rotating-ellipses.jl
Created January 19, 2018 09:36
rotating ellipses
using Luxor
function frame(scene, framenumber)
background("grey5")
setline(1.2)
eased = scene.easingfunction(framenumber-scene.framerange.start, 0, 1, scene.framerange.stop-scene.framerange.start)
eased_n = sin(rescale(eased, (0, 1), (0, 2pi)))
theta = eased_n/2
s = rescale(eased, 0, 1, 0.95, .01)
t = rescale(eased, 0, 1, .01, 0.95)
@cormullion
cormullion / calendar-2018.jl
Created December 15, 2017 11:46
calendar-2018.jl
using Luxor
pentagon(pos, radius, ang=0, action=:stroke) = ngon(pos, radius, 5, ang, vertices=true)
function drawmonth(year, month, radius)
# origin is now in center of pentagon
@layer begin
rotate(pi)
fontsize(18)
fontface("DINNextLTPro-Black")
@cormullion
cormullion / stripey.jl
Last active October 22, 2017 12:51
a stripey logo
using Luxor
darker_blue = (0.251, 0.388, 0.847)
darker_purple = (0.584, 0.345, 0.698)
darker_green = (0.22, 0.596, 0.149)
darker_red = (0.796, 0.235, 0.2)
@png begin
w = 256
background("white")
origin()
@cormullion
cormullion / pendulums.jl
Last active October 24, 2022 11:39
George's double pendulums
using Luxor, DynamicalSystems, Colors
function frame(scene, framenumber, datas)
background("black")
# datas contains two datasets
# each dataset is an array of sarrays of 4 floats
d1, d2 = datas
offset = π / 2
L = 200
disksize = 15
@cormullion
cormullion / pendulum.jl
Last active October 23, 2022 15:09
pendulum logo
using Luxor
using ODE # I should be using OrdinaryDiff, but that's for another day
function pendulum(t, y)
Y = [6 * (2 * y[3] - 3 * cos(y[1] - y[2]) * y[4])/(16 - 9 * cos(y[1] - y[2])^2);
6 * (8 * y[4] - 3 * cos(y[1] - y[2]) * y[3])/(16 - 9 * cos(y[1] - y[2])^2)]
[Y[1];
Y[2];
- (Y[1] * Y[2] * sin(y[1] - y[2]) + 3 * sin(y[1]))/2;
@cormullion
cormullion / juliapool.jl
Last active September 17, 2022 13:22
julia pool
using Luxor, Colors, Combinatorics, Random
mutable struct Ball
id::Int
position::Point
velocity::Point
color::Union{NTuple, Colorant, String}
ballradius::Float64
end
julia> Pkg.status()
37 required packages:
- AstroLib 0.1.0
- Atom 0.6.1
- BenchmarkTools 0.0.8
- Cairo 0.3.0
- ColorSchemes 1.4.0+ master
- Combinatorics 0.4.1
- DataFrames 0.10.0
- Documenter 0.11.1
@cormullion
cormullion / getjuliaconyoutube.jl
Last active August 5, 2017 09:08
get JuliaCon2017 videos from YouTube as list
using HTTP, JSON, Query
# get data for the julia channel "UC9IuUwwE2xdjQUT_LMLONoA"
function getrawdata(nextpagetoken, apikey)
d = HTTP.get("https://www.googleapis.com/youtube/v3/search?key=$(apikey)&channelId=UC9IuUwwE2xdjQUT_LMLONoA&pageToken=$(nextpagetoken)&part=snippet,id&order=date&maxResults=50")
return d.body
end
jsonpages = [] # store the json pages, 50 records at a time
vidlinks = [] # to hold the video titles and links