1
0

paint.l 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (
  2. (def gfx-w 16)
  3. (def gfx-h 16)
  4. (def block-size 16)
  5. (def gfxbuf (alloc (shl (* gfx-w gfx-h) 1)))
  6. (def palette (list 0x0000 0xffff 0x8888 0xf000 0x0f00 0x00f0 0x0f70 0xf00f))
  7. (def gfx-color 0x0000)
  8. (def get-gfx (fn x y (do
  9. (let ofs 0)
  10. (let ofs (shl (+ x (* y gfx-w)) 1))
  11. (let a (get gfxbuf ofs))
  12. (let b (get gfxbuf (+ 1 ofs)))
  13. (bitor (shl a 8) b)
  14. )))
  15. (def put-gfx (fn x y c (do
  16. (put gfxbuf (shl (+ x (* y gfx-w)) 1) (shr c 8))
  17. (put gfxbuf (+ (shl (+ x (* y gfx-w)) 1) 1) (bitand c 0xff))
  18. c
  19. )))
  20. (def render-gfx (fn (do
  21. (let x 0)
  22. (let y 0)
  23. (while (lt y gfx-h) (do
  24. (let x 0)
  25. (while (lt x gfx-w) (do
  26. (let c (get-gfx x y))
  27. (boxfill (* x block-size) (* y block-size) block-size block-size c)
  28. (let x (+ x 1))
  29. ))
  30. (let y (+ y 1))
  31. ))
  32. 0
  33. )))
  34. (def render-palette (fn (do
  35. (let x (* block-size gfx-w))
  36. (let y 0)
  37. (let pal palette)
  38. (let pal-bs 32)
  39. (while (cdr pal) (do
  40. (let c (car pal))
  41. (let x1 x)
  42. (let y1 (* y pal-bs))
  43. (boxfill x1 y1 pal-bs pal-bs c)
  44. (if (and mouse-btn (and (gt mouse-x x1) (and (lt mouse-y (+ y1 pal-bs)) (and (gt mouse-y y1) (lt mouse-x (+ x1 pal-bs))))))
  45. (def gfx-color c)
  46. 0)
  47. (let y (+ y 1))
  48. (let pal (cdr pal))
  49. ))
  50. 0
  51. )))
  52. (def gfx-task (fn (do
  53. (if mouse-btn (do
  54. (let mx (/ mouse-x block-size))
  55. (let my (/ mouse-y block-size))
  56. (if (and (lt mx gfx-w) (lt my gfx-h)) (do
  57. (put-gfx mx my gfx-color)
  58. ) 0)
  59. ) 0)
  60. (render-gfx)
  61. (render-palette)
  62. )))
  63. (def gfx (fn do
  64. (def tasks (list)) ; FIXME hack
  65. (mt-test)
  66. (add-task gfx-task)
  67. ))
  68. )