Debian Codegraph @

examples/rgb_colours.rs

raw symbols SCIP
1 extern crate yansi_term;
2 use yansi_term::{Colour, Style};
3
4 // This example prints out a colour gradient in a grid by calculating each
5 // character’s red, green, and blue components, and using 24-bit colour codes
6 // to display them.
7
8 const WIDTH: i32 = 80;
9 const HEIGHT: i32 = 24;
10
11 fn main() {
12 for row in 0..HEIGHT {
13 for col in 0..WIDTH {
14 let r = (row * 255 / HEIGHT) as u8;
15 let g = (col * 255 / WIDTH) as u8;
16 let b = 128;
17
18 print!("{}", Style::default().on(Colour::RGB(r, g, b)).paint(" "));
19 }
20
21 println!();
22 }
23 }