Barnsley fern: Difference between revisions
m
→{{header|Julia}}
Line 1,711:
=={{header|Julia}}==
mutable struct BarnsleyFern
▲<syntaxhighlight lang=julia>function barnsleyfern(n::Integer)
height::Int
(x, y) -> (0, 0.16y),▼
color::RGB
bgcolor::RGB
x::Float64
fern::Matrix{RGB}
for row in 2:n▼
function BarnsleyFern(width, height)
f = new(width, height, RGB(0.0, 1.0, 0.0), RGB(1.0, 1.0, 1.0), 0.0, 0.0, 0,
[RGB(0.0, 0.0, 0.0) for x in 1:width, y in 1:height])
f.fern[Int(trunc(x)) + 1, Int(trunc(y)) + 1] = f.color
return f
end
end
function transform(f::BarnsleyFern)
r = rand(0:99)
end
scale(f::BarnsleyFern) = (f.x + 2.182) * (f.width - 1) / 4.8378, (9.9983 - f.y) * (f.height - 1) / 9.9983
function iterate(f::BarnsleyFern, iterations)
transform(f)
newx, newy = scale(f)
f.fern[Int(trunc(newx)) + 1, Int(trunc(newy)) + 1] = f.color
end
end
end</syntaxhighlight>▼
fern = BarnsleyFern(500, 500)
iterate(fern, 1000000)
fern.fern'
[[File:Jbarnsleyfern.png]]
=={{header|Kotlin}}==
|