Initial commit
This commit is contained in:
commit
c8cf358a11
6 changed files with 180 additions and 0 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
use flake
|
||||||
22
.gitignore
vendored
Normal file
22
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/screenshots
|
||||||
|
/target
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/rust
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=rust
|
||||||
|
|
||||||
|
### Rust ###
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
|
Cargo.lock
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/rust
|
||||||
16
Cargo.toml
Normal file
16
Cargo.toml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
[package]
|
||||||
|
name = "specimen"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "noise-studies-01"
|
||||||
|
path = "src/noise-studies-01.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
nannou = "0.18"
|
||||||
|
rand = "0.8.5"
|
||||||
|
noise = "0.7.0"
|
||||||
|
|
||||||
26
flake.lock
generated
Normal file
26
flake.lock
generated
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1660420655,
|
||||||
|
"narHash": "sha256-iGWZIGEgzc4BpiI8k0UnzmodMfN7A3zuZPyzTFm+/f0=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "8979e6cc6901a3c3a0fa483ea997c84924d2f7f8",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
35
flake.nix
Normal file
35
flake.nix
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
description = "A very basic flake";
|
||||||
|
|
||||||
|
inputs.nixpkgs.url = github:NixOS/nixpkgs;
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs }:
|
||||||
|
let
|
||||||
|
system = "x86_64-linux";
|
||||||
|
pkgs = import nixpkgs { inherit system; };
|
||||||
|
lib = pkgs.lib;
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
clippy
|
||||||
|
rustc
|
||||||
|
cargo
|
||||||
|
cargo-watch
|
||||||
|
rustfmt
|
||||||
|
rust-analyzer
|
||||||
|
|
||||||
|
# for nannou
|
||||||
|
xorg.libX11
|
||||||
|
xorg.libXcursor
|
||||||
|
xorg.libXrandr
|
||||||
|
xorg.libXi
|
||||||
|
vulkan-tools vulkan-headers vulkan-loader vulkan-validation-layers
|
||||||
|
# wayland
|
||||||
|
# xwayland
|
||||||
|
];
|
||||||
|
in {
|
||||||
|
devShell.${system} = pkgs.mkShell {
|
||||||
|
inherit buildInputs;
|
||||||
|
RUST_BACKTRACE = 1;
|
||||||
|
LD_LIBRARY_PATH = (lib.makeLibraryPath buildInputs);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
80
src/noise-studies-01.rs
Normal file
80
src/noise-studies-01.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
use nannou::{prelude::*, color::Alpha};
|
||||||
|
use noise::{Fbm, NoiseFn};
|
||||||
|
|
||||||
|
const WIDTH: f32 = 512.0;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Model {
|
||||||
|
noise: Fbm,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
nannou::app(model).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn model(app: &App) -> Model {
|
||||||
|
app.set_loop_mode(LoopMode::NTimes { number_of_updates: 1 });
|
||||||
|
|
||||||
|
let _window = app
|
||||||
|
.new_window()
|
||||||
|
.size(WIDTH as u32, WIDTH as u32)
|
||||||
|
.view(view)
|
||||||
|
.key_pressed(key_pressed)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Model {
|
||||||
|
noise: Fbm::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(app: &App, model: &Model, frame: Frame) {
|
||||||
|
let draw = app
|
||||||
|
.draw()
|
||||||
|
.scale_y(-1.0)
|
||||||
|
.translate(vec3(WIDTH / -2.0, WIDTH / -2.0, 0.0));
|
||||||
|
|
||||||
|
draw.background().color(MINTCREAM);
|
||||||
|
|
||||||
|
let block_size: usize = 32;
|
||||||
|
let x_step = 0.01;
|
||||||
|
let y_step = 0.002;
|
||||||
|
|
||||||
|
let line_color = Alpha {
|
||||||
|
color: LIGHTSALMON,
|
||||||
|
alpha: 0.3
|
||||||
|
};
|
||||||
|
|
||||||
|
for x in (block_size..(frame.rect().w() as usize - block_size)).step_by(block_size / 8) {
|
||||||
|
for y in (block_size..(frame.rect().h() as usize - block_size)).step_by(block_size / 8) {
|
||||||
|
let half = (block_size / 2) as f32;
|
||||||
|
let v1 = vec2(x as f32, y as f32);
|
||||||
|
let noise = model.noise.get([(v1.x * x_step) as f64, (v1.y * y_step) as f64]) as f32;
|
||||||
|
let v2 = v1 + vec2(0.0, half * map_range(noise, -1.0, 1.0, 0.0, 2.0)).rotate(noise * TAU);
|
||||||
|
draw.line().weight(1.0).points(v1, v2).color(line_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
draw.to_frame(app, &frame).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn captured_frame_path(app: &App) -> std::path::PathBuf {
|
||||||
|
// Create a path that we want to save this frame to.
|
||||||
|
app.project_path()
|
||||||
|
.expect("failed to locate `project_path`")
|
||||||
|
// Capture all frames to a directory called `/<path_to_project>/screenshots/<name_of_bin>`.
|
||||||
|
.join("screenshots")
|
||||||
|
.join(app.exe_name().unwrap())
|
||||||
|
// Name each file after the number of the frame.
|
||||||
|
.join(format!("{:03}", app.elapsed_frames()))
|
||||||
|
// The extension will be PNG. We also support tiff, bmp, gif, jpeg, webp and some others.
|
||||||
|
.with_extension("png")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn key_pressed(app: &App, _model: &mut Model, key: Key) {
|
||||||
|
if key == Key::S {
|
||||||
|
let file_path = captured_frame_path(app);
|
||||||
|
println!("Saving to {:?}…", file_path);
|
||||||
|
app.main_window().capture_frame(file_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue