-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Perlin Noise</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
<link rel="icon" href="data:image/png;base64,AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////////////////////8AAD//AAAf/wAAD/8AAA4xB/4OMQf8DgEAAA8DAAAfAQAAGAAAABgAB/wMCAf8D4cAAB+HAAAfzwAAP/8AAH////////////////////////////////////////////8="> | ||
</head> | ||
<body> | ||
<h1>Perlin Noise</h1> | ||
<div id="image-container"> | ||
<fieldset class="settings-container"> | ||
<legend style="color:black;font-weight:bold;font-family:sans-serif;">Settings</legend> | ||
<div class="amplitude-slider"> | ||
<label for="amplitude-range"><code>amplitude: </code></label> | ||
<input type="range" min="0" max="10" value="1" step="0.1" class="slider" id="amplitude-range"> | ||
<label for="amplitude-range"><code><span id="amplitude"></span></code></label> | ||
</div> | ||
<div class="frequency-slider"> | ||
<label for="frequency-range"><code>frequency: </code></label> | ||
<input type="range" min="0" max="100" value="1" step="0.1" class="slider" id="frequency-range"> | ||
<label for="frequency-range"><code><span id="frequency"></span></code></label> | ||
</div> | ||
<div class="octaves-slider"> | ||
<label for="octaves-range"><code>octaves: </code></label> | ||
<input type="range" min="0" max="16" value="1" step="1" class="slider" id="octaves-range"> | ||
<label for="octaves-range"><code><span id="octaves"></span></code></label> | ||
</div> | ||
<div class="persistence-slider"> | ||
<label for="persistence-range"><code>persistence:</code></label> | ||
<input type="range" min="0" max="1" value="0.5" step="0.1" class="slider" id="persistence-range"> | ||
<label for="persistence-range"><code><span id="persistence"></span></code></label> | ||
</div> | ||
<div class="lacunarity-slider"> | ||
<label for="lacunarity-range"><code>lacunarity: </code></label> | ||
<input type="range" min="0" max="10" value="2" step="0.1" class="slider" id="lacunarity-range"> | ||
<label for="lacunarity-range"><code><span id="lacunarity"></span></code></label> | ||
</div> | ||
</fieldset> | ||
<canvas id="canvas" width="512" height="512"></canvas> | ||
<script src="perlin.js"></script> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const std = @import("std"); | ||
const builtin = @import("builtin"); | ||
const perlin = @import("zignal").perlin; | ||
const Rgba = @import("zignal").Rgba; | ||
const Image = @import("zignal").Image; | ||
|
||
pub const std_options: std.Options = .{ | ||
.logFn = if (builtin.cpu.arch.isWasm()) @import("js.zig").logFn else std.log.defaultLog, | ||
.log_level = .info, | ||
}; | ||
|
||
var opts = perlin.Options(f32){ | ||
.amplitude = 1, | ||
.frequency = 1, | ||
.octaves = 1, | ||
.persistence = 0.5, | ||
.lacunarity = 2, | ||
}; | ||
|
||
pub export fn set_amplitude(val: f32) void { | ||
std.log.debug("setting amplitude to {d}", .{val}); | ||
opts.amplitude = val; | ||
} | ||
pub export fn set_frequency(val: f32) void { | ||
std.log.debug("setting frequency to {d}", .{val}); | ||
opts.frequency = val; | ||
} | ||
|
||
pub export fn set_octaves(val: usize) void { | ||
std.log.debug("setting octaves to {d}", .{val}); | ||
opts.octaves = val; | ||
} | ||
|
||
pub export fn set_persistence(val: f32) void { | ||
std.log.debug("setting persistence to {d}", .{val}); | ||
opts.persistence = val; | ||
} | ||
|
||
pub export fn set_lacunarity(val: f32) void { | ||
std.log.debug("setting lacunarity to {d}", .{val}); | ||
opts.lacunarity = val; | ||
} | ||
|
||
pub export fn generate(rgba_ptr: [*]Rgba, rows: usize, cols: usize) void { | ||
const size = rows * cols; | ||
const image = Image(Rgba).init(rows, cols, rgba_ptr[0..size]); | ||
for (0..image.rows) |r| { | ||
const y: f32 = @as(f32, @floatFromInt(r)) / @as(f32, @floatFromInt(image.rows)); | ||
for (0..image.cols) |c| { | ||
const pos = r * image.cols + c; | ||
const x: f32 = @as(f32, @floatFromInt(c)) / @as(f32, @floatFromInt(image.cols)); | ||
const val: u8 = @intFromFloat( | ||
@max(0, @min(255, @round( | ||
255 * (opts.amplitude / 2 * (perlin.generate(f32, x, y, 0, opts) + opts.amplitude)), | ||
))), | ||
); | ||
image.data[pos] = Rgba.fromGray(val, 255); | ||
} | ||
} | ||
} |