phallic-noise 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ Zero-Clause BSD
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for
4
+ any purpose with or without fee is hereby granted.
5
+
6
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
7
+ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
8
+ OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
9
+ FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
10
+ DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
11
+ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
12
+ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1 @@
1
+ include examples/terrain.py
@@ -0,0 +1,100 @@
1
+ Metadata-Version: 2.4
2
+ Name: phallic-noise
3
+ Version: 0.1.1
4
+ Summary: Seeded 2D Perlin terrain with a strong bias toward phallic landforms
5
+ License-Expression: 0BSD
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # phallic-noise
12
+
13
+ `phallic-noise` generates 2D height maps with a bias toward phallic landforms. Each seed changes the landform’s position, size, angle, and proportions. Perlin noise bends the outline and varies the surrounding lowlands.
14
+
15
+ ## Installation
16
+
17
+ Requires Python 3.9 or newer. The package has no runtime dependencies.
18
+
19
+ ```sh
20
+ python -m pip install phallic-noise
21
+ ```
22
+
23
+ To install from a source checkout, run `python -m pip install .` in the project directory.
24
+
25
+ ## Generate a map
26
+
27
+ ```python
28
+ from phallic_noise import generate
29
+
30
+ heights = generate(width=64, height=48, seed=7)
31
+ height_at_x_10_y_5 = heights[5][10]
32
+ ```
33
+
34
+ `generate(width=64, height=48, *, seed=None, bias=0.88)` returns `height` rows of `width` floats, each from `0.0` to `1.0`. Index the result as `heights[y][x]`.
35
+
36
+ | Parameter | Default | Meaning |
37
+ | --- | --- | --- |
38
+ | `width` | `64` | Number of columns. Use a positive integer. |
39
+ | `height` | `48` | Number of rows. Use a positive integer. |
40
+ | `seed` | `None` | Pass an integer to reproduce a map with the same package version and settings. Omit it for a fresh map on each call. |
41
+ | `bias` | `0.88` | Weight of the landform, from `0.0` to `1.0`. Use `0.0` for plain Perlin terrain or `1.0` for a stronger outline that still has some bends. |
42
+
43
+ `bias` controls the blend between the landform and the noise. At small grid sizes, individual tiles can obscure the outline. Start with the default dimensions if the shape matters to your renderer.
44
+
45
+ ### Convert heights to terrain tiles
46
+
47
+ Run the terrain example from the source directory to draw a 48 × 36 map with a sandy island in slate-blue water. The palette switches from water to land at height `0.5` to make the outline clear. Open `terrain.svg` in a browser to see the result.
48
+
49
+ ```sh
50
+ python examples/terrain.py --seed 183 --output terrain.svg
51
+ ```
52
+
53
+ For a tile map that expects integer heights from `0` to `9`, scale the output before applying your terrain rules:
54
+
55
+ ```python
56
+ from phallic_noise import generate
57
+
58
+ heights = generate(width=48, height=36, seed=183, bias=0.84)
59
+ levels = [[round(value * 9) for value in row] for row in heights]
60
+
61
+
62
+ def terrain(level):
63
+ if level <= 1:
64
+ return "water"
65
+ if level >= 6:
66
+ return "mountain"
67
+ return "grass"
68
+
69
+
70
+ tiles = [[terrain(level) for level in row] for row in levels]
71
+ ```
72
+
73
+ ## Sample raw Perlin noise
74
+
75
+ Use `PerlinNoise(seed=None)` to sample the underlying signed gradient noise at any finite two-dimensional coordinate. Fractional coordinates sample between the integer grid points, where the noise is zero.
76
+
77
+ ```python
78
+ from phallic_noise import PerlinNoise
79
+
80
+ noise = PerlinNoise(seed=7)
81
+ value = noise(0.25, -0.75)
82
+ ```
83
+
84
+ ## Terminal preview
85
+
86
+ ```sh
87
+ phallic-noise --seed 41 --width 24 --height 20
88
+ ```
89
+
90
+ The command defaults to 40 columns and 28 rows. It leaves values below `0.5` blank and uses denser characters for higher terrain. Pass `--bias 0` to preview plain Perlin terrain. Run `python -m phallic_noise` if you prefer the module entry point.
91
+
92
+ ## How the map is built
93
+
94
+ The generator rotates and places a rounded ridge with two mounds, then uses two noise samples to bend the outline. It blends that shape with a separate noise sample for terrain detail and clips the final values to `0.0`–`1.0`. The sampler uses the fade curve from Ken Perlin’s reference. [Improved Noise](https://mrl.cs.nyu.edu/~perlin/noise/)
95
+
96
+ ## License
97
+
98
+ Zero-Clause BSD (`0BSD`). You can use, modify, and share the code, including in commercial projects. Credit is optional. [License text](https://opensource.org/license/0bsd)
99
+
100
+ If you make something with `phallic-noise`, I’d love to see it. Mention the package by name when you share your map, game, or experiment so other people can find it too.
@@ -0,0 +1,90 @@
1
+ # phallic-noise
2
+
3
+ `phallic-noise` generates 2D height maps with a bias toward phallic landforms. Each seed changes the landform’s position, size, angle, and proportions. Perlin noise bends the outline and varies the surrounding lowlands.
4
+
5
+ ## Installation
6
+
7
+ Requires Python 3.9 or newer. The package has no runtime dependencies.
8
+
9
+ ```sh
10
+ python -m pip install phallic-noise
11
+ ```
12
+
13
+ To install from a source checkout, run `python -m pip install .` in the project directory.
14
+
15
+ ## Generate a map
16
+
17
+ ```python
18
+ from phallic_noise import generate
19
+
20
+ heights = generate(width=64, height=48, seed=7)
21
+ height_at_x_10_y_5 = heights[5][10]
22
+ ```
23
+
24
+ `generate(width=64, height=48, *, seed=None, bias=0.88)` returns `height` rows of `width` floats, each from `0.0` to `1.0`. Index the result as `heights[y][x]`.
25
+
26
+ | Parameter | Default | Meaning |
27
+ | --- | --- | --- |
28
+ | `width` | `64` | Number of columns. Use a positive integer. |
29
+ | `height` | `48` | Number of rows. Use a positive integer. |
30
+ | `seed` | `None` | Pass an integer to reproduce a map with the same package version and settings. Omit it for a fresh map on each call. |
31
+ | `bias` | `0.88` | Weight of the landform, from `0.0` to `1.0`. Use `0.0` for plain Perlin terrain or `1.0` for a stronger outline that still has some bends. |
32
+
33
+ `bias` controls the blend between the landform and the noise. At small grid sizes, individual tiles can obscure the outline. Start with the default dimensions if the shape matters to your renderer.
34
+
35
+ ### Convert heights to terrain tiles
36
+
37
+ Run the terrain example from the source directory to draw a 48 × 36 map with a sandy island in slate-blue water. The palette switches from water to land at height `0.5` to make the outline clear. Open `terrain.svg` in a browser to see the result.
38
+
39
+ ```sh
40
+ python examples/terrain.py --seed 183 --output terrain.svg
41
+ ```
42
+
43
+ For a tile map that expects integer heights from `0` to `9`, scale the output before applying your terrain rules:
44
+
45
+ ```python
46
+ from phallic_noise import generate
47
+
48
+ heights = generate(width=48, height=36, seed=183, bias=0.84)
49
+ levels = [[round(value * 9) for value in row] for row in heights]
50
+
51
+
52
+ def terrain(level):
53
+ if level <= 1:
54
+ return "water"
55
+ if level >= 6:
56
+ return "mountain"
57
+ return "grass"
58
+
59
+
60
+ tiles = [[terrain(level) for level in row] for row in levels]
61
+ ```
62
+
63
+ ## Sample raw Perlin noise
64
+
65
+ Use `PerlinNoise(seed=None)` to sample the underlying signed gradient noise at any finite two-dimensional coordinate. Fractional coordinates sample between the integer grid points, where the noise is zero.
66
+
67
+ ```python
68
+ from phallic_noise import PerlinNoise
69
+
70
+ noise = PerlinNoise(seed=7)
71
+ value = noise(0.25, -0.75)
72
+ ```
73
+
74
+ ## Terminal preview
75
+
76
+ ```sh
77
+ phallic-noise --seed 41 --width 24 --height 20
78
+ ```
79
+
80
+ The command defaults to 40 columns and 28 rows. It leaves values below `0.5` blank and uses denser characters for higher terrain. Pass `--bias 0` to preview plain Perlin terrain. Run `python -m phallic_noise` if you prefer the module entry point.
81
+
82
+ ## How the map is built
83
+
84
+ The generator rotates and places a rounded ridge with two mounds, then uses two noise samples to bend the outline. It blends that shape with a separate noise sample for terrain detail and clips the final values to `0.0`–`1.0`. The sampler uses the fade curve from Ken Perlin’s reference. [Improved Noise](https://mrl.cs.nyu.edu/~perlin/noise/)
85
+
86
+ ## License
87
+
88
+ Zero-Clause BSD (`0BSD`). You can use, modify, and share the code, including in commercial projects. Credit is optional. [License text](https://opensource.org/license/0bsd)
89
+
90
+ If you make something with `phallic-noise`, I’d love to see it. Mention the package by name when you share your map, game, or experiment so other people can find it too.
@@ -0,0 +1,43 @@
1
+ import argparse
2
+ from pathlib import Path
3
+
4
+ from phallic_noise import generate
5
+
6
+
7
+ WIDTH, HEIGHT = 48, 36
8
+ BIAS = 0.84
9
+ PALETTE = (
10
+ "#4f6974", "#5c7680", "#6b838a", "#738e94", "#7d999d",
11
+ "#c0b29a", "#cab89f", "#d2b69a", "#d0aa90", "#c9977f",
12
+ )
13
+
14
+
15
+ def tile_color(height):
16
+ level = min(len(PALETTE) - 1, int(height * len(PALETTE)))
17
+ return PALETTE[level]
18
+
19
+
20
+ def main():
21
+ parser = argparse.ArgumentParser(description="Draw a terrain map as an SVG.")
22
+ parser.add_argument("--seed", type=int, default=183)
23
+ parser.add_argument("--output", type=Path, default=Path("terrain.svg"))
24
+ args = parser.parse_args()
25
+
26
+ heights = generate(WIDTH, HEIGHT, seed=args.seed, bias=BIAS)
27
+ tiles = [
28
+ '<svg xmlns="http://www.w3.org/2000/svg" width="672" height="504" '
29
+ f'viewBox="0 0 {WIDTH} {HEIGHT}" shape-rendering="crispEdges">',
30
+ f"<title>Terrain generated from seed {args.seed}</title>",
31
+ ]
32
+ for y, row in enumerate(heights):
33
+ for x, value in enumerate(row):
34
+ color = tile_color(value)
35
+ tiles.append(f'<rect x="{x}" y="{y}" width="1" height="1" fill="{color}"/>')
36
+
37
+ tiles.append("</svg>")
38
+ args.output.write_text("\n".join(tiles) + "\n", encoding="utf-8")
39
+ print(f"Wrote {args.output}")
40
+
41
+
42
+ if __name__ == "__main__":
43
+ main()
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "phallic-noise"
7
+ version = "0.1.1"
8
+ description = "Seeded 2D Perlin terrain with a strong bias toward phallic landforms"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "0BSD"
12
+ license-files = ["LICENSE"]
13
+ dependencies = []
14
+
15
+ [project.scripts]
16
+ phallic-noise = "phallic_noise.__main__:main"
17
+
18
+ [tool.setuptools.packages.find]
19
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,92 @@
1
+ import math
2
+ import random
3
+
4
+
5
+ def _fade(t):
6
+ return t**3 * (t * (6 * t - 15) + 10)
7
+
8
+
9
+ def _blend(a, b, weight):
10
+ return a + (b - a) * weight
11
+
12
+
13
+ class PerlinNoise:
14
+ """A seeded, two-dimensional gradient noise sampler."""
15
+
16
+ def __init__(self, seed=None):
17
+ self.seed = random.Random(seed).getrandbits(64)
18
+ self._gradients = {}
19
+
20
+ def _corner(self, x, y, dx, dy):
21
+ if (x, y) not in self._gradients:
22
+ angle = random.Random(f"{self.seed}:{x}:{y}").uniform(0, math.tau)
23
+ self._gradients[x, y] = (math.cos(angle), math.sin(angle))
24
+
25
+ gx, gy = self._gradients[x, y]
26
+ return gx * dx + gy * dy
27
+
28
+ def __call__(self, x, y):
29
+ left, top = math.floor(x), math.floor(y)
30
+ dx, dy = x - left, y - top
31
+ top_left = self._corner(left, top, dx, dy)
32
+ top_right = self._corner(left + 1, top, dx - 1, dy)
33
+ bottom_left = self._corner(left, top + 1, dx, dy - 1)
34
+ bottom_right = self._corner(left + 1, top + 1, dx - 1, dy - 1)
35
+
36
+ top_value = _blend(top_left, top_right, _fade(dx))
37
+ bottom_value = _blend(bottom_left, bottom_right, _fade(dx))
38
+ return _blend(top_value, bottom_value, _fade(dy))
39
+
40
+
41
+ def _landform(x, y, length, width, left_radius, right_radius):
42
+ # A rounded ridge, a wider tip, and two joined mounds at the base.
43
+ nearest_y = min(1.2, max(-length, y))
44
+ shaft = math.hypot(x, y - nearest_y) - width
45
+ tip = math.hypot(x, y + length) - width * 1.18
46
+ left = math.hypot(x + 0.69, y - 1.25) - left_radius
47
+ right = math.hypot(x - 0.69, y - 1.25) - right_radius
48
+ return min(shaft, tip, left, right)
49
+
50
+
51
+ def generate(width=64, height=48, *, seed=None, bias=0.88):
52
+ """Return a row-major height map with values between zero and one."""
53
+ if width < 1 or height < 1:
54
+ raise ValueError("width and height must be positive")
55
+ if not 0 <= bias <= 1:
56
+ raise ValueError("bias must be between zero and one")
57
+
58
+ rng = random.Random(seed)
59
+ noise = PerlinNoise(rng.getrandbits(64))
60
+ span = min(width, height)
61
+ radius = span * rng.uniform(0.13, 0.17)
62
+ angle = rng.uniform(0, math.tau)
63
+ cosine, sine = math.cos(angle), math.sin(angle)
64
+ center_x = (width - 1) / 2 + span * rng.uniform(-0.06, 0.06)
65
+ center_y = (height - 1) / 2 + span * rng.uniform(-0.06, 0.06)
66
+ noise_scale = span / rng.uniform(4, 7)
67
+ ridge_length = rng.uniform(1.25, 1.7)
68
+ ridge_width = rng.uniform(0.52, 0.73)
69
+ left_radius = rng.uniform(0.76, 0.95)
70
+ right_radius = rng.uniform(0.76, 0.95)
71
+
72
+ rows = []
73
+ for y in range(height):
74
+ row = []
75
+ for x in range(width):
76
+ dx, dy = (x - center_x) / radius, (y - center_y) / radius
77
+ across = dx * cosine + dy * sine
78
+ along = -dx * sine + dy * cosine
79
+ noise_x, noise_y = x / noise_scale, y / noise_scale
80
+
81
+ # Use two noise samples to bend the outline in both directions
82
+ across += 0.75 * noise(noise_x * 0.6 + 17, noise_y * 0.6)
83
+ along += 0.60 * noise(noise_x * 0.6, noise_y * 0.6 + 23)
84
+ landform = -_landform(across, along, ridge_length, ridge_width, left_radius, right_radius) / 2
85
+
86
+ detail = noise(noise_x, noise_y)
87
+ height_value = 0.5 + bias * landform + (1 - bias) * detail
88
+ lowland = 0.5 - 0.42 * bias + (1 - 0.75 * bias) * detail
89
+ row.append(max(0.0, min(1.0, max(height_value, lowland))))
90
+ rows.append(row)
91
+
92
+ return rows
@@ -0,0 +1,32 @@
1
+ import argparse
2
+
3
+ from . import generate
4
+
5
+
6
+ def main():
7
+ parser = argparse.ArgumentParser(description="Preview a seeded phallic height map.")
8
+ parser.add_argument("--width", type=int, default=40)
9
+ parser.add_argument("--height", type=int, default=28)
10
+ parser.add_argument("--seed", type=int)
11
+ parser.add_argument("--bias", type=float, default=0.88)
12
+ args = parser.parse_args()
13
+
14
+ try:
15
+ rows = generate(args.width, args.height, seed=args.seed, bias=args.bias)
16
+ except ValueError as error:
17
+ parser.error(str(error))
18
+
19
+ shades = " ..:-=+*#%@"
20
+ for row in rows:
21
+ line = []
22
+ for value in row:
23
+ if value < 0.5:
24
+ line.append(" ")
25
+ else:
26
+ shade = round(value * (len(shades) - 1))
27
+ line.append(shades[shade] * 2)
28
+ print("".join(line).rstrip())
29
+
30
+
31
+ if __name__ == "__main__":
32
+ main()
@@ -0,0 +1,100 @@
1
+ Metadata-Version: 2.4
2
+ Name: phallic-noise
3
+ Version: 0.1.1
4
+ Summary: Seeded 2D Perlin terrain with a strong bias toward phallic landforms
5
+ License-Expression: 0BSD
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # phallic-noise
12
+
13
+ `phallic-noise` generates 2D height maps with a bias toward phallic landforms. Each seed changes the landform’s position, size, angle, and proportions. Perlin noise bends the outline and varies the surrounding lowlands.
14
+
15
+ ## Installation
16
+
17
+ Requires Python 3.9 or newer. The package has no runtime dependencies.
18
+
19
+ ```sh
20
+ python -m pip install phallic-noise
21
+ ```
22
+
23
+ To install from a source checkout, run `python -m pip install .` in the project directory.
24
+
25
+ ## Generate a map
26
+
27
+ ```python
28
+ from phallic_noise import generate
29
+
30
+ heights = generate(width=64, height=48, seed=7)
31
+ height_at_x_10_y_5 = heights[5][10]
32
+ ```
33
+
34
+ `generate(width=64, height=48, *, seed=None, bias=0.88)` returns `height` rows of `width` floats, each from `0.0` to `1.0`. Index the result as `heights[y][x]`.
35
+
36
+ | Parameter | Default | Meaning |
37
+ | --- | --- | --- |
38
+ | `width` | `64` | Number of columns. Use a positive integer. |
39
+ | `height` | `48` | Number of rows. Use a positive integer. |
40
+ | `seed` | `None` | Pass an integer to reproduce a map with the same package version and settings. Omit it for a fresh map on each call. |
41
+ | `bias` | `0.88` | Weight of the landform, from `0.0` to `1.0`. Use `0.0` for plain Perlin terrain or `1.0` for a stronger outline that still has some bends. |
42
+
43
+ `bias` controls the blend between the landform and the noise. At small grid sizes, individual tiles can obscure the outline. Start with the default dimensions if the shape matters to your renderer.
44
+
45
+ ### Convert heights to terrain tiles
46
+
47
+ Run the terrain example from the source directory to draw a 48 × 36 map with a sandy island in slate-blue water. The palette switches from water to land at height `0.5` to make the outline clear. Open `terrain.svg` in a browser to see the result.
48
+
49
+ ```sh
50
+ python examples/terrain.py --seed 183 --output terrain.svg
51
+ ```
52
+
53
+ For a tile map that expects integer heights from `0` to `9`, scale the output before applying your terrain rules:
54
+
55
+ ```python
56
+ from phallic_noise import generate
57
+
58
+ heights = generate(width=48, height=36, seed=183, bias=0.84)
59
+ levels = [[round(value * 9) for value in row] for row in heights]
60
+
61
+
62
+ def terrain(level):
63
+ if level <= 1:
64
+ return "water"
65
+ if level >= 6:
66
+ return "mountain"
67
+ return "grass"
68
+
69
+
70
+ tiles = [[terrain(level) for level in row] for row in levels]
71
+ ```
72
+
73
+ ## Sample raw Perlin noise
74
+
75
+ Use `PerlinNoise(seed=None)` to sample the underlying signed gradient noise at any finite two-dimensional coordinate. Fractional coordinates sample between the integer grid points, where the noise is zero.
76
+
77
+ ```python
78
+ from phallic_noise import PerlinNoise
79
+
80
+ noise = PerlinNoise(seed=7)
81
+ value = noise(0.25, -0.75)
82
+ ```
83
+
84
+ ## Terminal preview
85
+
86
+ ```sh
87
+ phallic-noise --seed 41 --width 24 --height 20
88
+ ```
89
+
90
+ The command defaults to 40 columns and 28 rows. It leaves values below `0.5` blank and uses denser characters for higher terrain. Pass `--bias 0` to preview plain Perlin terrain. Run `python -m phallic_noise` if you prefer the module entry point.
91
+
92
+ ## How the map is built
93
+
94
+ The generator rotates and places a rounded ridge with two mounds, then uses two noise samples to bend the outline. It blends that shape with a separate noise sample for terrain detail and clips the final values to `0.0`–`1.0`. The sampler uses the fade curve from Ken Perlin’s reference. [Improved Noise](https://mrl.cs.nyu.edu/~perlin/noise/)
95
+
96
+ ## License
97
+
98
+ Zero-Clause BSD (`0BSD`). You can use, modify, and share the code, including in commercial projects. Credit is optional. [License text](https://opensource.org/license/0bsd)
99
+
100
+ If you make something with `phallic-noise`, I’d love to see it. Mention the package by name when you share your map, game, or experiment so other people can find it too.
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ examples/terrain.py
6
+ src/phallic_noise/__init__.py
7
+ src/phallic_noise/__main__.py
8
+ src/phallic_noise.egg-info/PKG-INFO
9
+ src/phallic_noise.egg-info/SOURCES.txt
10
+ src/phallic_noise.egg-info/dependency_links.txt
11
+ src/phallic_noise.egg-info/entry_points.txt
12
+ src/phallic_noise.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ phallic-noise = phallic_noise.__main__:main
@@ -0,0 +1 @@
1
+ phallic_noise