mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
different colors for cars and peds
This commit is contained in:
parent
a4b8c2247f
commit
1348db1288
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ authors = ["Dustin Carlino <dabreegster@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
aabb-quadtree = "0.1.0"
|
||||
palette = "0.4"
|
||||
piston = "*"
|
||||
piston2d-graphics = "*"
|
||||
piston2d-opengl_graphics = "*"
|
||||
|
@ -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]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user