Add the Interlinked CLI and a first project to start with.

This commit is contained in:
Bauke 2024-01-29 19:04:25 +01:00
parent 5fb4ed793c
commit 87c04e961a
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
10 changed files with 712 additions and 1 deletions

405
Cargo.lock generated
View File

@ -2,6 +2,172 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "anstream"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
[[package]]
name = "anstyle-parse"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "backtrace"
version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "cc"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [
"libc",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "color-eyre"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "console"
version = "0.15.8"
@ -26,20 +192,49 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "eyre"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6267a1fa6f59179ea4afc8e50fd8612a3cc60bc858f786ff877a4a8cb042799"
dependencies = [
"indenter",
"once_cell",
]
[[package]]
name = "gegl"
version = "0.0.0"
dependencies = [
"indexmap",
"insta",
"paste",
]
[[package]]
name = "gimli"
version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "hashbrown"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "indenter"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]]
name = "indexmap"
version = "2.1.0"
@ -63,6 +258,17 @@ dependencies = [
"yaml-rust",
]
[[package]]
name = "interlinked"
version = "0.0.0"
dependencies = [
"clap",
"color-eyre",
"gegl",
"insta",
"subprocess",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -81,12 +287,211 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "memchr"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "miniz_oxide"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
dependencies = [
"adler",
]
[[package]]
name = "object"
version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "owo-colors"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "paste"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "pin-project-lite"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "proc-macro2"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustc-demangle"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "similar"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32fea41aca09ee824cc9724996433064c89f7777e60762749a4170a14abbfa21"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "subprocess"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c2e86926081dda636c546d8c5e641661049d7562a68f5488be4a1f7f66f6086"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "syn"
version = "2.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thread_local"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "tracing"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
"sharded-slab",
"thread_local",
"tracing-core",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.52.0"

View File

@ -2,7 +2,8 @@
[workspace]
members = [
"gegl"
"gegl",
"interlinked",
]
resolver = "2"

33
interlinked/Cargo.toml Normal file
View File

@ -0,0 +1,33 @@
# https://doc.rust-lang.org/cargo/reference/manifest.html
[package]
name = "interlinked"
description = "Generative art with GIMP, GEGL and ImageMagick."
repository = "https://git.bauke.xyz/driftingnebula/interlinked"
license = "AGPL-3.0-or-later"
version = "0.0.0"
authors = ["Bauke <me@bauke.xyz>"]
edition = "2021"
readme = "../README.md"
[lib]
path = "source/lib.rs"
[[bin]]
name = "interlinked"
path = "source/main.rs"
[lints]
workspace = true
[dependencies]
color-eyre = "0.6.2"
gegl = { path = "../gegl" }
subprocess = "0.2.9"
[dependencies.clap]
features = ["derive"]
version = "4.4.18"
[dev-dependencies]
insta = "1.34.0"

View File

@ -0,0 +1,21 @@
//! The [`clap`] command-line definitions.
mod run;
pub use {clap::Parser, run::*};
/// The Interlinked CLI.
#[derive(Debug, Parser)]
pub struct CliArgs {
/// Only render projects starting with the filter.
#[clap(short, long)]
pub filter: Option<String>,
/// Include default values in the GEGL graphs.
#[clap(long, default_value = "false")]
pub include_defaults: bool,
/// Don't render any images.
#[clap(long, default_value = "false")]
pub no_render: bool,
}

View File

@ -0,0 +1,123 @@
//! The CLI logic.
use {
crate::{all_projects, utilities::shell_command, CliArgs, Parser},
color_eyre::{eyre::OptionExt, Result},
gegl::GeglOperation,
std::{
fs::{create_dir_all, write},
path::Path,
time::Instant,
},
};
/// Run the CLI.
pub fn run() -> Result<()> {
let args = CliArgs::parse();
let projects = if let Some(filter) = args.filter {
all_projects()
.into_iter()
.filter(|project| project.name.starts_with(&filter))
.collect::<Vec<_>>()
} else {
all_projects().into_iter().collect()
};
let base_out_dir = Path::new("output/rust/");
for project in projects {
let start = Instant::now();
let (width, height) = project.resolution;
let out_dir = base_out_dir.join(&project.name);
create_dir_all(&out_dir)?;
println!(
"→ {} ({}x{}, {} base operations ({} including crops))",
project.name,
width,
height,
project.operations.len(),
project
.operations
.iter()
.map(|op| if op.append_crop_operation() { 2 } else { 1 })
.sum::<i32>(),
);
let graph = project
.operations
.into_iter()
.flat_map(|op| {
let mut graph = vec![op.graph(args.include_defaults)];
if op.append_crop_operation() {
graph.push(
gegl::Crop::default()
.with_height(height as f64)
.with_width(width as f64)
.graph(args.include_defaults),
)
}
graph
})
.collect::<Vec<_>>();
let pretty_graph = graph
.iter()
.map(|params| {
params
.iter()
.map(|param| {
if param.starts_with("gegl:") {
param.to_string()
} else {
format!(" {}", param)
}
})
.collect::<Vec<_>>()
.join("\n")
})
.collect::<Vec<_>>()
.join("\n\n");
let graph_file = out_dir.join(format!("{}.txt", project.name));
write(graph_file, pretty_graph)?;
if args.no_render {
let end = Instant::now();
println!("{:?} (not rendered)", end - start);
continue;
}
let out_file = out_dir.join(format!("{}.png", project.name));
let out_file = out_file
.to_str()
.ok_or_eyre("Failed to convert out_file to str")?;
let input = if project.create_input_image {
shell_command(format!(
"convert -size {}x{} xc:white {}",
width, height, out_file
))?;
format!("-i {}", out_file)
} else {
String::new()
};
let graph = graph
.into_iter()
.map(|op| op.join(" "))
.collect::<Vec<_>>()
.join(" ");
shell_command(format!("gegl {} -o {} -- {}", input, out_file, graph))?;
if project.turn_off_alpha {
shell_command(format!("convert {0} -alpha Off {0}", out_file))?;
}
let end = Instant::now();
println!("{:?}", end - start);
}
Ok(())
}

36
interlinked/source/lib.rs Normal file
View File

@ -0,0 +1,36 @@
//! # Interlinked.
//!
//! > **Generative art with GIMP, GEGL and ImageMagick.**
mod cli;
pub mod projects;
pub mod utilities;
use gegl::GeglOperation;
pub use {cli::*, projects::all_projects};
/// An individual project with all the operations to generate it.
#[derive(Debug)]
pub struct Project {
/// Whether to start from an empty input image.
///
/// Some operations require an input buffer to start from so this will create
/// an empty image with `imagemagick` and then use that as the input.
pub create_input_image: bool,
/// The name of this project.
pub name: String,
/// The list of operations.
pub operations: Vec<Box<dyn GeglOperation>>,
/// The resolution of the image as a tuple of width and height.
pub resolution: (i64, i64),
/// Whether to explicitly turn off the image's alpha channel after finishing
/// rendering the operations.
///
/// TODO: Explain why this exists after I've figured it out myself again. x)
pub turn_off_alpha: bool,
}

View File

@ -0,0 +1,7 @@
//! # Interlinked.
//!
//! > **Generative art with GIMP, GEGL and ImageMagick.**
fn main() -> color_eyre::Result<()> {
interlinked::run()
}

View File

@ -0,0 +1,10 @@
//! All [`Project`]s created with Interlinked.
use crate::Project;
pub mod year_2022;
/// Get all [`Project`]s in a single [`Vec`].
pub fn all_projects() -> Vec<Project> {
vec![year_2022::day_2022_03_06()]
}

View File

@ -0,0 +1,59 @@
//! The project made on 2022-03-06.
use {crate::Project, gegl::*};
/// The project made on 2022-03-06.
pub fn day_2022_03_06() -> Project {
Project {
create_input_image: false,
name: "2022-03-06".to_string(),
operations: vec![
SimplexNoise::default()
.with_scale(4.0)
.with_seed(2_071_140_406.0)
.boxed(),
Newsprint::default()
.with_color_model(NewsprintColorModel::Rgb)
.with_pattern2(NewsprintPattern::Line)
.with_period2(200.0)
.with_angle2(15.0)
.with_pattern3(NewsprintPattern::Line)
.with_period3(200.0)
.with_angle3(45.0)
.with_pattern4(NewsprintPattern::Line)
.with_period4(200.0)
.with_angle4(0.0)
.boxed(),
Mirrors::default().boxed(),
Softglow::default().boxed(),
Newsprint::default().boxed(),
StereographicProjection::default().with_tilt(123.0).boxed(),
FocusBlur::default()
.with_blur_radius(11.5)
.with_blur_type(FocusBlurType::Gaussian)
.with_midpoint(0.6)
.with_radius(0.9)
.boxed(),
Newsprint::default()
.with_color_model(NewsprintColorModel::Rgb)
.with_pattern2(NewsprintPattern::Diamond)
.with_period2(200.0)
.with_angle2(0.0)
.with_pattern3(NewsprintPattern::Diamond)
.with_period3(200.0)
.with_angle3(35.0)
.with_pattern4(NewsprintPattern::Diamond)
.with_period4(200.0)
.with_angle4(55.0)
.boxed(),
FocusBlur::default()
.with_blur_radius(11.5)
.with_blur_type(FocusBlurType::Gaussian)
.with_midpoint(0.6)
.with_radius(0.9)
.boxed(),
],
resolution: (1920, 1080),
turn_off_alpha: false,
}
}

View File

@ -0,0 +1,16 @@
//! Helper and utility functions.
use {
color_eyre::Result,
subprocess::{Exec, NullFile},
};
/// Run a command using [`subprocess`] and discard the output.
pub fn shell_command(command: String) -> Result<()> {
Exec::shell(command)
.stdout(NullFile)
.stderr(NullFile)
.capture()?;
Ok(())
}