~~NOTOC~~ ====== Worley Noise ======
{{:article:worley_simple.png?150|}} 2D Worley noise
**Worley noise** (also called Voronoi noise) is a [[article:noise|noise]] function first proposed by Steven Worley in 1996. Worley noise is an extension of the [[article:voronoi_diagram|Voronoi diagram]] that, for each coordinate, returns a real value corresponding to the distance of the $n$th nearest site. ==== Creating Worley noise (Processing) ==== Processing is a Java-based IDE that requires minimal setup to get images onto the screen. Processing is free to download at [[https://processing.org|processing.org]]. === Setup === void setup(){ size(500,500); background(100); } void draw(){ loadPixels(); updatePixels(); } The ''setup()'' function is called once. In it, the canvas size is set to 500 by 500 pixels on the $x$ and $y$ axes, respectively. The ''background()'' function sets the background colour of the canvas. In this case, the background colour has been set to $(100,100,100)$, just grey. The ''draw()'' function has been created for later. It is called repeatedly, and for now, it ''loadPixels()'' to get data from the canvas into the ''pixels[]'' array, and it ''updatePixels()'' to update the canvas with data from the ''pixels[]'' array. The result of this code should be a static grey canvas. \\ \\ === Creating a grid (optional) === A naive approach to Worley noise would be to iterate over each site for each canvas pixel. Each canvas pixel must be processed; that is inevitable. However, we can use optimizations to minimize the number of sites we must process per-pixel. The optimization involves a grid-based approach where each grid cell has a fixed number of sites. In the code below, a 6x6 grid is used to plot 36 sites (1 site/cell). PVector[] sites; void setup(){ size(500,500); background(100); sites = new PVector[36]; // plot loops here } \\ \\ === Plotting points === \\ \\ === Calculating distance === \\ \\ ==== See also ==== * [[article:computer_graphics|Computer graphics]] * [[article:noise|Noise]]