diff --git a/docs/src/gallery.md b/docs/src/gallery.md index bb6804d..0c39875 100644 --- a/docs/src/gallery.md +++ b/docs/src/gallery.md @@ -25,4 +25,10 @@ heatmap(rand(EdgeGradient(), (45, 45))) ```@example gallery heatmap(rand(WaveSurface(), (45, 45))) +``` + +## Rectangular cluster + +```@example gallery +heatmap(rand(RectangularCluster(), (45, 45))) ``` \ No newline at end of file diff --git a/docs/src/index.md b/docs/src/index.md index 078b7d5..0bd2ede 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -10,6 +10,7 @@ NoGradient PlanarGradient EdgeGradient WaveSurface +RectangularCluster ``` ## Landscape generating function diff --git a/src/NeutralLandscapes.jl b/src/NeutralLandscapes.jl index 2bb94f6..0662061 100644 --- a/src/NeutralLandscapes.jl +++ b/src/NeutralLandscapes.jl @@ -21,4 +21,7 @@ export EdgeGradient include(joinpath("algorithms", "wavesurface.jl")) export WaveSurface +include(joinpath("algorithms", "rectangularcluster.jl")) +export RectangularCluster + end # module diff --git a/src/algorithms/rectangularcluster.jl b/src/algorithms/rectangularcluster.jl new file mode 100644 index 0000000..eb55424 --- /dev/null +++ b/src/algorithms/rectangularcluster.jl @@ -0,0 +1,28 @@ +""" + RectangularCluster + +Fills the landscape with rectangles containing a random value. The size of each +rectangle/patch is between `minimum` and `maximum` (the two can be equal for a +fixed size rectangle). +""" +struct RectangularCluster <: NeutralLandscapeMaker + minimum::Integer + maximum::Integer + function RectangularCluster(x::T, y::T) where {T <: Integer} + @assert 0 < x <= y + new(x, y) + end +end + +RectangularCluster() = RectangularCluster(2,4) + +function _landscape!(mat, alg::RectangularCluster) + mat .= -1.0 + while minimum(mat) == -1.0 + width, height = rand(alg.minimum:alg.maximum, 2) + row = rand(1:(size(mat,1)-(width-1))) + col = rand(1:(size(mat,2)-(height-1))) + mat[row:(row+(width-1)) , col:(col+(height-1))] .= rand() + end + return mat +end