June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,43 +1,42 @@
using Color, Images, FixedPointNumbers
using Images, FileIO
const W = 512
const W0 = W>>1
const H = 512
const H0 = H>>1
const N = iceil(1.0*W*H)
const SIDESTICK = false
function main(h::Integer, w::Integer, side::Bool=false)
W0 = w >> 1
H0 = h >> 1
@inline function motecolor(x::Integer, y::Integer)
h = clamp(180 * (atan2(y - H0, x - W0) / π + 1.0), 0.0, 360.0)
return HSV(h, 0.5, 0.5)
end
function motecolor(x::Int, y::Int)
h = clamp(180*(atan2(y-H0, x-W0)/pi + 1.0), 0.0, 360.0)
return HSV(h, 0.5, 0.5)
end
img = Image(zeros(RGB{Ufixed8}, H, W))
img["x", W0, "y", H0] = RGB(1, 1, 1)
isfree = trues(W, H)
isfree[W0, H0] = false
for i in 1:N
x = rand(1:W)
y = rand(1:H)
isfree[x, y] || continue
mc = motecolor(x, y)
for j in 1:10^3
xp = x + rand(-1:1)
yp = y + rand(-1:1)
iscontained = 0 < xp <= W && 0 < yp <= H
if iscontained && isfree[xp, yp]
x = xp
y = yp
continue
else
if SIDESTICK || (iscontained && !isfree[xp, yp])
isfree[x, y] = false
img["x", x, "y", y] = mc
img = zeros(RGB{N0f8}, h, w)
img[H0, W0] = RGB(1, 1, 1)
free = trues(h, w)
free[H0, W0] = false
for i in eachindex(img)
x = rand(1:h)
y = rand(1:w)
free[x, y] || continue
mc = motecolor(x, y)
for j in 1:1000
xp = x + rand(-1:1)
yp = y + rand(-1:1)
contained = checkbounds(Bool, img, xp, yp)
if contained && free[xp, yp]
x, y = xp, yp
continue
else
if side || (contained && !free[xp, yp])
free[x, y] = false
img[x, y] = mc
end
break
end
break
end
end
return img
end
imwrite(img, "brownian_tree.png")
imgnoside = main(256, 256)
imgwtside = main(256, 256, true)
save("data/browniantree_noside.jpg", imgnoside)
save("data/browniantree_wtside.jpg", imgwtside)