demiromantic and demisexual flags now have proper, scalable rendering

This commit is contained in:
Valerie Wolfe 2023-07-03 17:43:54 -04:00
parent f7afc30f2e
commit bd00a2813f
3 changed files with 132 additions and 30 deletions

View file

@ -1,9 +1,14 @@
use std::process::exit;
use termion::{
terminal_size,
color::{ Bg, Rgb }
};
use crate::color::*;
use crate::draw;
use crate::flag;
use crate::variant;
/// vertically stacking eighths
pub static V_EIGHTH: [char; 7] = ['▁', '▂', '▃', '▄', '▅', '▆', '▇'];
@ -13,10 +18,13 @@ pub static H_EIGHTH: [char; 7] = ['▏', '▎', '▍', '▌', '▋', '▊', '▉
/// shading by intensity
pub static SHADING: [char; 3] = ['░', '▒', '▓'];
/// 2/1 slope triangle cut in
pub static TRIANGLE_21: [char; 3] = ['', '🭬', ''];
/// 2/3 slope slant
pub static SLANT_23: [char; 2] = ['🭒', '🭏'];
pub fn progress() -> Colors {
pub fn progress(small: bool) -> Colors {
let red = bg(0xE50000);
let orange = bg(0xFF8D00);
let yellow = bg(0xFFEE00);
@ -25,11 +33,17 @@ pub fn progress() -> Colors {
let purple = bg(0x770088);
// we need these colors in both fg & bg; just hold the integers for now
let black: u16 = 0;
let brown: u16 = 0x784F17;
let pink: u16 = 0xEAACB8;
let white: u16 = 0xFFFFFF;
let black: u32 = 0;
let brown: u32 = 0x784F17;
let pink: u32 = 0xEAACB8;
let white: u32 = 0xFFFFFF;
let (width, height) = if small { (6, 18) } else { terminal_size().unwrap() };
let stripes = vec![red, orange, yellow, green, blue, purple];
let mut lines = draw::bg_stripes(stripes, width, height);
draw::lines(lines, !small);
exit(0);
}
@ -41,32 +55,74 @@ pub fn aroace() {
}
pub fn demiromantic() {
let green = rgb(0x3DA542);
let gray = rgb(0xD2D2D2);
fn demi_orientation_render(middle: Bg<Rgb>, bottom: Bg<Rgb>, width: u16, height: u16) -> Vec<String> {
let white = bg(0xFFFFFF);
// WHITE×2 / green / gray×2 vert
// BLACK triangle cutin
let stripes = vec![white, white, middle, bottom, bottom];
// initial stripe output buffer
let mut lines: Vec<String> = draw::bg_stripes(stripes, width, height);
// assemble triangle cut-in
let linecount = lines.len();
let depth = linecount / 2;
let corner = linecount % 2 == 1;
for n in 0..depth {
let line = lines[n].clone();
let replacement = format!("{BLACK}{}{}", draw::BLOCK.repeat(n), TRIANGLE_21[0]);
lines[n] = line.replacen(&" ".repeat(n + 1), &replacement, 1);
}
if corner {
let line = lines[depth].clone();
let replacement = format!("{BLACK}{}{}", draw::BLOCK.repeat(depth), TRIANGLE_21[1]);
lines[depth] = line.replacen(&" ".repeat(depth + 1), &replacement, 1);
}
let start = depth + (linecount % 2);
for n in 0..depth {
let line = lines[start + n].clone();
let size = depth - n - 1;
let replacement = format!("{BLACK}{}{}", draw::BLOCK.repeat(size), TRIANGLE_21[2]);
lines[start + n] = line.replacen(&" ".repeat(size + 1), &replacement, 1);
}
pub fn demisexual() {
let purple = rgb(0x832FA8);
let grey = rgb(0x7B868C);
lines
}
// WHITE×2 / green / grey×2 vert
// BLACK triangle cutin
pub fn demiromantic(small: bool) -> Colors {
let green = bg(0x3DA542);
let gray = bg(0xD2D2D2);
let (width, height) = if small { (15, 5) } else { terminal_size().unwrap() };
let lines = demi_orientation_render(green, gray, width, height);
draw::lines(lines, !small);
exit(0);
}
pub fn demisexual(small: bool) -> Colors {
let purple = bg(0x832FA8);
let grey = bg(0x7B868C);
let (width, height) = if small { (15, 5) } else { terminal_size().unwrap() };
let lines = demi_orientation_render(purple, grey, width, height);
draw::lines(lines, !small);
exit(0);
}
pub fn disability() {
let gray = bg(0x575757);
let green = rgb(0x3AAD7D);
let blue = rgb(0x79BFE0);
let white = rgb(0xE8E8E8);
let yellow = rgb(0xEDDB76);
let red = rgb(0xCD7281);
let green: u32 = 0x3AAD7D;
let blue: u32 = 0x79BFE0;
let white: u32 = 0xE8E8E8;
let yellow: u32 = 0xEDDB76;
let red: u32 = 0xCD7281;
let stripe = [red, yellow, white, blue, green];
let stripes = [red, yellow, white, blue, green];
// 2/3 slant stripes with gray background
}

View file

@ -4,6 +4,7 @@ use termion::{
terminal_size,
clear,
color::{ Bg, Fg, Rgb },
cursor,
input::TermRead,
raw::IntoRawMode
@ -87,3 +88,48 @@ pub fn lines(lines: Vec<String>, hold: bool) {
stdout.flush().ok();
}
pub fn fg_stripes(colors: Vec<Fg<Rgb>>, width: u16, height: u16) -> Vec<String> {
let width = width as usize;
let height = height as usize;
let count = colors.len();
let thresh = height / count;
let stripe = BLOCK.repeat(width);
let mut output = Vec::new();
let mut index = 0;
for n in 0..height {
if n != 0 && n % thresh == 0 {
index += 1;
if index >= count { break; }
}
let color = colors[index];
output.push(format!("{color}{stripe}"));
}
output
}
pub fn bg_stripes(colors: Vec<Bg<Rgb>>, width: u16, height: u16) -> Vec<String> {
let width = width as usize;
let height = height as usize;
let count = colors.len();
let thresh = height / count;
let stripe = " ".repeat(width);
let mut output = Vec::new();
let mut index = 0;
for n in 0..height {
if n != 0 && n % thresh == 0 {
index += 1;
if index >= count { break; }
}
let color = colors[index];
output.push(format!("{color}{stripe}"));
}
output
}

View file

@ -47,8 +47,8 @@ fn main() {
=> variant::gilbert_baker(),
Some("philadelphia")
=> variant::philadelphia(),
// Some("progress")
// => complex::progress(),
Some("progress")
=> complex::progress(small),
_
=> flag::pride()
}
@ -76,11 +76,11 @@ fn main() {
Some("bisexual" | "bi")
=> flag::bisexual(),
// Some("demiromantic")
// => complex::demiromantic(),
Some("demiromantic")
=> complex::demiromantic(small),
// Some("demisexual")
// => complex::demisexual(),
Some("demisexual")
=> complex::demisexual(small),
// Some("disability")
// => complex::disability();
@ -149,8 +149,8 @@ fn list_text() {
// println!(" aroace aromantic/asexual pride flag");
println!(" bigender bigender pride flag");
println!(" bi, bisexual bisexual pride flag");
// println!(" demiromantic demiromantic pride flag");
// println!(" demisexual demisexual pride flag");
println!(" demiromantic demiromantic pride flag");
println!(" demisexual demisexual pride flag");
// println!(" disability disability pride flag");
println!(" gay, pride six-color rainbow flag");
println!(" genderfluid genderfluid pride flag");