From 822e5c356b7daa5245dbc69c70f8e92cb4d55f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bor=20Gro=C5=A1elj=20Simi=C4=87?= Date: Mon, 17 Jan 2022 04:13:22 +0100 Subject: [PATCH] add begin/end parameters --- main.ha | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/main.ha b/main.ha index b7f8abc..92337e1 100644 --- a/main.ha +++ b/main.ha @@ -6,8 +6,6 @@ use os; use strconv; use time; -def SAMPLES: uint = 50u; - fn init_scene() *hittable = { let ground = alloc(make_lambertian(&C(0.5, 0.5, 0.5))); let near = alloc(make_metal(&C(0.7, 0.6, 0.5), 0.00)); @@ -92,6 +90,7 @@ export fn main() void = { let seed = 0u; let samples: (uint | void) = void; let width: (uint | void) = void, height: (uint | void) = void; + let begin: (uint | void) = void, end: (uint | void) = void; for (let i = 0z; i < len(cmd.opts); i += 1) { let opt = cmd.opts[i]; switch (opt.0) { @@ -103,6 +102,10 @@ export fn main() void = { height = strconv::stou(opt.1) as uint; case 'S' => seed = strconv::stou(opt.1) as uint; + case 'b' => + begin = strconv::stou(opt.1) as uint; + case 'e' => + end = strconv::stou(opt.1) as uint; }; }; let samples = match (samples) { @@ -124,6 +127,17 @@ export fn main() void = { yield u; }; + if ((begin is void) ^^ (end is void)) { + abort(); + }; + let tup = match (begin) { + case void => + yield (0u, height); + case let u: uint => + yield (u, end: uint); + }; + let begin = tup.0, end = tup.1; + rng = math::random::init(seed); let img = image_create(width, height, C(0f64, 0f64, 0f64)); @@ -139,8 +153,10 @@ export fn main() void = { let max_bounce = 50u; let start = time::unix(time::now(time::clock::MONOTONIC)); - for (let j = 0z; j < height; j += 1) { - fmt::errorf("\rProgress: {}/{}", j, height)!; + for (let j = begin; j < end; j += 1) { + fmt::errorf("\rProgress: begin: {} current: {} end: {} | {}%", + begin, j, end, + ((j - begin): i64: f64 / (end - begin): i64: f64 * 100.0): int)!; for (let i = 0z; i < width; i += 1) { for (let k = 0u; k < samples; k += 1) { let u = i: int: f64; -- 2.45.2