# Announcing CoherentNoise.jl

**URL:** https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860
**Category:** Package Announcements
**Tags:** package, announcement, graphics, algorithm
**Created:** [August 17, 2022, 6:53am UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860 "2022-08-17T06:53:30Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![mfiano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfiano/32/37565_2.png) [@mfiano](https://discourse.julialang.org/u/mfiano)
#### Post date: [August 17, 2022, 6:53am UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/1 "2022-08-17T06:53:30Z")

</div>

I am proud to announce the first version of [CoherentNoise.jl](https://github.com/mfiano/CoherentNoise.jl), a library consisting of several coherent noise algorithms and tools to compose them into interesting pipelines.

This is actually my first real package, only having used Julia for about 2 months now. I am not a master yet, but if you find this useful and/or find some things that could be written more idiomatically, feel free to open an issue or pull request. I really look forward to learning more through discussion and collaboration.

That said, I am in love with Julia after having used it to create this library. I hope you don’t mind that I will be sticking around for a while! 😉

For information about what coherent noise is, please see the Overview section of the documentation, and for some simple examples, the Tutorial section: [https://mfiano.github.io/CoherentNoise.jl](https://mfiano.github.io/CoherentNoise.jl)

Thank you.

---

<div class="post-metadata">

### Author: ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)
#### Post date: [August 17, 2022, 7:15am UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/2 "2022-08-17T07:15:23Z")

</div>

Without trying it, props for the nice documentation!

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [August 17, 2022, 7:43am UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/3 "2022-08-17T07:43:19Z")

</div>

That looks really impressive for a first go at developing a package, kudos! Also interesting to read the Overview section to learn a bit about a topic I’d never heard of before (but which I guess has interesting real-world applications given your overview says one of the algorithms is patented for a certain number of dimensions!?)

---

<div class="post-metadata">

### Author: ![mfiano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfiano/32/37565_2.png) [@mfiano](https://discourse.julialang.org/u/mfiano)
#### Post date: [August 17, 2022, 7:46am UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/4 "2022-08-17T07:46:51Z")

</div>

Yes, IIRC Ken Perlin holds a patent for Simplex noise \>= 3 dimensions when used in the context of texture generation. The details are vague, so I would stay away from it for that use case.

However, CoherentNoise has all sorts of applications. For example you could use it to drive a force-feedback game controller to give it a smoother feel, or really anything that requires a signal.

---

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [August 17, 2022, 7:52am UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/5 "2022-08-17T07:52:29Z")

</div>

The tutorial has a typo `seeed`. Ideally doctests in CI would catch this.

---

<div class="post-metadata">

### Author: ![mfiano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfiano/32/37565_2.png) [@mfiano](https://discourse.julialang.org/u/mfiano)
#### Post date: [August 17, 2022, 7:54am UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/6 "2022-08-17T07:54:55Z")

</div>

Fixed, thanks. Also note that the documentation has a lot of errors, due to me not understanding Documenter.jl well enough. If any kind soul is bored enough and wants to PR this, see the bottom of: [Initial commit · mfiano/CoherentNoise.jl@a92b2c5 · GitHub](https://github.com/mfiano/CoherentNoise.jl/actions/runs/2873228971)

---

<div class="post-metadata">

### Author: ![mfiano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfiano/32/37565_2.png) [@mfiano](https://discourse.julialang.org/u/mfiano)
#### Post date: [August 17, 2022, 8:03am UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/7 "2022-08-17T08:03:21Z")

</div>

Some `@ref` links point to nothing. I think this is due to Documenter.jl being a single-pass “compiler”, and forward references aren’t allowed/not expanded in “See also: …” doc sections. But it could also just be my improper way of writing docs.

Documentation writing is one of my worst qualities.

Edit: @digital_carver began working on this in a PR. Thanks!

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [August 17, 2022, 6:20pm UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/8 "2022-08-17T18:20:42Z")

</div>

It’s awesome!

![output](https://global.discourse-cdn.com/julialang/original/3X/8/f/8f1174fb6e1ced1487a3caa169d0c62a6709c545.gif)

---

<div class="post-metadata">

### Author: ![mfiano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfiano/32/37565_2.png) [@mfiano](https://discourse.julialang.org/u/mfiano)
#### Post date: [August 17, 2022, 6:22pm UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/9 "2022-08-17T18:22:56Z")

</div>

Nice work! You might consider creating a PR to add this to the gallery 🙂

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [August 17, 2022, 6:29pm UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/10 "2022-08-17T18:29:12Z")

</div>

Well, the code is a bit clumsy and I am not yet satisfied with it and the results. You see the rotation and I want to get rid of this… still experimenting 🙂

---

<div class="post-metadata">

### Author: ![mfiano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfiano/32/37565_2.png) [@mfiano](https://discourse.julialang.org/u/mfiano)
#### Post date: [August 17, 2022, 6:30pm UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/11 "2022-08-17T18:30:16Z")

</div>

I’m glad you’re enjoying it!

---

<div class="post-metadata">

### Author: ![mfiano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfiano/32/37565_2.png) [@mfiano](https://discourse.julialang.org/u/mfiano)
#### Post date: [August 17, 2022, 6:37pm UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/12 "2022-08-17T18:37:39Z")

</div>

I’m actually interested in the code, messy or not, on the approach you took to create the animated GIF.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [August 17, 2022, 6:41pm UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/13 "2022-08-17T18:41:34Z")

</div>

Sorry, but I recorded a MiniFB window with OBS and converted the result to gif with ffmpeg 😉

Here is the code:

```julia
#] add https://github.com/mfiano/CoherentNoise.jl

using Luxor
using Colors
using MiniFB
using ColorSchemes
using CoherentNoise
using ThreadPools

struct Window
    c::ReentrantLock
    w::Int
    h::Int
    d::Drawing
    buffer::Matrix{ARGB32}
    function Window(w,h)
        c=ReentrantLock()
        b=zeros(ARGB32, w, h)
        d=Drawing(b)
        origin()
        new(c,w,h,d,b)
    end
end

function window_update_task(win::Window, showFPS=true)
    w=win.w
    h=win.h
    updateCount=0
    startTime=floor(Int, time())
    fps="0"
    sb=zeros(ARGB32, 105, 55)
    window = mfb_open_ex("MiniFB", w, h, MiniFB.WF_RESIZABLE)
    state=MiniFB.STATE_OK
    set_drawing = true
    while state == MiniFB.STATE_OK
        lock(win.c)
        if set_drawing
            currentdrawing(win.d)
            set_drawing = false
        end
        if showFPS
            elapsedTime=floor(Int,time())-startTime
            if elapsedTime > 1
                fps=string(round(Int,updateCount/elapsedTime))
                startTime=floor(Int,time())
                updateCount=0
            end
            sb.=win.buffer[1:105, 1:55]
            @layer begin
                (dx,dy) = Point(0.0, 0.0) - getworldposition(Point(0.0, 0.0);centered=false)
                setcolor(1.0, 0, 0, 0.5)
                fontsize(50)
                text(fps, Point(5+dx, 5+dy), halign=:left, valign = :top)
            end
        end
        state=mfb_update(window,win.buffer)
        if showFPS
            win.buffer[1:105, 1:55].=sb
        end
        unlock(win.c)
        sleep(1.0/120.0)
        updateCount+=1
    end
    println("\nWindow closed\n")
end

const WIDTH = 400
const HEIGHT = 400

win = Window(WIDTH, HEIGHT)

let window=win
   global t_window_update_task
   function t_window_update_task()
       window_update_task(window)
   end
end

spawnbg(t_window_update_task)

rng(sampler::AbstractSampler) = sampler.random_state.rng
function CoherentNoise.gen_image(buffer,
    sampler::S;
    w::Integer=1024,
    h::Integer=1024,
    xbounds::NTuple{2,Float64}=(-1.0, 1.0),
    ybounds::NTuple{2,Float64}=(-1.0, 1.0),
    colorscheme=nothing,
) where {N,S<:AbstractSampler{N}}
    x1, x2 = xbounds
    y1, y2 = ybounds
    xd = (x2 - x1) / w
    yd = (y2 - y1) / h
    zw = rand(rng(sampler), Float64, N - 2) * 1000
    Threads.@threads for x in 1:w
        cx = x * xd + x1
        for y in 1:h
            cy = y * yd + y1
            value = sample(sampler, cx, cy, zw...) * 0.5 + 0.5
            buffer[x, y] = colorscheme !== nothing ? colorscheme[value] : value
        end
    end
end

sampler1 = cache(OpenSimplex{2}(seed=1))
#sampler1 = cache(Constant(seed=1))

ub=10.0
lb=-10.0
rad=1.0

#while true
    for sc in 0.0:0.01:2pi
        #sampler2 = CoherentNoise.Modifiers.rotate(CoherentNoise.Modifiers.scale(OpenSimplex{2}(seed=2),0.8);z=rad)
        sampler2 = CoherentNoise.Modifiers.rotate(OpenSimplex{2}(seed=2);z=3.0+1.5*sin(sc))
        sampler3 = CoherentNoise.Modifiers.rotate(OpenSimplex{2}(seed=3);z=3.0-1.5*cos(sc))
        #println(rad)
        sampler = warp(sampler1;x=sampler2,y=sampler3)
        lock(win.c)
        gen_image(win.buffer,sampler,w=WIDTH,h=HEIGHT,colorscheme=ColorSchemes.terrain,xbounds=(ub,lb),ybounds=(ub,lb))
        unlock(win.c)
        #sleep(0.001)
    end
#end

```

---

<div class="post-metadata">

### Author: ![tfgast](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tfgast/32/38891_2.png) [@tfgast](https://discourse.julialang.org/u/tfgast)
#### Post date: [August 18, 2022, 7:56pm UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/14 "2022-08-18T19:56:04Z")

</div>

The patent on simplex noise [expired](https://en.wikipedia.org/wiki/Simplex_noise#:~:text=Uses%20of%20implementations%20in%203D,expired%20on%20January%208%2C%202022.) in January of this year.

---

<div class="post-metadata">

### Author: ![mfiano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfiano/32/37565_2.png) [@mfiano](https://discourse.julialang.org/u/mfiano)
#### Post date: [August 18, 2022, 10:29pm UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/15 "2022-08-18T22:29:07Z")

</div>

Thanks for the heads up. I updated the documentation to remove the warning.

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [August 18, 2022, 11:46pm UTC](https://discourse.julialang.org/t/announcing-coherentnoise-jl/85860/16 "2022-08-18T23:46:21Z")

</div>

> [@mfiano](#):
>
> Documentation writing is one of my worst qualities.

For my taste it is very nice. Very cool package, and I’m already learning a lot from your questions and contributions on the Zulip chat. Welcome, and thanks!
