Last active
May 24, 2019 06:20
-
-
Save shiftshuffle/4b663a260c79cafd2cc1d306392686db to your computer and use it in GitHub Desktop.
Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ColorSchemes, Images, FileIO | |
# and possibly QuartzImageIO (macOS) and/or ImageMagick (Linux) | |
function julia(z, c, maxiter::Int64) | |
for n = 1:maxiter | |
if abs(z) > 2 | |
return n | |
end | |
z = z^2 + c | |
end | |
return maxiter | |
end | |
# convert a value between oldmin/oldmax to equivalent value between newmin/newmax | |
remap(value, oldmin, oldmax, newmin, newmax) = ((value - oldmin) / (oldmax - oldmin)) * (newmax - newmin) + newmin | |
function draw(c, imsize; | |
xmin = -1, ymin = -1, xmax = 1, ymax = 1, | |
filename = "julia-set.png") | |
imOutput = zeros(RGB{Float32}, imsize, imsize) | |
maxiterations = 200 | |
for col = range(xmin, stop=xmax, length=imsize) | |
for row = range(ymin, stop=ymax, length=imsize) | |
pixelcolor = julia(complex(row, col), c, maxiterations) / 256 | |
xpos = convert(Int, round(remap(col, xmin, xmax, 1, imsize))) | |
ypos = convert(Int, round(remap(row, ymin, ymax, 1, imsize))) | |
imOutput[xpos, ypos] = get(ColorSchemes.vermeer, pixelcolor) | |
end | |
end | |
save(filename, imOutput) | |
end | |
draw(-0.4 + 0.6im, 1200) | |
################# | |
using Images, Colors, ImageMagick, Interact | |
const cmap = convert(Array{FixedPointNumbers.Normed{UInt8,8},2}, colormap("RdBu",100)) | |
const maxiter = 100 | |
function julia(z,c) | |
for n = 1:maxiter | |
abs2(z) > 4 && return n-1 | |
z = z*z + c | |
end | |
return maxiter | |
end | |
julia(.4+.5im, .6+.7im) | |
let I = -1:.005:1, R = -1:.005:1 | |
data = Array{FixedPointNumbers.Normed{UInt8,8},2}(undef,length(I),length(R)) | |
img = ImageMeta(data) | |
@manipulate for r_ = -0.1:.01:0.1, i_ = .065:.01:85 | |
for (j,i) in enumerate(I),(k,r) in enumerate(R) | |
data[j,k] = Array{FixedPointNumbers.Normed{UInt8,8},2}[julia(r+i*im, r_+i_*im)] | |
end | |
img | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment