Skip to content

Instantly share code, notes, and snippets.

View SimonDanisch's full-sized avatar
🏠
Working from home

Simon SimonDanisch

🏠
Working from home
View GitHub Profile
using Base.Broadcast: broadcasted
struct LazyBro{T, N, B} <: AbstractArray{T, N}
size::NTuple{N, Int}
broadcast::B
function (LazyBro{T})(x::B, size::NTuple{N, Int}) where {T, N, B <: Base.Broadcast.Broadcasted}
new{T, N, B}(size, x)
end
end
Base.size(x::LazyBro) = x.size
Base.@propagate_inbounds Base.getindex(x::LazyBro, idx...) = x.broadcast[idx...]
# pkg"add AbstractPlotting#master"
using Makie, GeometryTypes, Colors
using AbstractPlotting: slider!, playbutton
using Observables
cd(@__DIR__)
psps = [rand(50, 50, 50) for i in 1:50]
mini, maxi = mapreduce(extrema, (a, b)-> (min(a[1], b[1]), max(a[2], b[2])), psps)
psps_n = map(psps) do vol
#Get a console handle
GetConsoleWindow() = ccall((:GetConsoleWindow, :kernel32), Ptr{Void}, ())
GetDC(win) = ccall((:GetDC, :user32), Ptr{Void}, (Ptr{Void},), win)
ReleaseDC(win, dc) = ccall((:ReleaseDC, :user32), Cint, (Ptr{Void}, Ptr{Void}), win, dc)
function GetCursorPos() # mouse position
pos = Ref{Tuple{Int32, Int32}}()
ccall((:GetCursorPos, :user32), UInt8, (Ptr{Tuple{Int32, Int32}},), pos)
Int64.(pos[])
end

Makie WebGL backend prototype:

webgl

Makie GUI / interaction examples (will work on all backends)

lorentz_ui

mouseover

using Makie, Colors
using AbstractPlotting: modelmatrix
scene = Scene(resolution = (1000, 1000))
AbstractPlotting.set_theme!()
ui_width = 260
ui = Scene(scene, lift(x-> IRect(0, 0, ui_width, widths(x)[2]), pixelarea(scene)))
plot_scene = Scene(scene, lift(x-> IRect(ui_width, 0, widths(x) .- Vec(ui_width, 0)), pixelarea(scene)))
using Makie
points = node(:poly, Point2f0[(0, 0), (0.5, 0.5), (1.0, 0.0)])
scene = poly(points, strokewidth = 2, strokecolor = :black, color = :skyblue2, show_axis = false, scale_plot = false)
scatter!(points, color = :white, strokewidth = 10, markersize = 0.05, strokecolor = :black, raw = true)
pplot = scene[end]
push!(points[], Point2f0(0.6, -0.3))
points[] = points[]
using HTTP
function url_exists(url)
try
r = HTTP.request("GET", url)
return r.status == 200
catch e
return false
end
end
cd(@__DIR__)
using Makie
using FileIO, GeometryTypes, Colors, GDAL
GDAL.allregister()
istiff(x) = endswith(x, ".tif")
function loadf0(x)
img = GDAL.open(x, GDAL.GA_ReadOnly)
band = GDAL.getrasterband(img, 1)
xsize = GDAL.getrasterbandxsize(band)
ysize = GDAL.getrasterbandysize(band)
using Makie
import DiffEqPhysics: SimulationResult
import AbstractPlotting: Plot, default_theme, plot!, to_value
# Probably worth having a macro for this!
function default_theme(scene::SceneLike, ::Type{<: Plot(SimulationResult)})
Theme(
simulation_index = 1
unroll(f, ::Val{1}) = f()
function unroll(f, ::Val{N}) where N
f(); unroll(f, Val(N-1))
end
function test()
box = Ref(1.0) # explicitely box to make escape analysis easier
unroll(()-> box[] += sin(box[]), Val(3))
box[]
end