Skip to content

Instantly share code, notes, and snippets.

# Simple 1 to 1 conversion - can only be used to transform arguments + pass additional attributes
# and change the default plot type - but can't be used for complex plots!
# Name is up for debate!
function convert_arguments(args...)
# Return a named tuple with the optional fields:
return (
arguments = convert.(args),
plot = Scatter, # Optionally define the default plot type
attributes = (
labels = create_labels(args...),
using Makie, Interact, WebIO, Colors
widgets = (
slider = widget(range(0.0, stop = 2pi, length = 200), label = "size"), # Slider
ranges = rangepicker(
range(0.1, stop = 3.0, length = 50)
),
toggle = widget(false), # Checkbox
text = widget("text"), # Textbox
# spinbox = widget(1.1), # Spinbox
using WebIO, TreeViews, CSSUtil, JSExpr, Interact
x = Lal(1f0, rand(10))
using TreeViews: treenode, numberofnodes
function represent_node(s, x, i)
unfold = true
n = treenode(x, i)
str = sprint() do io
treelabel(io, x, i)
print(io, " → ")
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