[Proc Gen] ColorLayer - apply_threshold, apply_gradient, apply_ranges #201

Closed
opened 2026-01-12 00:08:52 +00:00 by john · 0 comments
Owner

Parent Issue: #192
Depends On: #193 (HeightMap core), #197 (HeightMap threshold - for value preservation)

Overview

Add methods to ColorLayer for applying HeightMap data to colors, including gradient interpolation.

Specification

def apply_threshold(self,
                    source: HeightMap,
                    range: tuple[float, float],
                    color: tuple[int, ...]) -> ColorLayer

Set fixed color where source value is in range. Color is (R, G, B) or (R, G, B, A).

def apply_gradient(self,
                   source: HeightMap,
                   range: tuple[float, float],
                   color_low: tuple[int, ...],
                   color_high: tuple[int, ...]) -> ColorLayer

Interpolate between colors based on source value within range.

  • At range minimum → color_low
  • At range maximum → color_high
def apply_ranges(self,
                 source: HeightMap,
                 ranges: list[tuple]) -> ColorLayer

Apply multiple color assignments. Each range maps to either a fixed color or a gradient.

Example

colors.apply_threshold(terrain, range=(0.0, 0.3), color=(0, 0, 180))

colors.apply_gradient(terrain, range=(0.3, 0.7), 
                      color_low=(50, 120, 50), 
                      color_high=(100, 200, 100))

colors.apply_ranges(terrain, [
    ((0.0, 0.3), (0, 0, 180)),                        # Fixed blue
    ((0.3, 0.7), ((50, 120, 50), (100, 200, 100))),  # Gradient (tuple of 2 colors)
    ((0.7, 1.0), ((100, 100, 100), (255, 255, 255))), # Gradient gray to white
])

Implementation Notes

  • For gradients, use the original HeightMap value for interpolation (not binary 0/1)
  • This is why HeightMap.threshold() preserves values - for gradient lerping
  • In apply_ranges, detect gradient vs fixed by checking if value is tuple of 2 tuples
  • Alpha defaults to 255 if not specified

Acceptance Criteria

  • apply_threshold sets fixed colors correctly
  • apply_gradient produces smooth color transitions
  • apply_ranges handles mixed fixed/gradient entries
  • Visual demo showing terrain coloring
**Parent Issue:** #192 **Depends On:** #193 (HeightMap core), #197 (HeightMap threshold - for value preservation) ## Overview Add methods to ColorLayer for applying HeightMap data to colors, including gradient interpolation. ## Specification ```python def apply_threshold(self, source: HeightMap, range: tuple[float, float], color: tuple[int, ...]) -> ColorLayer ``` Set fixed color where source value is in range. Color is `(R, G, B)` or `(R, G, B, A)`. ```python def apply_gradient(self, source: HeightMap, range: tuple[float, float], color_low: tuple[int, ...], color_high: tuple[int, ...]) -> ColorLayer ``` Interpolate between colors based on source value within range. - At range minimum → `color_low` - At range maximum → `color_high` ```python def apply_ranges(self, source: HeightMap, ranges: list[tuple]) -> ColorLayer ``` Apply multiple color assignments. Each range maps to either a fixed color or a gradient. ### Example ```python colors.apply_threshold(terrain, range=(0.0, 0.3), color=(0, 0, 180)) colors.apply_gradient(terrain, range=(0.3, 0.7), color_low=(50, 120, 50), color_high=(100, 200, 100)) colors.apply_ranges(terrain, [ ((0.0, 0.3), (0, 0, 180)), # Fixed blue ((0.3, 0.7), ((50, 120, 50), (100, 200, 100))), # Gradient (tuple of 2 colors) ((0.7, 1.0), ((100, 100, 100), (255, 255, 255))), # Gradient gray to white ]) ``` ## Implementation Notes - For gradients, use the **original HeightMap value** for interpolation (not binary 0/1) - This is why `HeightMap.threshold()` preserves values - for gradient lerping - In `apply_ranges`, detect gradient vs fixed by checking if value is tuple of 2 tuples - Alpha defaults to 255 if not specified ## Acceptance Criteria - [ ] `apply_threshold` sets fixed colors correctly - [ ] `apply_gradient` produces smooth color transitions - [ ] `apply_ranges` handles mixed fixed/gradient entries - [ ] Visual demo showing terrain coloring
john closed this issue 2026-01-12 03:35:52 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
john/McRogueFace#201
No description provided.