Croissant Runtime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
crsn/examples/colorz.csn

67 lines
1.5 KiB

4 years ago
(
; 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)
)
)