This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

:refactor: Start putting examples into separate bin crates

+82 -1
+1 -1
Cargo.toml
··· 10 10 description = "An experimental WASM-capable, generative SVG-based video rendering engine that reacts to MIDI or audio data" 11 11 12 12 [workspace] 13 - members = ["xtask"] 13 + members = [ "examples/dna-analysis-machine","xtask"] 14 14 15 15 [lib] 16 16 crate-type = ["cdylib", "lib"]
+8
examples/dna-analysis-machine/Cargo.toml
··· 1 + [package] 2 + name = "dna-analysis-machine" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + rand = "0.9.0" 8 + shapemaker = { path = "../../" }
examples/dna-analysis-machine/dna-analysis-machine.png

This is a binary file and will not be displayed.

+73
examples/dna-analysis-machine/src/main.rs
··· 1 + use shapemaker::*; 2 + use rand; 3 + 4 + pub fn main() { 5 + let mut canvas = Canvas::with_colors(ColorMapping { 6 + black: "#000000".into(), 7 + white: "#ffffff".into(), 8 + red: "#cf0a2b".into(), 9 + green: "#22e753".into(), 10 + blue: "#2734e6".into(), 11 + yellow: "#f8e21e".into(), 12 + orange: "#f05811".into(), 13 + purple: "#6a24ec".into(), 14 + brown: "#a05634".into(), 15 + pink: "#e92e76".into(), 16 + gray: "#81a0a8".into(), 17 + cyan: "#4fecec".into(), 18 + }); 19 + 20 + canvas.set_grid_size(16, 9); 21 + canvas.set_background(Color::Black); 22 + 23 + let draw_in = canvas.world_region.resized(-2, -2); 24 + 25 + // Strands 26 + 27 + let strands_in = 28 + Region::from_bottomleft(draw_in.bottomleft().translated(2, -1), (3, 3)) 29 + .unwrap(); 30 + 31 + canvas.add_layer(canvas.n_random_curves_within(&strands_in, 30, "strands")); 32 + 33 + for (i, obj) in canvas.layer("strands").objects.values_mut().enumerate() { 34 + obj.recolor(if i % 2 == 0 { Color::Cyan } else { Color::Pink }); 35 + obj.filter(Filter::glow(4.0)); 36 + } 37 + 38 + // Red dot 39 + 40 + let red_dot = Object::BigCircle( 41 + Region::from_topright(draw_in.topright().translated(-3, 1), (4, 3)) 42 + .unwrap() 43 + .random_point(), 44 + ) 45 + .colored(Color::Red) 46 + .filtered(Filter::glow(5.0)); 47 + 48 + canvas.new_layer("red dot").add(red_dot.clone()); 49 + 50 + // Hatched circles & squares 51 + 52 + let hatches = canvas.new_layer("hatches"); 53 + 54 + for (i, point) in draw_in.except(&strands_in).enumerate() { 55 + if red_dot.region().contains(&point) { 56 + continue; 57 + } 58 + if rand::random() { 59 + Object::BigCircle(point) 60 + } else { 61 + Object::Rectangle(point, point) 62 + } 63 + .filled(Fill::Hatches( 64 + Color::White, 65 + Angle(45.0), 66 + (i + 5) as f32 / 10.0, 67 + 0.25, 68 + )) 69 + .add_to(hatches); 70 + } 71 + 72 + canvas.render_to_png("dna-analysis-machine.png", 480).unwrap(); 73 + }