From f70a08146337ce156970282c33123e13e81bdc32 Mon Sep 17 00:00:00 2001 From: Marc Lepage Date: Mon, 23 Sep 2013 08:32:39 -0400 Subject: [PATCH] Update README and format LICENSE --- COPYRIGHT => LICENSE | 4 ++- README | 68 -------------------------------------------- README.md | 63 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 69 deletions(-) rename COPYRIGHT => LICENSE (94%) delete mode 100644 README create mode 100644 README.md diff --git a/COPYRIGHT b/LICENSE similarity index 94% rename from COPYRIGHT rename to LICENSE index c165c29..a3dc771 100644 --- a/COPYRIGHT +++ b/LICENSE @@ -1,4 +1,6 @@ -Copyright (C) 2011 Marc Lepage +The MIT License (MIT) + +Copyright (c) 2011 Marc Lepage Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README b/README deleted file mode 100644 index e203a06..0000000 --- a/README +++ /dev/null @@ -1,68 +0,0 @@ -Heightmap module -by Marc Lepage - - -OVERVIEW - -The heightmap module uses the diamond-square algorithm to generate cloud or -plasma fractal heightmaps which can be used for terrain. - - -USAGE - --- import module -require "heightmap" - --- create 32x32 heightmap -map = heightmap.create(32, 32) - --- examine each height value -for x = 0, map.w do - for y = 0, map.h do - print(map[x][y]) - end -end - --- define a custom height function (reusing the default but scaling it) -function f(map, x, y, d, h) - return 2 * heightmap.defaultf(map, x, y, d, h) -end - --- use it to create a larger non-square heightmap -map = heightmap.create(100, 200, f) - - -HOW IT WORKS - -The heightmap must be a square the size of a power of two, plus one, so that -it can be evenly divided. For example, 4x4 cells will require 5x5 vertices. -If another size is specified, a sufficiently large power of two square will -be used, and the result clipped to the desired size. - -First the four corners are seeded with a random value (C). - -Then each square is used to set the value of its center (S) based on the -average of its four corners (plus some randomness). - -Then each diamond is used to set the value of its center (D) based on the -average of its four points (plus some randomness). - -The square and diamond steps continue until all values have been set: - - 4 S 2 D 2 S 1 D 1 - C...C c...c c.D.c c.d.c cDdDc - ..... ..... ..... .S.S. DsDsD - ..... ..S.. D.s.D d.s.d dDsDd - ..... ..... ..... .S.S. DsDsD - C...C c...c c.D.c c.d.c cDdDc - -The default height function randomly displaces values by up to +/- 0.5 of the -step size. So above, the corners will be from -2 to +2, the center will be -the mean of the corners randomly displaced from -1 to +1, and so on. - - -RESOURCES - -http://en.wikipedia.org/wiki/Diamond-square_algorithm -http://en.wikipedia.org/wiki/Heightmap -http://en.wikipedia.org/wiki/Fractal_landscape diff --git a/README.md b/README.md new file mode 100644 index 0000000..0c05405 --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +Heightmap +========= + +Overview +-------- + +A Lua module by Marc Lepage for producing heightmaps. + +The heightmap module uses the diamond-square algorithm to generate cloud or plasma fractal heightmaps which can be used for terrain. + +Usage +----- + + -- import module + require "heightmap" + + -- create 32x32 heightmap + map = heightmap.create(32, 32) + + -- examine each height value + for x = 0, map.w do + for y = 0, map.h do + print(map[x][y]) + end + end + + -- define a custom height function + -- (reusing the default but scaling it) + function f(map, x, y, d, h) + return 2 * heightmap.defaultf(map, x, y, d, h) + end + + -- use it to create a larger non-square heightmap + map = heightmap.create(100, 200, f) + +How it Works +------------ + +The heightmap must be a square the size of a power of two, plus one, so that it can be evenly divided. For example, 4x4 cells will require 5x5 vertices. If another size is specified, a sufficiently large power of two square will be used, and the result clipped to the desired size. + +First the four corners are seeded with a random value (C). + +Then each square is used to set the value of its center (S) based on the average of its four corners (plus some randomness). + +Then each diamond is used to set the value of its center (D) based on the average of its four points (plus some randomness). + +The square and diamond steps continue until all values have been set: + + 4 S 2 D 2 S 1 D 1 + C...C c...c c.D.c c.d.c cDdDc + ..... ..... ..... .S.S. DsDsD + ..... ..S.. D.s.D d.s.d dDsDd + ..... ..... ..... .S.S. DsDsD + C...C c...c c.D.c c.d.c cDdDc + +The default height function randomly displaces values by up to +/- 0.5 of the step size. So above, the corners will be from -2 to +2, the center will be the mean of the corners randomly displaced from -1 to +1, and so on. + +Resources +--------- + +* [Wikipedia: heightmap](http://en.wikipedia.org/wiki/Heightmap) +* [Wikipedia: diamond-square algorithm](http://en.wikipedia.org/wiki/Diamond-square_algorithm) +* [Wikipedia: fractal landscape](http://en.wikipedia.org/wiki/Fractal_landscape)