-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
e49ce20
commit ba380ac
Showing
8 changed files
with
281 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"rust-analyzer.inlayHints.chainingHints.enable": false, | ||
"rust-analyzer.inlayHints.closingBraceHints.enable": false, | ||
"rust-analyzer.inlayHints.parameterHints.enable": false, | ||
"rust-analyzer.inlayHints.typeHints.enable": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,61 @@ | ||
use std::f64::consts::TAU; | ||
|
||
use sketch_utils::{opener, sketch_output_path}; | ||
|
||
use ivo::*; | ||
|
||
use rand::prelude::*; | ||
|
||
pub fn main() { | ||
let mut scene = Scene::new(); | ||
|
||
let mut rng = rand::thread_rng(); | ||
|
||
let n = rng.gen::<u8>(); | ||
|
||
let mut cells: Vec<u8> = vec![0; 360]; | ||
for _ in 0..rng.gen_range(1..=10) { | ||
let i = rng.gen_range(0..cells.len()); | ||
cells[i] = 1; | ||
} | ||
|
||
for z in 0..100 { | ||
let mut new = vec![0; cells.len()]; | ||
|
||
for (x, c) in cells.iter().enumerate() { | ||
let a = f64::from(x as i32) / (cells.len() as f64) * TAU; | ||
|
||
let xx = f64::round(a.cos() * 50.0) as i32; | ||
let yy = f64::round(a.sin() * 50.0) as i32; | ||
|
||
// if *c != 0 { | ||
// if *c != 0 && (xx > 0 || (yy & 1) != 0) { | ||
if *c != 0 && (xx & 1) != 0 { | ||
scene.add(xx, yy, -z); | ||
} | ||
|
||
if x > 0 && x < cells.len() - 1 { | ||
let ix = (cells[x - 1] << 2) | (c << 1) | (cells[x + 1]); | ||
new[x] = (n >> ix) & 1; | ||
} | ||
} | ||
|
||
cells = new; | ||
} | ||
|
||
let triangles = render_outlines(&scene); | ||
|
||
let path = sketch_output_path("automata.svg").unwrap(); | ||
|
||
dump_outlines_svg( | ||
&path, | ||
&triangles, | ||
// &SvgSettings::new(744.0, 1052.0) | ||
&SvgSettings::new(744.0 * 3.0, 1052.0 * 3.0) | ||
.with_stroke_width(2.0) | ||
.with_padding(10.0), | ||
) | ||
.unwrap(); | ||
|
||
opener::open(&path).expect("cannot open automata.svg"); | ||
} |
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,42 @@ | ||
use geo::{sdf::*, v3}; | ||
use sketch_utils::{opener, sketch_output_path}; | ||
|
||
use rand::prelude::*; | ||
|
||
use ivo::*; | ||
|
||
pub fn main() { | ||
let mut scene = Scene::new(); | ||
|
||
let path = sketch_output_path("building.svg").unwrap(); | ||
|
||
scene.aabb((0, 0, 0), (100, 100, 100)); | ||
|
||
scene.invert(); | ||
|
||
let mut rng = thread_rng(); | ||
for octave in 0..=6 { | ||
let n = 2 << octave; | ||
let r = 100 / (1 << octave); | ||
|
||
for _ in 0..n { | ||
scene.sdf( | ||
&(sphere(r.into()) | ||
+ v3( | ||
rng.gen_range(-100.0..=100.0), | ||
rng.gen_range(-100.0..=100.0), | ||
rng.gen_range(-100.0..=100.0), | ||
)), | ||
); | ||
} | ||
} | ||
|
||
let settings = SvgSettings::new(744.0, 1052.0) | ||
.with_stroke_width(1.0) | ||
.with_padding(20.0); | ||
|
||
let triangles = render_outlines(&scene); | ||
dump_outlines_svg(&path, &triangles, &settings).unwrap(); | ||
|
||
opener::open(&path).expect("cannot open building.svg"); | ||
} |
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,114 @@ | ||
use std::{env, f64::consts::TAU}; | ||
|
||
use geo::util::arange; | ||
use sketch_utils::{opener, sketch_output_path}; | ||
|
||
use ivo::*; | ||
|
||
use noise::{NoiseFn, Perlin}; | ||
use rand::prelude::*; | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
enum Mode { | ||
Cone, | ||
Noise, | ||
} | ||
|
||
pub fn main() { | ||
let mut scene = Scene::new(); | ||
|
||
let _fill = ["true", "1"].contains( | ||
&env::args() | ||
.nth(1) | ||
.unwrap_or_default() | ||
.trim() | ||
.to_lowercase() | ||
.as_str(), | ||
); | ||
let mode = if env::args().nth(2).unwrap_or_default().trim().to_lowercase() == "cone" { | ||
Mode::Cone | ||
} else { | ||
Mode::Noise | ||
}; | ||
|
||
let fill = false; | ||
|
||
let mut rng = thread_rng(); | ||
|
||
let freq = rng.gen_range(0.3..=5.0); | ||
let freq2 = rng.gen_range(0.3..=3.0); | ||
let freq3 = rng.gen_range(0.3..=3.0); | ||
|
||
let nseeds = rng.gen_range(1..=20); | ||
let radius = if mode == Mode::Noise { | ||
rng.gen_range(30.0..=100.0) | ||
} else { | ||
rng.gen_range(30.0..=100.0) | ||
}; | ||
|
||
let noise = Perlin::new(rng.gen()); | ||
|
||
let mut seeds = vec![]; | ||
for i in 1..=nseeds { | ||
let a = match mode { | ||
Mode::Cone => TAU / f64::from(i), | ||
Mode::Noise => f64::from(i) / f64::from(nseeds) * TAU, | ||
}; | ||
seeds.push(a); | ||
} | ||
|
||
let height = 200.0; | ||
for zz in arange(0.0, height, 0.01) { | ||
let z = zz.round() as i32; | ||
|
||
let zt = zz / height; | ||
let a = zt * TAU; | ||
let a = a * freq; | ||
|
||
for ba in &seeds { | ||
let a = ba + a; | ||
|
||
let x; | ||
let y; | ||
match mode { | ||
Mode::Cone => { | ||
x = a.cos() * radius * zt; | ||
y = a.sin() * radius * zt; | ||
} | ||
Mode::Noise => { | ||
let r = noise.get([a.cos() / freq2, a.sin() / freq2, zt * freq3]); | ||
x = a.cos() * radius * r * rng.gen_range(0.8..=1.0); | ||
y = a.sin() * radius * r * rng.gen_range(0.8..=1.0); | ||
} | ||
} | ||
|
||
scene.add(x as i32, y as i32, -z); | ||
} | ||
} | ||
|
||
let path = sketch_output_path("helix.svg").unwrap(); | ||
|
||
let a4_multiplier = 3.0; | ||
let settings = SvgSettings::new(744.0 * a4_multiplier, 1052.0 * a4_multiplier) | ||
.with_stroke_width(2.0) | ||
.with_padding(10.0) | ||
.with_fill_color(Orientation::Top, "#ff0000") | ||
.with_fill_color(Orientation::Left, "#00ff00") | ||
.with_fill_color(Orientation::Right, "#0000ff"); | ||
|
||
let settings = if fill { | ||
settings.with_background("#050609") | ||
} else { | ||
settings | ||
}; | ||
|
||
if fill { | ||
let triangles = render_triangles(&scene); | ||
dump_triangles_svg(&path, &triangles, &settings).unwrap(); | ||
} else { | ||
let triangles = render_outlines(&scene); | ||
dump_outlines_svg(&path, &triangles, &settings).unwrap(); | ||
} | ||
|
||
opener::open(&path).expect("cannot open helix.svg"); | ||
} |
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,26 @@ | ||
use sketch_utils::opener; | ||
|
||
use ivo::*; | ||
|
||
pub fn main() { | ||
let mut scene = Scene::with_dimensions_hint(500, 500, 500); | ||
|
||
for y in (-500..=500).step_by(50) { | ||
let yt = f64::from(y) / 500.0; | ||
for x in (-500..=500).step_by(50) { | ||
let xt = f64::from(x) / 500.0; | ||
let t = 1.0 - f64::abs(xt * yt); | ||
let h = 150.0 + 300.0 * t.powi(6); | ||
|
||
scene.zslab((x + 25, y + 25, 0), (20, 20, h as i32)); | ||
scene.zslab((x + 25, y + 25, -h as i32), (20, 20, h as i32)); | ||
} | ||
} | ||
|
||
let triangles = render_outlines(&scene); | ||
|
||
dump_outlines_svg("sym.svg", &triangles, &SvgSettings::new(1080.0, 1920.0)) | ||
.expect("cannot save sym.svg"); | ||
|
||
opener::open("sym.svg").expect("cannot open sym.svg"); | ||
} |
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,27 @@ | ||
use std::io; | ||
|
||
use sketch_utils::opener; | ||
|
||
use ivo::*; | ||
|
||
pub fn main() { | ||
let mut scene = Scene::new(); | ||
|
||
for l in io::stdin().lines() { | ||
let l = l.unwrap(); | ||
|
||
let mut coords = l.split(','); | ||
let x = coords.next().unwrap().parse::<i32>().unwrap(); | ||
let y = coords.next().unwrap().parse::<i32>().unwrap(); | ||
let z = coords.next().unwrap().parse::<i32>().unwrap(); | ||
|
||
scene.add(x, y, z); | ||
} | ||
|
||
let triangles = render_outlines(&scene); | ||
|
||
dump_outlines_svg("voxels.svg", &triangles, &SvgSettings::new(2048.0, 2048.0)) | ||
.expect("cannot save voxels.svg"); | ||
|
||
opener::open("voxels.svg").expect("cannot open voxels.svg"); | ||
} |