diff --git a/docs/TODO_phase3.md b/docs/TODO_phase3.md index c6238fd0f0..d3ee2908c5 100644 --- a/docs/TODO_phase3.md +++ b/docs/TODO_phase3.md @@ -14,7 +14,6 @@ - better visualization - draw moving / blocked colors (gradually more red as they wait longer) - draw stop buffer in front/behind of cars - - draw cars in slightly different colors, to distinguish them better - start implementing a second AORTAish driving model - then make cars park/unpark at the correct position diff --git a/editor/src/ui.rs b/editor/src/ui.rs index e8e79fb663..0bdaaab5fd 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -6,10 +6,10 @@ use abstutil; use colors::{ColorScheme, Colors}; use control::ControlMap; use control::{ModifiedStopSign, ModifiedTrafficSignal}; +use ezgui; use ezgui::canvas::Canvas; use ezgui::input::UserInput; -use ezgui::GfxCtx; -use ezgui::ToggleableLayer; +use ezgui::{GfxCtx, ToggleableLayer}; use graphics::types::Color; use gui; use map_model; @@ -327,9 +327,9 @@ impl UI { return c; } match self.sim_ctrl.sim.get_car_state(id) { - CarState::Moving => self.cs.get(Colors::MovingCar), - CarState::Stuck => self.cs.get(Colors::StuckCar), - CarState::Parked => self.cs.get(Colors::ParkedCar), + CarState::Moving => ezgui::shift_color(self.cs.get(Colors::MovingCar), id.0), + CarState::Stuck => ezgui::shift_color(self.cs.get(Colors::StuckCar), id.0), + CarState::Parked => ezgui::shift_color(self.cs.get(Colors::ParkedCar), id.0), } } @@ -337,7 +337,7 @@ impl UI { if let Some(c) = self.current_selection_state.color_p(id, &self.cs) { return c; } - self.cs.get(Colors::Pedestrian) + ezgui::shift_color(self.cs.get(Colors::Pedestrian), id.0) } } diff --git a/ezgui/Cargo.toml b/ezgui/Cargo.toml index d9d1ad4073..1e6b0d9a6d 100644 --- a/ezgui/Cargo.toml +++ b/ezgui/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Dustin Carlino "] [dependencies] aabb-quadtree = "0.1.0" +palette = "0.4" piston = "*" piston2d-graphics = "*" piston2d-opengl_graphics = "*" diff --git a/ezgui/src/lib.rs b/ezgui/src/lib.rs index 0cb14ed56e..73862d0fa6 100644 --- a/ezgui/src/lib.rs +++ b/ezgui/src/lib.rs @@ -3,6 +3,7 @@ extern crate aabb_quadtree; extern crate graphics; extern crate opengl_graphics; +extern crate palette; extern crate piston; pub mod canvas; @@ -135,3 +136,23 @@ impl ToggleableLayer { self.enabled = false; } } + +// Deterministically shift a color's brightness based on an ID. +pub fn shift_color(c: Color, id: usize) -> Color { + use palette::Shade; + + // TODO this needs tuning. too easy to get too light/dark, but also too easy to have too few + // variants. should maybe just manually come up with a list of 100 colors, hardcode in, modulo. + let variants = 10; + let half_variants = variants / 2; + let modulo = id % variants; + let scale = 1.0 / (variants as f32); + + let color = palette::Srgb::new(c[0], c[1], c[2]).into_linear(); + let new_color = if modulo < half_variants { + color.lighten(scale * (modulo as f32)) + } else { + color.darken(scale * ((modulo - half_variants) as f32)) + }; + [new_color.red, new_color.green, new_color.blue, 1.0] +}