(Attribute::Bold.into(), Attribute::Reset.into())
}
- fn try_point(&self, point: Point) -> bool {
+ fn draw_point(&self, point: Point) -> Option<char> {
if let Some(cell) = self.get((point.y, point.x)) {
if cell.get() == State::Alive {
- return true;
+ return Some('●');
+ } else {
+ return Some('◌');
}
+ } else {
+ return None;
}
- false
- }
-
- fn get_point(&self, point: Point) -> Option<Cell<State>> {
- self.get((point.y, point.x)).cloned()
}
}
for x in 0..=(map.x_size()) {
for y in 0..=(map.y_size()) {
let point = Point::new(x, y);
+ let char = map.draw_point(point).unwrap_or(' ');
let (x_off, y_off) = origin.u16_offset(point)?;
if x_off <= x_zero || x_off >= x_max || y_off <= y_zero || y_off >= y_max - 1 {
continue;
}
- if map.try_point(point) {
- queue!(
- stdout(),
- MoveTo(x_off, y_off),
- SetAttributes(style_on),
- SetColors(on_colors),
- Print(char_on)
- )?;
- } else {
- queue!(
- stdout(),
- MoveTo(x_off, y_off),
- SetAttributes(style_off),
- SetColors(off_colors),
- Print(char_off)
- )?;
- }
+ queue!(
+ stdout(),
+ MoveTo(x_off, y_off),
+ SetAttributes(style_on),
+ SetColors(on_colors),
+ Print(char)
+ )?;
}
}
use super::*;
pub trait Map<T> {
- fn try_point(&self, point: Point) -> bool;
- fn get_point(&self, point: Point) -> Option<T>;
+ fn draw_point(&self, point: Point) -> Option<char>;
fn x_size(&self) -> usize;
fn y_size(&self) -> usize;
fn characters(&self) -> (char, char);
self.nrows()
}
- fn try_point(&self, point: Point) -> bool {
- if let Some(note) = self.get((point.y, point.x)) {
- *note != Note::Off
- } else {
- false
- }
- }
-
- fn get_point(&self, point: Point) -> Option<Note> {
- self.get((point.y, point.x)).copied()
+ fn draw_point(&self, point: Point) -> Option<char> {
+ self.get((point.y, point.x)).map(|n| n.to_char())
}
fn characters(&self) -> (char, char) {
pub use scale::*;
pub use transport::*;
-use std::fmt::Display;
+use std::{fmt::Display, ops::Deref};
#[derive(Clone, Copy, Debug)]
pub struct TimeSignature {
}
}
+impl Note {
+ pub fn to_char(&self) -> char {
+ match self {
+ Note::Off => ' ',
+ Note::A(_) => 'a',
+ Note::B(_) => 'b',
+ Note::C(_) => 'c',
+ Note::D(_) => 'd',
+ Note::E(_) => 'e',
+ Note::F(_) => 'f',
+ Note::G(_) => 'g',
+ }
+ }
+}
+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Acc {
Flt,