|
| 1 | +import Noise |
| 2 | +import MaxPNG |
| 3 | + |
| 4 | +import Tests |
| 5 | + |
| 6 | +import func Glibc.clock |
| 7 | + |
| 8 | +banners(width: 700, ratio: 5) |
| 9 | + |
| 10 | +calibrate_noise(width: 256, height: 256) |
| 11 | + |
| 12 | +var t0:Int |
| 13 | + |
| 14 | +let viewer_size:Int = 1024 |
| 15 | +var pixbuf:[UInt8] |
| 16 | +let png_properties:PNGProperties = PNGProperties(width: viewer_size, height: viewer_size, bit_depth: 8, color: .grayscale, interlaced: false)! |
| 17 | + |
| 18 | +var poisson = DiskSampler2D(seed: 0) |
| 19 | +t0 = clock() |
| 20 | +pixbuf = [UInt8](repeating: 0, count: viewer_size * viewer_size) |
| 21 | +for point:(x:Double, y:Double) in poisson.generate(radius: 10, width: viewer_size, height: viewer_size) |
| 22 | +{ |
| 23 | + pixbuf[Int(point.y) * viewer_size + Int(point.x)] = 255 |
| 24 | +} |
| 25 | +print(clock() - t0) |
| 26 | +try png_encode(path: "tests/disk2d.png", raw_data: pixbuf, properties: png_properties) |
| 27 | + |
| 28 | + |
| 29 | +let V:CellNoise2D = CellNoise2D(amplitude: 255, frequency: 0.01) |
| 30 | +t0 = clock() |
| 31 | +for (i, (x, y)) in Domain2D(samples_x: viewer_size, samples_y: viewer_size).enumerated() |
| 32 | +{ |
| 33 | + pixbuf[i] = UInt8(max(0, min(255, V.evaluate(x, y)))) |
| 34 | +} |
| 35 | +print(clock() - t0) |
| 36 | +try png_encode(path: "tests/cell2d.png", raw_data: pixbuf, properties: png_properties) |
| 37 | + |
| 38 | +let V3:CellNoise3D = CellNoise3D(amplitude: 255, frequency: 0.01) |
| 39 | +t0 = clock() |
| 40 | +for (i, (x, y)) in Domain2D(samples_x: viewer_size, samples_y: viewer_size).enumerated() |
| 41 | +{ |
| 42 | + pixbuf[i] = UInt8(max(0, min(255, V3.evaluate(x, y)))) |
| 43 | +} |
| 44 | +print(clock() - t0) |
| 45 | +try png_encode(path: "tests/cell3d.png", raw_data: pixbuf, properties: png_properties) |
| 46 | + |
| 47 | +let P:FBM<ClassicNoise3D> = FBM<ClassicNoise3D>(ClassicNoise3D(amplitude: 255, frequency: 0.001), octaves: 10, persistence: 0.62) |
| 48 | +t0 = clock() |
| 49 | +for (i, (x, y)) in Domain2D(samples_x: viewer_size, samples_y: viewer_size).enumerated() |
| 50 | +{ |
| 51 | + pixbuf[i] = UInt8(max(0, min(255, P.evaluate(x, y) + 127.5))) |
| 52 | +} |
| 53 | +print(clock() - t0) |
| 54 | +try png_encode(path: "tests/classic3d.png", raw_data: pixbuf, properties: png_properties) |
| 55 | + |
| 56 | + |
| 57 | +let SS:FBM<GradientNoise2D> = FBM<GradientNoise2D>(GradientNoise2D(amplitude: 180, frequency: 0.001), octaves: 10, persistence: 0.62) |
| 58 | +t0 = clock() |
| 59 | +for (i, (x, y)) in Domain2D(samples_x: viewer_size, samples_y: viewer_size).enumerated() |
| 60 | +{ |
| 61 | + pixbuf[i] = UInt8(max(0, min(255, SS.evaluate(x, y) + 127.5))) |
| 62 | +} |
| 63 | +print(clock() - t0) |
| 64 | +try png_encode(path: "tests/gradient2d.png", raw_data: pixbuf, properties: png_properties) |
| 65 | + |
| 66 | +let SS3D:FBM<GradientNoise3D> = FBM<GradientNoise3D>(GradientNoise3D(amplitude: 180, frequency: 0.001), octaves: 10, persistence: 0.62) |
| 67 | +t0 = clock() |
| 68 | +for (i, (x, y)) in Domain2D(samples_x: viewer_size, samples_y: viewer_size).enumerated() |
| 69 | +{ |
| 70 | + pixbuf[i] = UInt8(max(0, min(255, SS3D.evaluate(x, y) + 127.5))) |
| 71 | +} |
| 72 | +print(clock() - t0) |
| 73 | +try png_encode(path: "tests/gradient3d.png", raw_data: pixbuf, properties: png_properties) |
0 commit comments