1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-02 16:43:02 +00:00

Add more drawing examples.

This commit is contained in:
Calvin Rose
2024-11-25 09:39:55 -06:00
parent c13ef02ea2
commit 9fa9286fca
3 changed files with 26 additions and 37 deletions

View File

@@ -51,14 +51,14 @@
(while (< y h)
(var x:uint 0)
(while (< x w)
(write_32 (if (< y 32) blue red))
(write_32 (if (> y 64) blue red))
(set x (+ 1 x)))
(set y (+ y 1)))
(return))
(defsys main:int []
(def w:uint 128)
(def h:uint 128)
(def w:uint 512)
(def h:uint 512)
(write_header w h)
(draw w h)
(return 0))

View File

@@ -2,6 +2,9 @@
### Create a .bmp file on linux.
###
# Quick run and view on Linux:
# build/janet examples/sysir/drawing2.janet > temp.c && cc temp.c && ./a.out > temp.bmp && feh temp.bmp
(use ./frontend)
(defpointer p32 uint)
@@ -15,7 +18,7 @@
(defsys w32:void [c:cursor x:uint]
(def p:p32 (load c))
(store p x)
(store c (the p32 (pointer-add p 4)))
(store c (the p32 (pointer-add p 1)))
(return))
(defsys w16:void [c:cursor x:uint]
@@ -28,14 +31,17 @@
(defsys makebmp:p32 [w:uint h:uint]
(def size:uint (+ 56 (* w h 4)))
(def mem:p32 (malloc size))
(def c:cursor (address mem))
(w16 c 0x424D) # ascii "BM"
(def cursor_data:p32 mem)
(def c:cursor (address cursor_data))
(w16 c 0x4D42) # ascii "BM"
(w32 c size)
(w32 c 0)
(w32 c 56)
(w32 c 40)
(w32 c w)
(w32 c h)
(w32 c 0x20001)
(w16 c 1)
(w16 c 32)
(w32 c 0)
(w32 c 0)
(w32 c 4096)
@@ -46,12 +52,10 @@
# Draw
(def red:uint 0xFFFF0000)
(def blue:uint 0xFF0000FF)
(def size:uint (* w h 4))
(var y:uint 0)
(while (< y h)
(var x:uint 0)
(while (< x w)
#(write_32 (if (< y 32) blue red))
(if (> y 64)
(w32 c blue)
(w32 c red))
@@ -60,31 +64,10 @@
(write 1 mem size)
(return mem))
(defsys makebmp2:p32 [w:uint h:uint]
(def size:uint 56)
(def mem:p32 (malloc size))
(def c:cursor (address mem))
(w32 c 0x12345678)
(w32 c size)
(w32 c 56)
(w32 c 40)
(w32 c w)
(w32 c h)
(w32 c 0x20001)
(w32 c 0)
(w32 c 0)
(w32 c 4096)
(w32 c 4096)
(w32 c 0)
(w32 c 0)
(write 1 mem size)
(return mem))
(defsys main:int []
(def w:uint 128)
(def h:uint 128)
#(makebmp w h)
(makebmp2 w h)
(def h:uint 512)
(makebmp w h)
(return 0))
####