this repo has no description
3
fork

Configure Feed

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

♻️ Add .color(Color) on objects, and move .color(Fill) to .paint(Fill)

+53 -55
+19 -39
src/examples.rs
··· 11 11 12 12 let root = canvas.layer("root"); 13 13 14 - root.add_object( 15 - "1", 16 - Object::BigCircle(Point(0, 0)).color(Fill::Solid(Color::Black)), 17 - ); 14 + root.add_object("1", Object::BigCircle(Point(0, 0)).color(Color::Black)); 18 15 root.add_object( 19 16 "2", 20 - Object::CurveOutward(Point(1, 1), Point(2, 0), 5.0) 21 - .color(Fill::Solid(Color::Black)), 17 + Object::CurveOutward(Point(1, 1), Point(2, 0), 5.0).color(Color::Black), 22 18 ); 23 19 root.add_object( 24 20 "3", 25 - Object::CurveInward(Point(2, 1), Point(3, 0), 5.0) 26 - .color(Fill::Solid(Color::Black)), 21 + Object::CurveInward(Point(2, 1), Point(3, 0), 5.0).color(Color::Black), 27 22 ); 28 - root.add_object( 29 - "4", 30 - Object::SmallCircle(Point(0, 1)).color(Fill::Solid(Color::Black)), 31 - ); 23 + root.add_object("4", Object::SmallCircle(Point(0, 1)).color(Color::Black)); 32 24 root.add_object( 33 25 "5", 34 - Object::Line(Point(1, 1), Point(2, 2), 5.0) 35 - .color(Fill::Solid(Color::Black)), 26 + Object::Line(Point(1, 1), Point(2, 2), 5.0).color(Color::Black), 36 27 ); 37 28 root.add_object( 38 29 "6", ··· 43 34 LineSegment::Straight(Point(3, 2)), 44 35 ], 45 36 ) 46 - .color(Fill::Solid(Color::Black)), 37 + .color(Color::Black), 47 38 ); 48 39 root.add_object( 49 40 "7", 50 - Object::Rectangle(Point(0, 2), Point(0, 2)) 51 - .color(Fill::Solid(Color::Black)), 41 + Object::Rectangle(Point(0, 2), Point(0, 2)).color(Color::Black), 52 42 ); 53 - root.add_object( 54 - "8", 55 - Object::Dot(Point(2, 3)).color(Fill::Solid(Color::Black)), 56 - ); 43 + root.add_object("8", Object::Dot(Point(2, 3)).color(Color::Black)); 57 44 58 45 canvas 59 46 } ··· 83 70 iter::zip(colors, canvas.world_region.iter()) 84 71 { 85 72 println!("{}: {:?} {:?}", point, color, bgcolor); 86 - canvas.layer("circles").add_object( 87 - color.name(), 88 - Object::BigCircle(point).color(Fill::Solid(*color)), 89 - ); 73 + canvas 74 + .layer("circles") 75 + .add_object(color.name(), Object::BigCircle(point).color(*color)); 90 76 canvas.layer("root").add_object( 91 77 format!("{}_bg", color.name()), 92 - Object::Rectangle(point, point).color(Fill::Solid(*bgcolor)), 78 + Object::Rectangle(point, point).color(*bgcolor), 93 79 ); 94 80 } 95 81 ··· 103 89 for point in canvas.world_region.iter() { 104 90 canvas.root().add_object( 105 91 point.to_string(), 106 - Object::Dot(point).color(Fill::Solid(Color::Black)), 92 + Object::Dot(point).color(Color::Black), 107 93 ); 108 94 } 109 95 canvas 110 96 } 111 97 112 98 pub fn dna_analysis_machine() -> Canvas { 113 - let mut canvas = Canvas::new(vec![]); 114 - 115 - canvas.colormap = ColorMapping { 99 + let mut canvas = Canvas::with_colors(ColorMapping { 116 100 black: "#000000".into(), 117 101 white: "#ffffff".into(), 118 102 red: "#cf0a2b".into(), ··· 125 109 pink: "#e92e76".into(), 126 110 gray: "#81a0a8".into(), 127 111 cyan: "#4fecec".into(), 128 - }; 112 + }); 129 113 130 114 canvas.set_grid_size(16, 9); 131 115 canvas.set_background(Color::Black); ··· 153 137 red_dot_layer.add_object( 154 138 format!("red circle @ {}", point), 155 139 Object::BigCircle(point) 156 - .color(Fill::Solid(Color::Red)) 140 + .color(Color::Red) 157 141 .filter(Filter::glow(5.0)), 158 142 ); 159 143 } ··· 165 149 } else { 166 150 Object::Rectangle(point, point) 167 151 } 168 - .color(Fill::Hatched( 152 + .paint(Fill::Hatched( 169 153 Color::White, 170 154 Angle(45.0), 171 155 (i + 5) as f32 / 10.0, ··· 175 159 } 176 160 177 161 let mut filaments = 178 - canvas.n_random_curves_within("splines", &filaments_area, 30); 162 + canvas.n_random_curves_within(&filaments_area, 30, "splines"); 179 163 180 164 for (i, object) in filaments.objects.values_mut().enumerate() { 181 - object.recolor(Fill::Solid(if i % 2 == 0 { 182 - Color::Cyan 183 - } else { 184 - Color::Pink 185 - })); 165 + object.recolor(if i % 2 == 0 { Color::Cyan } else { Color::Pink }); 186 166 } 187 167 188 168 filaments.filter_all_objects(Filter::glow(4.0));
+12 -8
src/graphics/canvas.rs
··· 59 59 } 60 60 } 61 61 62 + pub fn with_colors(colormap: ColorMapping) -> Self { 63 + Self { 64 + colormap, 65 + ..Self::default_settings() 66 + } 67 + } 68 + 62 69 pub fn set_grid_size(&mut self, new_width: usize, new_height: usize) { 63 70 self.grid_size = (new_width, new_height); 64 71 self.world_region = Region { ··· 332 339 333 340 layer.add_object( 334 341 format!("{}_corner_ss", region).as_str(), 335 - Object::Dot(region.topleft()).color(Fill::Solid(color)), 342 + Object::Dot(region.topleft()).color(color), 336 343 ); 337 344 layer.add_object( 338 345 format!("{}_corner_se", region).as_str(), 339 - Object::Dot(region.topright().translated(1, 0)) 340 - .color(Fill::Solid(color)), 346 + Object::Dot(region.topright().translated(1, 0)).color(color), 341 347 ); 342 348 layer.add_object( 343 349 format!("{}_corner_ne", region).as_str(), 344 - Object::Dot(region.bottomright().translated(1, 1)) 345 - .color(Fill::Solid(color)), 350 + Object::Dot(region.bottomright().translated(1, 1)).color(color), 346 351 ); 347 352 layer.add_object( 348 353 format!("{}_corner_nw", region).as_str(), 349 - Object::Dot(region.bottomleft().translated(0, 1)) 350 - .color(Fill::Solid(color)), 354 + Object::Dot(region.bottomleft().translated(0, 1)).color(color), 351 355 ); 352 356 layer.add_object( 353 357 format!("{}_region", region).as_str(), 354 358 Object::Rectangle(region.start, region.end) 355 - .color(Fill::Translucent(color, 0.25)), 359 + .paint(Fill::Translucent(color, 0.25)), 356 360 ) 357 361 } 358 362 }
+18 -4
src/graphics/objects.rs
··· 2 2 #[cfg(feature = "web")] 3 3 use wasm_bindgen::prelude::*; 4 4 5 + use super::Color; 6 + 5 7 #[derive(Debug, Clone, PartialEq, Eq)] 6 8 pub enum LineSegment { 7 9 Straight(Point), ··· 28 30 } 29 31 30 32 impl Object { 31 - pub fn color(self, fill: Fill) -> ColoredObject { 33 + pub fn paint(self, fill: Fill) -> ColoredObject { 32 34 ColoredObject::from((self, Some(fill))) 33 35 } 34 36 37 + pub fn color(self, color: Color) -> ColoredObject { 38 + ColoredObject::from((self, Some(Fill::Solid(color)))) 39 + } 40 + 35 41 pub fn filter(self, filter: Filter) -> ColoredObject { 36 42 ColoredObject::from((self, None)).filter(filter) 37 43 } ··· 64 70 self.filters.clear(); 65 71 } 66 72 67 - pub fn recolor(&mut self, fill: Fill) { 73 + pub fn repaint(&mut self, fill: Fill) { 68 74 self.fill = Some(fill); 69 75 } 76 + 77 + pub fn recolor(&mut self, color: Color) { 78 + self.fill = Some(Fill::Solid(color)) 79 + } 70 80 } 71 81 72 82 impl std::fmt::Display for ColoredObject { ··· 147 157 match line { 148 158 LineSegment::InwardCurve(anchor) 149 159 | LineSegment::OutwardCurve(anchor) 150 - | LineSegment::Straight(anchor) => anchor.translate(dx, dy), 160 + | LineSegment::Straight(anchor) => { 161 + anchor.translate(dx, dy) 162 + } 151 163 } 152 164 } 153 165 } ··· 225 237 pub fn fillable(&self) -> bool { 226 238 !matches!( 227 239 self, 228 - Object::Line(..) | Object::CurveInward(..) | Object::CurveOutward(..) 240 + Object::Line(..) 241 + | Object::CurveInward(..) 242 + | Object::CurveOutward(..) 229 243 ) 230 244 } 231 245
+2 -2
src/main.rs
··· 110 110 canvas.root().add_object( 111 111 "text", 112 112 Object::CenteredText(center, ctx.timestamp.to_string(), 30.0) 113 - .color(Fill::Solid(Color::White)), 113 + .color(Color::White), 114 114 ); 115 115 canvas.root().add_object( 116 116 "beat", ··· 119 119 format!("beat {}", ctx.beat), 120 120 30.0, 121 121 ) 122 - .color(Fill::Solid(Color::Cyan)), 122 + .color(Color::Cyan), 123 123 ); 124 124 Ok(()) 125 125 })
+2 -2
src/random/canvas.rs
··· 17 17 18 18 pub fn n_random_curves_within( 19 19 &self, 20 - layer_name: &str, 21 20 region: &Region, 22 21 count: usize, 22 + layer_name: &str, 23 23 ) -> Layer { 24 24 let mut objects: HashMap<String, ColoredObject> = HashMap::new(); 25 25 for i in 0..count { ··· 68 68 let hatchable = object.hatchable(); 69 69 objects.insert( 70 70 format!("{}#{}", name, i), 71 - object.color(if hatchable { 71 + object.paint(if hatchable { 72 72 Fill::random_hatches(self.background) 73 73 } else { 74 74 Fill::random_solid(self.background)