|
76 | 76 | # Threshold set ad hoc and needs more experiments. |
77 | 77 | # 3.23.13.13 All docstrings go to ReST. |
78 | 78 | # 3.26.10.10 Pixel reading scheme changed. |
| 79 | +# 3.27.10.10 Rewritten from condensed f-strings to sparse list |
| 80 | +# in attempt to make it easier to edit further. |
| 81 | +# Turned to per row output to increase buffer. |
79 | 82 |
|
80 | 83 | __author__ = 'Ilya Razmanov' |
81 | 84 | __copyright__ = '(c) 2023-2026 Ilya Razmanov' |
82 | 85 | __credits__ = 'Ilya Razmanov' |
83 | 86 | __license__ = 'unlicense' |
84 | | -__version__ = '3.27.8.1' |
| 87 | +__version__ = '3.27.10.10' |
85 | 88 | __maintainer__ = 'Ilya Razmanov' |
86 | 89 | __email__ = 'ilyarazmanov@gmail.com' |
87 | 90 | __status__ = 'Production' |
@@ -280,9 +283,9 @@ def _src_lum_blin(x: float, y: float) -> float: |
280 | 283 | ' pigment {', |
281 | 284 | ' gradient z', |
282 | 285 | ' colour_map {', |
283 | | - ' [0.0, rgb <1, 0, 0>]', |
284 | | - ' [0.5, rgb <0, 0, 1>]', |
285 | | - ' [1.0, rgb <1, 1, 1>]', |
| 286 | + ' [0.0, rgb <1, 0, 0>]', # [0.0, rgb <0.0, 1.5, 0.0>] |
| 287 | + ' [0.5, rgb <0, 0, 1>]', # [0.5, rgb <0.88, 0.62, 0>] |
| 288 | + ' [1.0, rgb <1, 1, 1>]', # [1.0, rgb <1.5, 0.0, 0.0>] |
286 | 289 | ' }', |
287 | 290 | ' }', |
288 | 291 | ' finish {phong 1.0}', |
@@ -344,8 +347,7 @@ def _y_out(y: int, shift: float) -> float: |
344 | 347 | # ↑ Not needed for Python but Ruff gets mad about "Undefined name" without it. |
345 | 348 |
|
346 | 349 | for y in range(Y - 1): # Mesh includes extra pixels at the right and below, therefore -1 |
347 | | - resultfile.write(f'\n\n // Row {y}') |
348 | | - |
| 350 | + row = [f'\n\n // Row {y}'] # Starting a row of pyramids. |
349 | 351 | for x in range(X - 1): # Mesh includes extra pixels at the right and below, therefore -1 |
350 | 352 | """Pixel order around default pixel 1. |
351 | 353 | ┌───┬───┐ |
@@ -378,36 +380,65 @@ def _y_out(y: int, shift: float) -> float: |
378 | 380 |
|
379 | 381 | # ↓ Finally going to build a pyramid! |
380 | 382 | # Triangles are described clockwise. |
| 383 | + pyramid = [] |
381 | 384 |
|
| 385 | +# ↓ Triangle 1-2-0 |
382 | 386 | if (v1 + v2 + v0) > (0.5 / maxcolors): |
383 | | - triangle_120 = f'\n triangle {{<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v1:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v2:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>}}' |
384 | | - # ↑ Triangle 1-2-0 |
385 | | - else: |
386 | | - triangle_120 = '' |
| 387 | + pyramid.extend([ |
| 388 | +'\n triangle{', |
| 389 | +f'<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v1:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
| 390 | + |
| 391 | +f'<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v2:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
387 | 392 |
|
| 393 | +f'<{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
| 394 | +'}', |
| 395 | + ]) |
| 396 | +# ↑ Triangle 1-2-0 |
| 397 | + |
| 398 | +# ↓ Triangle 2-3-0 |
388 | 399 | if (v0 + v2 + v3) > (0.5 / maxcolors): |
389 | | - triangle_230 = f'\n triangle {{<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v2:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v3:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>}}' |
390 | | - # ↑ Triangle 2-3-0 |
391 | | - else: |
392 | | - triangle_230 = '' |
| 400 | + pyramid.extend([ |
| 401 | +'\n triangle{', |
| 402 | +f'<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v2:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
| 403 | + |
| 404 | +f'<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v3:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
393 | 405 |
|
| 406 | +f'<{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
| 407 | +'}', |
| 408 | + ]) |
| 409 | +# ↑ Triangle 2-3-0 |
| 410 | + |
| 411 | +# ↓ Triangle 3-4-0 |
394 | 412 | if (v0 + v3 + v4) > (0.5 / maxcolors): |
395 | | - triangle_340 = f'\n triangle {{<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v3:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v4:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>}}' |
396 | | - # ↑ Triangle 3-4-0 |
397 | | - else: |
398 | | - triangle_340 = '' |
| 413 | + pyramid.extend([ |
| 414 | +'\n triangle{', |
| 415 | +f'<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v3:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
399 | 416 |
|
400 | | - if (v0 + v1 + v4) > (0.5 / maxcolors): |
401 | | - triangle_410 = f'\n triangle {{<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v4:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v1:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>}}' |
402 | | - # ↑ Triangle 4-1-0 |
403 | | - else: |
404 | | - triangle_410 = '' |
| 417 | +f'<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v4:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
405 | 418 |
|
406 | | - # ↓ Built triangles as four strings, now writing pyramid |
407 | | - # as single string in attempt to reduce disk access. |
408 | | - resultfile.write(f'{triangle_120}{triangle_230}{triangle_340}{triangle_410}') |
| 419 | +f'<{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
| 420 | +'}', |
| 421 | + ]) |
| 422 | +# ↑ Triangle 3-4-0 |
409 | 423 |
|
410 | | - # ↑ Pyramid construction complete. Ave me! |
| 424 | +# ↓ Triangle 4-1-0 |
| 425 | + if (v0 + v1 + v4) > (0.5 / maxcolors): |
| 426 | + pyramid.extend([ |
| 427 | +'\n triangle{' |
| 428 | +f'<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v4:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
| 429 | + |
| 430 | +f'<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v1:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
| 431 | + |
| 432 | +f'<{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>', |
| 433 | +'}', |
| 434 | + ]) |
| 435 | +# ↑ Triangle 4-1-0 |
| 436 | + |
| 437 | + # ↓ Pyramid construction complete. Ave me! |
| 438 | + # Now adding it to a row. |
| 439 | + row.extend(pyramid) |
| 440 | + # ↓ Finally writing a row to file. |
| 441 | + resultfile.write(''.join(row)) |
411 | 442 |
|
412 | 443 | resultfile.write( |
413 | 444 | '\n'.join( |
|
0 commit comments