Julia set: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 464: | Line 464: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
The following code build a ppm file named julia.ppm. So there is no need of an external library to create the final image. |
|||
<lang julia> |
|||
function iter(z,c) |
|||
n = 0 |
|||
while (n<256 && norm(z)<2) z = z^2+c ; n+=1 end |
|||
return n |
|||
end |
|||
coord(i,j,w,h,a,b) = 2*a*(i-1)/(w-1) - a + im * (2*b*(j-1)/(h-1) - b) |
|||
palette(n) = string(min(3n,255)," ", min(n,255)," ", 0," "); |
|||
julia(c) = (w,h,a,b,i,j) -> palette(iter(coord(i,j,w,h,a,b), c)) |
|||
writeppm(f; width=600,height=300,a=2,b=1,file="julia.ppm") = |
|||
open(file, "w") do out |
|||
write(out, string("P3\n", width, " ", height, "\n255\n")) |
|||
writedlm(out, [f(width,height,a,b,i,j) for j = 1:height, i = 1:width], '\n') |
|||
end |
|||
</lang> |
|||
We can then produce a 800x600 ppm image of the Julia set associated to the parameter ''-0.786+0.147i'' as follows. |
|||
<pre>writeppm(julia(-0.786+0.147im))</pre> |
|||
The following code makes use of the library '''Images''' to build a png image. |
|||
[[File:JuliaSet_julia.png|250px|thumb|right]] |
[[File:JuliaSet_julia.png|250px|thumb|right]] |
||
<lang julia>using Images |
<lang julia>using Images |