Skip to content

Commit a91910e

Browse files
committed
move test files into folder, clean up readme
1 parent 0c23c39 commit a91910e

File tree

11 files changed

+13
-96
lines changed

11 files changed

+13
-96
lines changed

Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ let package = Package(
1515
targets: [
1616
.target(
1717
name: "Noise",
18-
dependencies: ["MaxPNG"],
1918
path: "sources/noise"),
2019
.testTarget(
2120
name: "NoiseTests",
22-
dependencies: ["Noise"],
21+
dependencies: ["Noise", "MaxPNG"],
2322
path: "tests/noise"),
2423
]
2524
)

cells.png

-31.3 KB
Binary file not shown.

cells3D.png

-33.2 KB
Binary file not shown.

readme.md

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,12 @@
66
[![License](https://img.shields.io/badge/license-GPL3-ff3079.svg)](https://github.com/kelvin13/noise/blob/master/LICENSE.gpl3)
77
[![Queen](https://img.shields.io/badge/taylor-swift-e030ff.svg)](https://www.google.com/search?q=where+is+ts6&oq=where+is+ts6)
88

9-
*Noise-swift* will eventually be a free, native Swift procedural noise generation library. It will be free of Foundation or any other Apple framework. Currently supported:
9+
![](tests/banner_FBM.png)
1010

11-
* Simplex noise (2D)
11+
**Noise** is a free, pure Swift procedural noise generation library. It is free of Foundation or any other Apple framework, and has no dependencies. All popular types of procedural noise are supported, including three [gradient noises](https://en.wikipedia.org/wiki/Perlin_noise) (often called Perlin or simplex noises), and two [cellular noises](https://en.wikipedia.org/wiki/Worley_noise) (sometimes called Worley or Voronoi noises). *Noise* includes a fractal brownian motion (FBM) noise composition framework, and a [disk point sampler](https://en.wikipedia.org/wiki/Supersampling#Poisson_disc) (often called a Poisson sampler), for generating visually even point distributions in the plane. *Noise* also includes pseudo-random number generation and hashing tools.
1212

13-
Simplex noise is an improved version of the classical [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise) algorithm. Noise-swift uses the OpenSimplex procedural noise generation algorithm, which solves many of the quality issues apparent in the 3D version of the proprietary Simplex noise algorithm, as well as sidestepping potential patent threats.
13+
***Noise*’s entire public API is [documented](wiki).**
1414

15-
* SuperSimplex noise (2D)
15+
## Building
1616

17-
SuperSimplex noise is yet another improvement on Simplex noise that results in even noise with fewer artifacts. SuperSimplex noise also runs slightly (~5%) faster than Simplex noise. Many thanks to the Java and [Rust OpenSimplex communities](https://github.com/brendanzab/noise-rs) for their assistance, which was essential for bringing SuperSimplex procedural noise to Swift.
18-
19-
* SuperSimplex noise (3D)
20-
21-
3D SuperSimplex volumetric noise, suitable for texturing any 3D object without seams or texture unwrapping.
22-
23-
* Voronoi noise (2D)
24-
25-
Also known as Worley noise, produces a cellular, bulby texture.
26-
27-
* Voronoi noise (3D)
28-
29-
3 dimensional cell/worley noise.
30-
31-
* Poisson sample noise (2D)
32-
33-
Two dimensional point noise with a visually uniform distribution, and no clumping.
34-
35-
36-
![](super_simplex3D.png)
37-
![](voronoi3D.png)
38-
![](cells3D.png)
39-
![](poisson.png)
40-
41-
### A note on building
42-
43-
Noise-swift does not actually depend on [maxpng](https://github.com/kelvin13/maxpng), my free Swift PNG library; it is only being used to view the output of the noise generator as a PNG. For similar reasons, this repository currently contains a small Cairo interface library, which will probably be spun-off into a library of its own right once Noise-swift matures.
17+
Build *Noise* with the Swift Package Manager. *Noise* itself has no dependencies, but the tests depend on [MaxPNG](https://github.com/kelvin13/maxpng), my free Swift PNG library, to view the generated noise.

tests/LinuxMain.swift

Lines changed: 7 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import Noise
2-
32
import MaxPNG
43

5-
let viewer_size:Int = 1024
6-
74
import func Glibc.clock
85

96
import NoiseTests
107

118
banners(width: 700, ratio: 5)
129

13-
10+
let viewer_size:Int = 1024
1411
var pixbuf:[UInt8]
1512
let png_properties:PNGProperties = PNGProperties(width: viewer_size, height: viewer_size, bit_depth: 8, color: .grayscale, interlaced: false)!
1613

17-
1814
var t0:Int
1915

2016
var poisson = DiskSampler2D(seed: 0)
@@ -25,90 +21,38 @@ for point:(x:Double, y:Double) in poisson.generate(radius: 10, width: viewer_siz
2521
pixbuf[Int(point.y) * viewer_size + Int(point.x)] = 255
2622
}
2723
print(clock() - t0)
28-
try png_encode(path: "poisson.png", raw_data: pixbuf, properties: png_properties)
24+
try png_encode(path: "tests/disk2d.png", raw_data: pixbuf, properties: png_properties)
2925

3026

3127
let V:CellNoise2D = CellNoise2D(amplitude: 255, frequency: 0.01)
3228
t0 = clock()
3329
pixbuf = V.sample_area_saturated_to_u8(width: viewer_size, height: viewer_size, offset: 0)
3430
print(clock() - t0)
35-
try png_encode(path: "voronoi.png", raw_data: pixbuf, properties: png_properties)
36-
37-
t0 = clock()
38-
try {
39-
let png_color:PNGProperties = PNGProperties(width: viewer_size, height: viewer_size, bit_depth: 8, color: .rgb, interlaced: false)!
40-
var pixbuf_color = [UInt8](repeating: 0, count: viewer_size * viewer_size * 3)
41-
let red:PermutationTable = PermutationTable(seed: 0),
42-
green:PermutationTable = PermutationTable(seed: 1),
43-
blue:PermutationTable = PermutationTable(seed: 2)
31+
try png_encode(path: "tests/cell2d.png", raw_data: pixbuf, properties: png_properties)
4432

45-
var base_addr:Int = 0
46-
for y in 0 ..< viewer_size
47-
{
48-
for x in 0 ..< viewer_size
49-
{
50-
let (point, _):((Int, Int), Double) = V.closest_point(Double(x), Double(y))
51-
pixbuf_color[base_addr ] = red.hash (point.0, point.1)
52-
pixbuf_color[base_addr + 1] = green.hash(point.0, point.1)
53-
pixbuf_color[base_addr + 2] = blue.hash (point.0, point.1)
54-
55-
base_addr += 3
56-
}
57-
}
58-
59-
print(clock() - t0)
60-
61-
try png_encode(path: "cells.png", raw_data: pixbuf_color, properties: png_color)
62-
}()
6333

6434
let V3:CellNoise3D = CellNoise3D(amplitude: 255, frequency: 0.01)
6535
t0 = clock()
6636
pixbuf = V3.sample_area_saturated_to_u8(width: viewer_size, height: viewer_size, offset: 0)
6737
print(clock() - t0)
68-
try png_encode(path: "voronoi3D.png", raw_data: pixbuf, properties: png_properties)
69-
70-
t0 = clock()
71-
try {
72-
let png_color:PNGProperties = PNGProperties(width: viewer_size, height: viewer_size, bit_depth: 8, color: .rgb, interlaced: false)!
73-
var pixbuf_color = [UInt8](repeating: 0, count: viewer_size * viewer_size * 3)
74-
let red:PermutationTable = PermutationTable(seed: 0),
75-
green:PermutationTable = PermutationTable(seed: 1),
76-
blue:PermutationTable = PermutationTable(seed: 2)
77-
78-
var base_addr:Int = 0
79-
for y in 0 ..< viewer_size
80-
{
81-
for x in 0 ..< viewer_size
82-
{
83-
let (point, _):((Int, Int, Int), Double) = V3.closest_point(Double(x), Double(y), 0)
84-
pixbuf_color[base_addr ] = red.hash (point.0, point.1, point.2)
85-
pixbuf_color[base_addr + 1] = green.hash(point.0, point.1, point.2)
86-
pixbuf_color[base_addr + 2] = blue.hash (point.0, point.1, point.2)
87-
88-
base_addr += 3
89-
}
90-
}
91-
92-
print(clock() - t0)
38+
try png_encode(path: "tests/cell3d.png", raw_data: pixbuf, properties: png_properties)
9339

94-
try png_encode(path: "cells3D.png", raw_data: pixbuf_color, properties: png_color)
95-
}()
9640

9741
let S:FBM<SimplexNoise2D> = FBM<SimplexNoise2D>(amplitude: 0.5*127.5, frequency: 0.001, octaves: 10)
9842
t0 = clock()
9943
pixbuf = S.sample_area_saturated_to_u8(width: viewer_size, height: viewer_size, offset: 127.5)
10044
print(clock() - t0)
101-
try png_encode(path: "simplex.png", raw_data: pixbuf, properties: png_properties)
45+
try png_encode(path: "tests/simplex2d.png", raw_data: pixbuf, properties: png_properties)
10246

10347

10448
let SS:FBM<SuperSimplexNoise2D> = FBM<SuperSimplexNoise2D>(amplitude: 0.5*127.5, frequency: 0.001, octaves: 10)
10549
t0 = clock()
10650
pixbuf = SS.sample_area_saturated_to_u8(width: viewer_size, height: viewer_size, offset: 127.5)
10751
print(clock() - t0)
108-
try png_encode(path: "super_simplex.png", raw_data: pixbuf, properties: png_properties)
52+
try png_encode(path: "tests/super_simplex2d.png", raw_data: pixbuf, properties: png_properties)
10953

11054
let SS3D:FBM<SuperSimplexNoise3D> = FBM<SuperSimplexNoise3D>(amplitude: 0.5*127.5, frequency: 0.001, octaves: 10)
11155
t0 = clock()
11256
pixbuf = SS3D.sample_area_saturated_to_u8(width: viewer_size, height: viewer_size, offset: 127.5)
11357
print(clock() - t0)
114-
try png_encode(path: "super_simplex3D.png", raw_data: pixbuf, properties: png_properties)
58+
try png_encode(path: "tests/super_simplex3D.png", raw_data: pixbuf, properties: png_properties)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)