almost compact

master
Ondřej Hruška 5 years ago
parent ef4f3aedc1
commit 185158cf7b
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 551
      Cargo.lock
  2. 3
      Cargo.toml
  3. 256
      src/main.rs

551
Cargo.lock generated

@ -1,556 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "adler32"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2"
[[package]]
name = "approx"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3"
dependencies = [
"num-traits",
]
[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "bytemuck"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37fa13df2292ecb479ec23aa06f4507928bef07839be9ef15281411076629431"
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "color_quant"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd"
[[package]]
name = "conv"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299"
dependencies = [
"custom_derive",
]
[[package]]
name = "crc32fast"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-deque"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
"maybe-uninit",
]
[[package]]
name = "crossbeam-epoch"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"lazy_static",
"maybe-uninit",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-queue"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
dependencies = [
"autocfg",
"cfg-if",
"lazy_static",
]
[[package]]
name = "custom_derive"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9"
[[package]]
name = "deflate"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7e5d2a2273fed52a7f947ee55b092c4057025d7a3e04e5ecdbd25d6c3fb1bd7"
dependencies = [
"adler32",
"byteorder",
]
[[package]]
name = "either"
version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
[[package]]
name = "gammon"
version = "0.1.0"
dependencies = [
"image",
"imageproc",
"rusttype",
]
[[package]]
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "gif"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af"
dependencies = [
"color_quant",
"lzw",
]
[[package]]
name = "hermit-abi"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a0d737e0f947a1864e93d33fdef4af8445a00d1ed8dc0c8ddb73139ea6abf15"
dependencies = [
"libc",
]
[[package]]
name = "image"
version = "0.23.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9117f4167a8f21fa2bb3f17a652a760acd7572645281c98e3b612a26242c96ee"
dependencies = [
"bytemuck",
"byteorder",
"gif",
"jpeg-decoder",
"num-iter",
"num-rational",
"num-traits",
"png",
"scoped_threadpool",
"tiff",
]
[[package]]
name = "imageproc"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4552f3c2cbcf66e0451863120805b480fc421a7a8cf45f19eee5fc4a6fc3a3d3"
dependencies = [
"conv",
"image",
"itertools",
"num 0.2.1",
"rand",
"rand_distr",
"rayon",
"rulinalg",
"rusttype",
]
[[package]]
name = "inflate"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff"
dependencies = [
"adler32",
]
[[package]]
name = "itertools"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484"
dependencies = [
"either",
]
[[package]]
name = "jpeg-decoder"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0256f0aec7352539102a9efbcb75543227b7ab1117e0f95450023af730128451"
dependencies = [
"byteorder",
"rayon",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
[[package]]
name = "lzw"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
[[package]]
name = "matrixmultiply"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcad67dcec2d58ff56f6292582377e6921afdf3bfbd533e26fb8900ae575e002"
dependencies = [
"rawpointer",
]
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "memoffset"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8"
dependencies = [
"autocfg",
]
[[package]]
name = "miniz_oxide"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa679ff6578b1cddee93d7e82e263b94a575e0bfced07284eb0c037c1d2416a5"
dependencies = [
"adler32",
]
[[package]]
name = "num"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
dependencies = [
"num-integer",
"num-iter",
"num-traits",
]
[[package]]
name = "num"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36"
dependencies = [
"num-bigint",
"num-complex",
"num-integer",
"num-iter",
"num-rational",
"num-traits",
]
[[package]]
name = "num-bigint"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-complex"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-iter"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfb0800a0291891dd9f4fe7bd9c19384f98f7fbe0cd0f39a2c6b88b9868bbc00"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef"
dependencies = [
"autocfg",
"num-bigint",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "ordered-float"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518"
dependencies = [
"num-traits",
]
[[package]]
name = "png"
version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c68a431ed29933a4eb5709aca9800989758c97759345860fa5db3cfced0b65d"
dependencies = [
"bitflags",
"crc32fast",
"deflate",
"inflate",
]
[[package]]
name = "ppv-lite86"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom",
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_distr"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96977acbdd3a6576fb1d27391900035bf3863d4a16422973a409b488cf29ffb2"
dependencies = [
"rand",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core",
]
[[package]]
name = "rawpointer"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebac11a9d2e11f2af219b8b8d833b76b1ea0e054aa0e8d8e9e4cbde353bdf019"
[[package]]
name = "rayon"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098"
dependencies = [
"crossbeam-deque",
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9"
dependencies = [
"crossbeam-deque",
"crossbeam-queue",
"crossbeam-utils",
"lazy_static",
"num_cpus",
]
[[package]]
name = "rulinalg"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04ada202c9685e1d72a7420c578e92b358dbf807d3dfabb676a3dab9cc3bb12f"
dependencies = [
"matrixmultiply",
"num 0.1.42",
]
[[package]]
name = "rusttype"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f61411055101f7b60ecf1041d87fb74205fb20b0c7a723f07ef39174cf6b4c0"
dependencies = [
"approx",
"ordered-float",
"stb_truetype",
]
[[package]]
name = "scoped_threadpool"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "stb_truetype"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f77b6b07e862c66a9f3e62a07588fee67cd90a9135a2b942409f195507b4fb51"
dependencies = [
"byteorder",
]
[[package]]
name = "tiff"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "002351e428db1eb1d8656d4ca61947c3519ac3191e1c804d4600cd32093b77ad"
dependencies = [
"byteorder",
"lzw",
"miniz_oxide",
]
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"

@ -7,6 +7,3 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
image = "0.23.0"
imageproc = "0.20.0"
rusttype = "0.8.2"

@ -1,15 +1,9 @@
use std::default::Default;
use rusttype::{Scale, FontCollection, Font};
use imageproc::drawing;
use image::{GrayImage, RgbImage, Rgb, Luma};
use std::path::Path;
use imageproc::rect::Rect;
use std::fmt;
use std::fmt::Display;
#[derive(Debug,Clone,Copy,Eq,PartialEq)]
pub enum PlayerSide {
pub enum Side {
Black = 0,
White = 1,
}
@ -17,7 +11,7 @@ pub enum PlayerSide {
#[derive(Debug,Clone,Copy)]
pub enum Phase {
PickSides,
Turn(PlayerSide),
Turn(Side),
}
#[derive(Debug,Clone,Default)]
@ -28,7 +22,7 @@ pub struct Player {
#[derive(Debug,Clone,Copy)]
pub enum Bin {
Free,
Empty,
Black(u32),
White(u32),
}
@ -52,7 +46,7 @@ impl Default for Game {
Player::default(),
Player::default(),
],
bins: [Bin::Free; 24],
bins: [Bin::Empty; 24],
}
}
}
@ -60,242 +54,66 @@ impl Default for Game {
impl Display for Game {
fn fmt(&self, f : &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, " ")?;
for n in (13..=24).rev() { write!(f, "{:2}. ", n)?; }
write!(f, "\n╭ ")?;
for n in (13..=24) { write!(f, " {:2}", n)?; }
write!(f, "\n╭")?;
for b in &self.bins[12..=23] {
match *b {
Bin::Free => write!(f, "┈┈┈ ")?,
Bin::Black(n) => write!(f, "{:2}", n)?,
Bin::White(n) => write!(f, "{:2}", n)?
Bin::Empty => write!(f, " ┈┈")?,
Bin::Black(n) => write!(f, "{:2}#", n)?,
Bin::White(n) => write!(f, "{:2}:", n)?
}
}
write!(f, "╴\n╰ ")?;
write!(f, " > {}:\n╰", self.players[Side::Black as usize].born_off)?;
for b in (&self.bins[0..=11]).iter().rev() {
match *b {
Bin::Free => write!(f, "┈┈┈ ")?,
Bin::Black(n) => write!(f, "{:2}", n)?,
Bin::White(n) => write!(f, "{:2}", n)?
Bin::Empty => write!(f, " ┈┈")?,
Bin::Black(n) => write!(f, "{:2}#", n)?, //█
Bin::White(n) => write!(f, "{:2}:", n)? //░
}
}
write!(f, "╴\n ")?;
for n in (1..=12).rev() { write!(f, "{:2}. ", n)?; }
write!(f, " > {}#\n ", self.players[Side::Black as usize].born_off)?;
for n in (1..=12).rev() { write!(f, " {:2}", n)?; }
write!(f, "\n")?;
Ok(())
}
}
fn main() {
let mut board = Game::default();
board.bins[4] = Bin::Black(5);
board.bins[5] = Bin::Black(2);
board.bins[6] = Bin::Black(7);
board.bins[14] = Bin::White(9);
board.bins[15] = Bin::White(10);
board.bins[16] = Bin::White(11);
board.bins[2] = Bin::White(2);
// // let mut image = RgbImage::new(200, 200);
// let mut image : RgbImage = RgbImage::new(200, 200);
//
// let font = Vec::from(include_bytes!("DejaVuSans.ttf") as &[u8]);
// let font = FontCollection::from_bytes(font)
// .unwrap()
// .into_font()
// .unwrap();
//
// let height = 12.0;
// let scale = Scale {
// x: height,
// y: height,
// };
//
// let white = Rgb([255u8, 255u8, 255u8]);
//
// draw_text_mut(
// &mut image,
// white,
// 0,
// 0,
// scale,
// &font,
// "Hello, world!",
// );
//
// imageproc::drawing::draw_line_segment_mut(&mut image, (0.0, 0.0), (200.0,200.0), white);
//
// let _ = image.save("out.gif").unwrap();
let mut image = CrispImage::new(250, 60);
image.fill(BG);
fn draw_disc(image : &mut CrispImage, pos: (i32, i32), bin : Bin) {
match bin {
Bin::Free => {
image.circle_filled(GRAY, pos, 7);
},
Bin::Black(n) => {
let s = n.to_string();
// image.circle_filled(BLACK, pos, 7);
image.circle(WHITE, pos, 7);
image.text(WHITE, (pos.0 - (s.len() as i32 * 5)/2, pos.1 - 3), &s);
},
Bin::White(n) => {
let s = n.to_string();
image.circle_filled(WHITE, pos, 7);
image.circle(WHITE, pos, 7);
image.text(BLACK, (pos.0 - (s.len() as i32 * 5)/2, pos.1 - 3), &s);
},
}
}
for (i, n) in (13..=24).enumerate() {
let s = n.to_string();
image.text(YELLOW, (10 + 20 * i as i32 - (s.len() as i32 * 5)/2, 2), &s);
impl Game {
fn clear(&mut self) {
for i in 0..24 {
self.bins[i] = Bin::Empty;
}
for (i, n) in (1..=12).rev().enumerate() {
let s = n.to_string();
image.text(YELLOW, (10 + 20 * i as i32 - (s.len() as i32 * 5)/2, 51), &s);
}
//
// let s = "1";
// image.text(YELLOW, (10 - (s.len() as i32 * 5)/2, 2), &s);
//
// let s = "13";
// image.text(YELLOW, (30 - (s.len() as i32 * 5)/2, 2), &s);
draw_disc(&mut image, (10, 20), Bin::Black(7));
draw_disc(&mut image, (30, 20), Bin::Black(13));
draw_disc(&mut image, (50, 20), Bin::Free);
draw_disc(&mut image, (70, 20), Bin::White(69));
draw_disc(&mut image, (90, 20), Bin::White(9));
for n in 1..=7 {
draw_disc(&mut image, (90+n*20, 20), Bin::Free);
fn set(&mut self, n : u32, val : Bin) {
assert!(n > 0 && n <= 24);
let i = n - 1;
self.bins[i as usize] = val;
}
for n in 0..=11 {
draw_disc(&mut image, (10 + n*20, 40), Bin::Free);
fn starting_position(&mut self) {
self.clear();
self.set(1, Bin::White(2));
self.set(6, Bin::Black(5));
self.set(8, Bin::Black(3));
self.set(12, Bin::White(5));
self.set(13, Bin::Black(5));
self.set(17, Bin::White(3));
self.set(19, Bin::White(5));
self.set(24, Bin::Black(2));
}
image.render("out.png");
println!("{}", board);
}
type Color = Rgb<u8>;
struct CrispImage<'a> {
image : RgbImage,
font: Font<'a>,
width: u32,
height: u32,
font_scale: Scale,
}
const BG : Color = Rgb([18, 26, 36]);
const BLACK : Color = Rgb([0, 0, 0]);
const GRAY : Color = Rgb([67, 83, 104]);
const WHITE : Color = Rgb([255, 255, 255]);
const RED : Color = Rgb([255, 0, 0]);
const YELLOW : Color = Rgb([255, 255, 0]);
const GREEN : Color = Rgb([0, 255, 0]);
const BLUE : Color = Rgb([0, 0, 255]);
const CYAN : Color = Rgb([0, 255, 255]);
const MAGENTA : Color = Rgb([255, 0, 255]);
impl<'a> CrispImage<'a> {
fn new(width: u32, height: u32) -> Self {
let mut image : RgbImage = RgbImage::new(width, height);
// let font_bytes = include_bytes!("DejaVuSans.ttf");
// let font_bytes = include_bytes!("lilliput steps.ttf");
// let font_bytes = include_bytes!("fixedsys.ttf"); // 16.2
// let font_bytes = include_bytes!("DOSVGA.ttf"); // 16
let font_bytes = include_bytes!("coders_crux.ttf"); // 8.86
let font = Vec::from(font_bytes as &[u8]);
let font = FontCollection::from_bytes(font)
.unwrap()
.into_font()
.unwrap();
Self {
image,
font,
width,
height,
font_scale: Scale {
/* x: 16.,
y: 16.,*/
x: 8.86,
y: 8.86,
},
}
}
fn fill(&mut self, color: Color) {
self.rect_filled(color, (0,0), (self.width, self.height));
}
fn render(&self, path : impl AsRef<Path>) {
let _ = self.image.save(path).unwrap();
}
fn font_scale(&mut self, f : f32) {
self.font_scale.x = f;
self.font_scale.y = f;
}
fn text(&mut self, color: Color, pos : (i32, i32), text: &str) {
assert!(pos.0 >= 0);
assert!(pos.1 >= 0);
drawing::draw_text_mut(
&mut self.image,
color,
pos.0 as u32,
pos.1 as u32,
self.font_scale,
&self.font,
text,
);
}
fn main() {
let mut board = Game::default();
fn circle(&mut self, color: Color, center: (i32, i32), radius: i32) {
drawing::draw_hollow_circle_mut(&mut self.image, center, radius, color);
}
board.starting_position();
fn circle_filled(&mut self, color: Color, center: (i32, i32), radius: i32) {
drawing::draw_filled_circle_mut(&mut self.image, center, radius, color);
}
println!("{}", board);
fn line(&mut self, color: Color, from: (i32, i32), to: (i32, i32)) {
drawing::draw_line_segment_mut(&mut self.image,
(from.0 as f32, from.1 as f32),
(to.0 as f32, to.1 as f32),
color);
}
fn rect(&mut self, color: Color, tl: (i32, i32), size: (u32, u32)) {
drawing::draw_hollow_rect_mut(&mut self.image,
Rect::at(tl.0, tl.1).of_size(size.0, size.1),
color);
}
fn rect_filled(&mut self, color: Color, tl: (i32, i32), size: (u32, u32)) {
drawing::draw_filled_rect_mut(&mut self.image,
Rect::at(tl.0, tl.1).of_size(size.0, size.1),
color);
}
}

Loading…
Cancel
Save