-- draw a gradient in a raw file (512x512) -- ugly LUA code by www.astrofra.com ------------------------------ function contrast(color_value) ------------------------------ return ((color_value * color_value) / 256); end ---------------------------- function invert(color_value) ---------------------------- return (255 - color_value); end ------------------------------------------------ function write_rgb_pixel(file_handler, r , g, b) ------------------------------------------------ r, g, b = invert(contrast(r)), invert(contrast(g)), invert(contrast(b)); if (r < 1) then r = 1; end; if (g < 1) then g = 1; end; if (b < 1) then b = 1; end; io.write(string.format("%s%s%s", string.char(r),string.char(g),string.char(b))); end -------------------------------------------------- -- main -------------------------------------------------- print("Gradient test"); file_name = "grad_out.raw"; file_handler = nil; bmp_size_x = 512; bmp_size_y = 512; print("open file "..file_name.." in write mode"); bmp_handler = io.open(file_name,"wb"); if not(bmp_handler) then print("io.open returned error"); return; end io.output(bmp_handler); for i = 0, bmp_size_x-1, 1 do r = (i * 255) / bmp_size_x; for j = 0, bmp_size_y-1, 1 do b = (j * 255) / bmp_size_y; g = (r + b) / 2; write_rgb_pixel(bmp_handler, r, g, b); end; end; io.close(bmp_handler); print("Done");