Skip to content

Instantly share code, notes, and snippets.

using WebSockets, WebIO, Colors, ImageMagick
using CSSUtil
using ImageFiltering, JSExpr
using Base64, FixedPointNumbers
using ImageTransformations, CSSUtil
# using the string macro since for loops + ifs seem to make problems
const redraw = js"""
function redraw(context, brushsize, rect, drawtext){
context.clearRect(0, 0, rect.height, rect.width); // Clears the canvas
context.beginPath();
using Colors, FixedPointNumbers
const DWORD = Culong
const LONG = Clong
const WORD = Cushort
const CIEXYZTRIPLE = NTuple{3, XYZ{Float32}}
struct BITMAPV5HEADER
bV5Size::DWORD
bV5Width::LONG
bV5Height::LONG
AbstractPlotting.set_theme!() # reset theme
function lorenz(t0, a, b, c, h)
Point3f0(
t0[1] + h * a * (t0[2] - t0[1]),
t0[2] + h * (t0[1] * (b - t0[3]) - t0[2]),
t0[3] + h * (t0[1] * t0[2] - c * t0[3]),
)
end
# step through the `time`
function lorenz(array::Vector, a = 5.0 ,b = 2.0, c = 6.0, d = 0.01)
base = dirname(Base.find_source_file("sysimg.jl"))
file = "/home/sd/Desktop/precompile.jl" # snippet from slack
cd(homedir() * "/Desktop")
filebase = homedir() * "/Desktop/sysimg"
mkdir(filebase)
cd(base)
run(`julia1 --output-ji $filebase/corecompiler.ji --startup-file=no -g0 -O0 compiler/compiler.jl`)
run(`julia1 -g1 -O0 -C "native" --output-ji $filebase/sys.ji --startup-file=no --warn-overwrite=yes --sysimage $filebase/corecompiler.ji sysimg.jl`)
run(`julia1 -O3 -C "native" --output-o $filebase/sys.a --startup-file=no --warn-overwrite=yes --sysimage $filebase/sys.ji $file`)
pkg"add FixedPointNumbers"
using WebSockets, WebIO, Colors, ImageMagick
using CSSUtil
using ImageFiltering, JSExpr
using Base64, FixedPointNumbers
using ImageTransformations
# using the string macro since for loops + ifs seem to make problems
const redraw = js"""
function redraw(context, brushsize, rect, drawtext){
context.clearRect(0, 0, rect.height, rect.width); // Clears the canvas
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