Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
jkrumbiegel / portaudio.jl
Last active Dec 5, 2021
basic portaudio
View portaudio.jl
using Pkg
pkg"activate @portaudio"
using PortAudio.LibPortAudio
mutable struct Audio
ptr::Ptr{Float32}
buffer::Vector{Float32} # vector reference so no problems with garbage collection
len::Int
@jkrumbiegel
jkrumbiegel / multi_archimedes_spiral_makie.jl
Created Sep 19, 2021
multiple archimedes spiral makie
View multi_archimedes_spiral_makie.jl
using CairoMakie
##
s = Scene(resolution = (500, 500), camera = campixel!, show_axis = false)
o = Point2f(250, 250)
n = 5
linewidth = 10
center_offset = 0
rotation_gain = 1.5
View makie_axis_bracket.jl
function bracketlabel!(ax, label, mi, ma, axoffset, bracketwidth, labeloffset)
bracketpoints = lift(ax.finallimits, ax.scene.px_area) do lims, px_area
x = minimum(lims)[1]
pmin = Makie.project(ax.scene, Point2f(x, mi))
pmax = Makie.project(ax.scene, Point2f(x, ma))
ps = Point2f[
pmin,
pmin - Point2f(bracketwidth, 0),
@jkrumbiegel
jkrumbiegel / makie_gantt.jl
Created Aug 20, 2021
makie gantt bar chart
View makie_gantt.jl
task_starts = [0, 3, 5, 10]
task_ends = [3, 6, 9, 12]
task_positions = [1, 2, 1, 2]
barplot(task_positions, task_ends, fillto = task_starts,
direction = :x)
text!("task " .* string.(1:4),
position = Point2f0.(
(task_starts .+ task_ends) ./ 2,
task_positions
@jkrumbiegel
jkrumbiegel / cleveland.jl
Created May 2, 2021
cleveland gridlayout
View cleveland.jl
f = Figure()
nrows, ncols = (3, 7)
real_axes = map(Iterators.product(1:nrows, 1:ncols)) do (i, j)
ax = Axis(f[2i, j])
if i < nrows
hidexdecorations!(ax, grid = false)
end
if 1 < j < ncols
@jkrumbiegel
jkrumbiegel / subplots_fixed_size.jl
Created May 2, 2021
makielayout set figure size according to fixed width/height subplots
View subplots_fixed_size.jl
f = Figure()
[Axis(f[i, j], width = 300, height = 250) for i in 1:3, j in 1:3]
sz = ceil.(Int, GridLayoutBase.determinedirsize.(
Ref(f.layout),
(GridLayoutBase.Col(), GridLayoutBase.Row())))
resize!(f.scene, sz)
View stairs_recipe.jl
@recipe(Stairs) do scene
a = Attributes(
step = :pre, # :center :post
)
merge(a, AbstractPlotting.default_theme(scene, Lines))
end
AbstractPlotting.conversion_trait(x::Type{<: Stairs}) = AbstractPlotting.PointBased()
function AbstractPlotting.plot!(p::Stairs{<:Tuple{<:AbstractVector{<:Point2}}})
View integer_log_ticks.jl
struct IntegerTicks end
MakieLayout.get_tickvalues(::IntegerTicks, vmin, vmax) = ceil(Int, vmin) : floor(Int, vmax)
lines(0.01:0.001:0.99, axis = (yscale = log10, yticks = LogTicks(IntegerTicks())))
View plot_example.jl
measures = ["Endurance", "Coordination", "Speed", "Power Low", "Power Up"]
groups = ["boys", "girls"]
x = LinRange(-8, 9, 15)
f = Figure(resolution = (1000, 500))
axs = [Axis(f[1, i]) for i in 1:length(measures)]
for (i, m) in enumerate(measures)
@jkrumbiegel
jkrumbiegel / legendre.jl
Created Apr 4, 2021
legendre polynomials makie
View legendre.jl
using Legendre, GLMakie
using GeometryBasics, LinearAlgebra, StatsBase
using AbstractPlotting
using AbstractPlotting: get_dim, surface_normals
function Y(θ, ϕ, l, m)
if m < 0
return (-1)^m * 2 * Nlm(l, abs(m)) * Plm(l, abs(m), cos(θ)) * sin(abs(m)*ϕ)
elseif m == 0
return sqrt((2*l+1)/4π)*Plm(l, m, cos(θ))