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 Makie
N = 100
scene = mesh(
FRect3D(Vec3f0(-0.5), Vec3f0(1)), color = :skyblue2,
)
rect = scene[end] # last plot is the rect
# there are a couple of ratate! functions, that accept e.g. a vector etc
rotate!(rect, Quaternionf0(0, 0.4, 0, 1))
scene
function project_position(scene, point, model)
res = scene.camera.resolution[]
p4d = to_ndim(Vec4f0, to_ndim(Vec3f0, point, 0f0), 1f0)
clip = scene.camera.projectionview[] * model * p4d
p = (clip / clip[4])[Vec(1, 2)]
(p .+ 1) ./ 2
end
"""
`scatter(x, y, z)` / `scatter(x, y)` / `scatter(positions)`
"""
`scatter(x, y, z)` / `scatter(x, y)` / `scatter(positions)`
Plots a marker for each element in `(x, y, z)`, `(x, y)`, or `positions`.
"""
function draw(scene::Scene, plot::Scatter)
# Extracts attributes from plot and makes them available in the current scope
# This also applies all conversions + extracts the current value from them.
# e.g. plot[:color] might be e.g. Node(:red), while @get_attribute(plot, (color,)) will be
# Code taken from article: http://www.tylermw.com/throwing-shade/
# Author: Tyler Morgan-Wall
function shadows(
A, volcanoshadow = fill(1.0, size(A));
sunangle = 45 / 180*pi,
angle = -90 / 180 * pi,
diffangle = 90 / 180 * pi,
numberangles = 25,
anglebreaks = range(angle, stop = diffangle, length = numberangles),
growth(🐇, 🥕) = 🐇 * 🥕 * (1.0 - 🐇)
function orbitdiagram(growth, r1, r2, n = 500, a = zeros(1000, n); T = 1000)
rs = range(r1, stop = r2, length = 1000)
for (j, r) in enumerate(rs)
x = 0.5
for _ in 1:T; x = growth(x, r); end
for i in 1:n
x = growth(x, r)
@inbounds a[j, i] = x
end
# 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