<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Diamond-square_algorithm</id>
	<title>Diamond-square algorithm - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Diamond-square_algorithm"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Diamond-square_algorithm&amp;action=history"/>
	<updated>2026-05-05T02:40:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Diamond-square_algorithm&amp;diff=2255848&amp;oldid=prev</id>
		<title>imported&gt;Bearcat: /* top */ dabfix</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Diamond-square_algorithm&amp;diff=2255848&amp;oldid=prev"/>
		<updated>2025-04-13T18:16:52Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;top: &lt;/span&gt; dabfix&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{short description|Method for generating heightmaps for computer graphics}}&lt;br /&gt;
[[Image:Plasmafractal.gif|200px|right|thumb|Plasma fractal]]&lt;br /&gt;
[[File:-PLASMA-ColorCycling.Gif|200px|thumb|right|Animated plasma fractal with [[color cycling]]]]&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;diamond-square algorithm&amp;#039;&amp;#039;&amp;#039; is a method for generating [[heightmap]]s for [[computer graphics]]. It is a slightly better algorithm than the three-dimensional implementation of the midpoint displacement algorithm, which produces two-dimensional landscapes.  It is also known as the &amp;#039;&amp;#039;&amp;#039;random midpoint displacement fractal&amp;#039;&amp;#039;&amp;#039;, the &amp;#039;&amp;#039;&amp;#039;cloud fractal&amp;#039;&amp;#039;&amp;#039; or the &amp;#039;&amp;#039;&amp;#039;plasma fractal&amp;#039;&amp;#039;&amp;#039;, because of the [[plasma effect]] produced when applied.&lt;br /&gt;
&lt;br /&gt;
The idea was first introduced by [[Alain Fournier (academic)|Fournier]], [[Don Fussell|Fussell]] and [[Loren Carpenter|Carpenter]] at [[SIGGRAPH]] in 1982.&amp;lt;ref name=fournier&amp;gt;{{Cite journal |last1=Fournier |first1=Alain |last2=Fussell |first2=Don |last3=Carpenter |first3=Loren |date=June 1982 |title=Computer rendering of stochastic models |journal=Communications of the ACM |volume=25 |issue=6 |pages=371–384 |doi=10.1145/358523.358553 |issn=0001-0782|doi-access=free }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The diamond-square algorithm starts with a two-dimensional grid, then [[terrain generation|randomly generates terrain height]] from four seed values arranged in a grid of points so that the entire plane is covered in squares.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The diamond-square algorithm begins with a two-dimensional square array of width and height 2&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt; + 1.  The four corner points of the array must first be set to initial values.&lt;br /&gt;
The diamond and square steps are then performed alternately until all array values have been set.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The diamond step:&amp;#039;&amp;#039;&amp;#039; For each square in the array, set the midpoint of that square to be the average of the four corner points plus a random value.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The square step:&amp;#039;&amp;#039;&amp;#039; For each diamond in the array, set the midpoint of that diamond to be the average of the four corner points plus a random value.&lt;br /&gt;
&lt;br /&gt;
Each random value is multiplied by a scale constant, which decreases with each iteration by a factor of 2&amp;lt;sup&amp;gt;−h&amp;lt;/sup&amp;gt;, where h is a value between 0.0 and 1.0 (lower values produce rougher terrain).&amp;lt;ref&amp;gt;{{Cite web |date=2006-04-20 |title=Generating Random Fractal Terrain |url=http://www.gameprogrammer.com/fractal.html#diamond |access-date=2022-12-13 |archive-url=https://web.archive.org/web/20060420054134/http://www.gameprogrammer.com/fractal.html#diamond |archive-date=2006-04-20 }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
During the square steps, points located on the edges of the array will have only three adjacent values set, rather than four.  There are a number of ways to handle this complication - the simplest being to take the average of just the three adjacent values.  Another option is to &amp;#039;wrap around&amp;#039;, taking the fourth value from the other side of the array.  When used with consistent initial corner values, this method also allows generated fractals to be stitched together without discontinuities.&lt;br /&gt;
&lt;br /&gt;
==Visualization==&lt;br /&gt;
The image below shows the steps involved in running the diamond-square algorithm on a 5 × 5 array.&lt;br /&gt;
&lt;br /&gt;
[[File:Diamond Square.svg|800px|Visualization of the Diamond Square Algorithm]]&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
This [[algorithm]] can be used to generate realistic-looking [[Fractal landscape|landscapes]], and different implementations are used in computer graphics software such as [[Terragen]]. It is also applicable as a common component in [[procedural textures]].&lt;br /&gt;
&lt;br /&gt;
==Artifacts and extensions==&lt;br /&gt;
&lt;br /&gt;
The diamond-square algorithm was analyzed by [[Gavin S. P. Miller]] in SIGGRAPH 1986&amp;lt;ref name=miller&amp;gt;{{cite journal|last=Miller|first=Gavin S. P.|title=The definition and rendering of terrain maps|journal=ACM SIGGRAPH Computer Graphics|date=August 1986|volume=20|issue=4|pages=39–48|doi=10.1145/15886.15890}}&amp;lt;!--|accessdate=3 November 2011--&amp;gt;&amp;lt;/ref&amp;gt; who described it as flawed because the algorithm produces noticeable vertical and horizontal &amp;quot;creases&amp;quot; due to the most significant perturbation taking place in a rectangular grid. The grid artifacts were addressed in a generalized algorithm introduced by J.P. Lewis.&amp;lt;ref&amp;gt;{{cite journal|last1=Lewis|first1=J. P.|title=Generalized stochastic subdivision|journal=ACM Transactions on Graphics|date=1 July 1987|volume=6|issue=3|pages=167–190|doi=10.1145/35068.35069|citeseerx=10.1.1.21.3719|s2cid=14994949 }}&amp;lt;/ref&amp;gt; In this variant the weights on the neighboring points are obtained by solving&lt;br /&gt;
a small linear system motivated by estimation theory, rather than being fixed. The Lewis algorithm also allows the synthesis of non-fractal heightmaps such as rolling hills or ocean waves.&lt;br /&gt;
Similar results can be efficiently obtained with Fourier synthesis,&amp;lt;ref name=PeitgenSaupe&amp;gt;{{cite book|last1=Peitgen|first1=Heinz-Otto, Dietmar Saupe|title=The Science of Fractal Images|date=1988|publisher=Springer-Verlag|location=New York|isbn=978-0-387-96608-3|url-access=registration|url=https://archive.org/details/scienceoffractal0000unse}}&amp;lt;/ref&amp;gt; although the possibility of adaptive refinement is lost. The diamond-square algorithm and its refinements are reviewed in Peitgen and Saupe&amp;#039;s book &amp;quot;The Science of Fractal Images&amp;quot;.&amp;lt;ref name=PeitgenSaupe /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* [https://github.com/mlepage/heightmap Simple open source heightmap module for Lua] using diamond-square algorithm&lt;br /&gt;
* [https://web.archive.org/web/20060420054134/http://www.gameprogrammer.com/fractal.html#diamond Generating Random Fractal Terrain: The Diamond-Square Algorithm] from [http://www.gameprogrammer.com/ GameProgrammer.com]&lt;br /&gt;
* [http://www.ic.sunysb.edu/Stu/jseyster/plasma/ Plasma Fractal] from Justin Seyster&amp;#039;s web page&lt;br /&gt;
* [http://www2.vo.lu/homepages/phahn/fractals/plasma.htm Plasma fractals] from Patrick Hahn&amp;#039;s home page&lt;br /&gt;
* [http://www.lighthouse3d.com/opengl/terrain/index.php?mpd2 Terrain Tutorial] from Lighthouse3d.com&lt;br /&gt;
* [http://www.somethinghitme.com/2009/12/06/terrain-generation-with-canvas-and-javascript/ Random Midpoint Displacement with Canvas]&lt;br /&gt;
* [http://www.cescg.org/CESCG97/marak/node3.html Random midpoint displacement method]&lt;br /&gt;
* [https://github.com/A1essandro/Diamond-And-Square Diamond And Square] algorithm on [https://github.com/ Github] (PHP)&lt;br /&gt;
* [http://blog.cleancoder.com/uncle-bob/2017/01/09/DiamondSquare.html An example] of [[Test-driven development|test-driving]] an implementation of the algorithm on [[Robert Cecil Martin|Uncle Bob]]&amp;#039;s [http://blog.cleancoder.com/ Clean Coder blog]&lt;br /&gt;
* [https://spbooth.github.io/xmountains/ Xmountains] classic sideways scrolling X11 implementation. [https://spbooth.github.io/xmountains/about_xmountains.html Algorithm details].&lt;br /&gt;
* [https://janert.me/blog/2022/the-diamond-square-algorithm-for-terrain-generation/ A Python implementation], short and straightforward. Handles both fixed and periodic boundary conditions.&lt;br /&gt;
&lt;br /&gt;
[[Category:Fractals]]&lt;br /&gt;
[[Category:Computer graphics algorithms]]&lt;br /&gt;
[[Category:Procedural generation]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Bearcat</name></author>
	</entry>
</feed>