mu/apps/texture.mu

54 lines
1.2 KiB
Forth
Raw Normal View History

2020-10-18 22:39:34 +00:00
# Playing with emitting cool textures.
#
# To run (on Linux):
# $ git clone https://github.com/akkartik/mu
# $ cd mu
# $ ./translate_mu apps/texture.mu
# $ ./a.elf > a.ppm
fn main -> exit-status/ebx: int {
#? var width/esi: int <- copy 0x190 # 400
#? var height/edi: int <- copy 0xe1 # 225; aspect ratio 16:9
var width/esi: int <- copy 0xff
var height/edi: int <- copy 0xff
print-string 0, "P3\n"
print-int32-decimal 0, width
print-string 0, " "
print-int32-decimal 0, height
print-string 0, "\n"
2020-10-18 22:49:20 +00:00
print-string 0, "255\n" # color depth
2020-10-18 22:39:34 +00:00
var row/ecx: int <- copy 0
{
compare row, height
break-if->=
var col/edx: int <- copy 0
{
compare col, width
break-if->=
# r
var tmp/eax: int <- copy col
2020-10-18 22:49:20 +00:00
tmp <- multiply row
tmp <- and 0xff
2020-10-18 22:39:34 +00:00
print-int32-decimal 0, tmp
print-string 0, " "
# g
tmp <- copy row
2020-10-18 22:49:20 +00:00
tmp <- multiply col
tmp <- and col
2020-10-18 22:39:34 +00:00
print-int32-decimal 0, tmp
print-string 0, " "
# b
2020-10-18 22:49:20 +00:00
tmp <- copy row
tmp <- multiply col
tmp <- and row
2020-10-18 22:39:34 +00:00
print-int32-decimal 0, tmp
print-string 0, "\n"
col <- increment
loop
}
row <- increment
loop
}
exit-status <- copy 0
}