new examples

floats
Ondřej Hruška 4 years ago
parent c953e39b34
commit 4cf24f0382
Signed by untrusted user: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 66
      examples/colorz.csn
  2. 66
      examples/purple.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)
)
)

@ -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)
)
)
Loading…
Cancel
Save