From 4cf24f0382a20fd80c9d74de234e12da15003695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 11 Oct 2020 22:34:11 +0200 Subject: [PATCH] new examples --- examples/colorz.csn | 66 +++++++++++++++++++++++++++++++++++++++++++++ examples/purple.csn | 66 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 examples/colorz.csn create mode 100644 examples/purple.csn diff --git a/examples/colorz.csn b/examples/colorz.csn new file mode 100644 index 0000000..b5314f4 --- /dev/null +++ b/examples/colorz.csn @@ -0,0 +1,66 @@ +( + ; If you pipe a text file into this script, it will print it in random colors. + + (:n) + (ld r0 @cin (eof? (j :q))) + (cmp r0 '\n') + (j.eq :nl) + (rng r1 32 255) + (rng r2 32 255) + (rng r3 32 255) + (call rgb 1 r1 r2 r3) + (rng r1 0 64) + (rng r2 0 64) + (rng r3 0 64) + (call rgb 0 r1 r2 r3) + (ld @cout r0) + (j :n) + (:nl) + (ld @cout 27)(ld @cout '[')(ld @cout 'm')(ld @cout '\n') + (j :n) + (:q) + (ld @cout 27)(ld @cout '[')(ld @cout 'm') + (halt) + + (proc rgb fg r g b + (mkbf r7) + (ld @cout 27) + (ld @cout '[') + (tst fg + (z? (ld @cout '4')) + (nz? (ld @cout '3'))) + (ld @cout '8')(ld @cout ';')(ld @cout '2')(ld @cout ';') + + (call itoa r7 r) + (bfsz r0 @r7) + (ldn @cout @r7 r0) + (ld @cout ';') + + (call itoa r7 g) + (bfsz r0 @r7) + (ldn @cout @r7 r0) + (ld @cout ';') + + (call itoa r7 b) + (bfsz r0 @r7) + (ldn @cout @r7 r0) + + (ld @cout 'm') + (del @r7) + (ret) + ) + + (proc itoa buf num + (bfrsz @buf 0) + (ld r1 num) + (tst r1 (<0? (mul r1 -1))) + (:next) + (mod r0 r1 10) + (add r0 '0') + (bfrpush @buf r0) + (div r1 10 (z? + (tst num (<0? (bfrpush @buf '-'))) + (ret))) + (j :next) + ) +) diff --git a/examples/purple.csn b/examples/purple.csn new file mode 100644 index 0000000..ffcf349 --- /dev/null +++ b/examples/purple.csn @@ -0,0 +1,66 @@ +( + ; Do you like purple? I like purple + + (ld r0 10000) + (call rgb 1 255 0 255) + (:n) + (rng r1 100 160) + (rng r2 170 200) + (call rgb 0 r1 0 r2) + (rng r1 32 126) + (ld @cout r1) + (dec r0) + (j.nz :n) + (call resetcolor) + (ld @cout '\n') + (halt) + + (proc rgb fg r g b + (mkbf r7) + (ld @cout 27) + (ld @cout '[') + (tst fg + (z? (ld @cout '4')) + (nz? (ld @cout '3'))) + (ld @cout '8')(ld @cout ';')(ld @cout '2')(ld @cout ';') + + (call itoa r7 r) + (bfsz r0 @r7) + (ldn @cout @r7 r0) + (ld @cout ';') + + (call itoa r7 g) + (bfsz r0 @r7) + (ldn @cout @r7 r0) + (ld @cout ';') + + (call itoa r7 b) + (bfsz r0 @r7) + (ldn @cout @r7 r0) + + (ld @cout 'm') + (del @r7) + (ret) + ) + + (proc resetcolor + (ld @cout 27) + (ld @cout '[') + (ld @cout 'm') + (ret) + ) + + (proc itoa buf num + (bfrsz @buf 0) + (ld r1 num) + (tst r1 (<0? (mul r1 -1))) + (:next) + (mod r0 r1 10) + (add r0 '0') + (bfrpush @buf r0) + (div r1 10 (z? + (tst num (<0? (bfrpush @buf '-'))) + (ret))) + (j :next) + ) +)