aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dither.rs66
-rw-r--r--src/guide.rs7
-rw-r--r--src/lisp/prelude.rs23
3 files changed, 72 insertions, 24 deletions
diff --git a/src/dither.rs b/src/dither.rs
index c19bd6d..99e2839 100644
--- a/src/dither.rs
+++ b/src/dither.rs
@@ -1,24 +1,5 @@
1use crate::bitmap::MapPoint; 1use crate::bitmap::MapPoint;
2 2
3// dither intensities (rylander)
4// 0: none
5// 1: (1, 3)
6// 2: (3, 1)
7// 3: (3, 3)
8// 4: (1, 1)
9// 5: (1, 2)
10// 6: (3, 0)
11// 7: (3, 2)
12// 8: (1, 0)
13// 9: (0, 3)
14// 10: (2, 1)
15// 11: (2, 3)
16// 12: (0, 1)
17// 13: (0, 2)
18// 14: (2, 0)
19// 15: (2, 2)
20// 16: (0, 0)
21
22// dither intensities (bayers) 3// dither intensities (bayers)
23// 0: none 4// 0: none
24// 1: (0, 0) 5// 1: (0, 0)
@@ -65,3 +46,50 @@ pub fn bayer(level: u8, pt: MapPoint) -> bool {
65 } 46 }
66 } 47 }
67} 48}
49
50// dither intensities (rylander)
51// 0: none
52// 1: (1, 3)
53// 2: (3, 1)
54// 3: (3, 3)
55// 4: (1, 1)
56// 5: (1, 2)
57// 6: (3, 0)
58// 7: (3, 2)
59// 8: (1, 0)
60// 9: (0, 3)
61// 10: (2, 1)
62// 11: (2, 3)
63// 12: (0, 1)
64// 13: (0, 2)
65// 14: (2, 0)
66// 15: (2, 2)
67// 16: (0, 0)
68
69pub fn rylander(level: u8, pt: MapPoint) -> bool {
70 if level == 0 {
71 false
72 } else {
73 let MapPoint { x, y } = pt;
74 let r = (x % 4, y % 4);
75 match level {
76 01 => r == (1, 3) || rylander(00, pt),
77 02 => r == (3, 1) || rylander(01, pt),
78 03 => r == (3, 3) || rylander(02, pt),
79 04 => r == (1, 1) || rylander(03, pt),
80 05 => r == (1, 2) || rylander(04, pt),
81 06 => r == (3, 0) || rylander(05, pt),
82 07 => r == (3, 2) || rylander(06, pt),
83 08 => r == (1, 0) || rylander(07, pt),
84 09 => r == (0, 3) || rylander(08, pt),
85 10 => r == (2, 1) || rylander(09, pt),
86 11 => r == (2, 3) || rylander(10, pt),
87 12 => r == (0, 1) || rylander(11, pt),
88 13 => r == (0, 2) || rylander(12, pt),
89 14 => r == (2, 0) || rylander(13, pt),
90 15 => r == (2, 2) || rylander(14, pt),
91 16 => r == (0, 0) || rylander(15, pt),
92 _ => panic!("Invalid dither level!"),
93 }
94 }
95}
diff --git a/src/guide.rs b/src/guide.rs
new file mode 100644
index 0000000..006566e
--- /dev/null
+++ b/src/guide.rs
@@ -0,0 +1,7 @@
1use crate::bitmap::Axis;
2
3#[derive(Debug)]
4pub struct Guide {
5 axis: Axis,
6 offset: u32,
7}
diff --git a/src/lisp/prelude.rs b/src/lisp/prelude.rs
index 4a6a4ed..372bb00 100644
--- a/src/lisp/prelude.rs
+++ b/src/lisp/prelude.rs
@@ -27,6 +27,13 @@ macro_rules! primitive {
27} 27}
28 28
29#[macro_export] 29#[macro_export]
30macro_rules! define {
31 ($env:expr, $name:expr, $value:expr) => {
32 let _ = $env.insert($name.to_string(), $value);
33 };
34}
35
36#[macro_export]
30macro_rules! type_match { 37macro_rules! type_match {
31 ($args:expr, $($range:literal => $kind:pat),+) => { 38 ($args:expr, $($range:literal => $kind:pat),+) => {
32 { 39 {
@@ -54,6 +61,8 @@ macro_rules! type_match {
54pub fn new_env() -> Result<Environment, LispError> { 61pub fn new_env() -> Result<Environment, LispError> {
55 let mut env = Environment::new(); 62 let mut env = Environment::new();
56 63
64 define!(env, "else", LispExpr::BoolLit(true));
65
57 primitive!(env, Arity::Atleast(2), "+", |args, _| { 66 primitive!(env, Arity::Atleast(2), "+", |args, _| {
58 let nums = args 67 let nums = args
59 .into_iter() 68 .into_iter()
@@ -98,11 +107,6 @@ pub fn new_env() -> Result<Environment, LispError> {
98 Ok(LispExpr::Number(acc)) 107 Ok(LispExpr::Number(acc))
99 }); 108 });
100 109
101 primitive!(env, Arity::Exact(0), "toggle-grid", |_, app| {
102 app.toggle_grid();
103 Ok(LispExpr::Unit)
104 });
105
106 primitive!(env, Arity::Atleast(2), "and", |args, _| { 110 primitive!(env, Arity::Atleast(2), "and", |args, _| {
107 if args 111 if args
108 .iter() 112 .iter()
@@ -252,6 +256,15 @@ pub fn new_env() -> Result<Environment, LispError> {
252 } 256 }
253 }); 257 });
254 258
259 primitive!(env, Arity::Exact(0), "grid-enabled?", |_, app| {
260 Ok(LispExpr::BoolLit(app.grid.enabled))
261 });
262
263 primitive!(env, Arity::Exact(1), "set-grid!", |args, app| {
264 app.grid.enabled = args[0].cast_bool();
265 Ok(LispExpr::Unit)
266 });
267
255 primitive!(env, Arity::Exact(0), "brush-fill", |_, app| { 268 primitive!(env, Arity::Exact(0), "brush-fill", |_, app| {
256 app.brush = Brush::Fill; 269 app.brush = Brush::Fill;
257 return Ok(LispExpr::Unit); 270 return Ok(LispExpr::Unit);