[orx-shade-styles] Revise level quantization

This commit is contained in:
Edwin Jakobs
2025-03-06 20:48:22 +01:00
parent 49a3f3ea49
commit 5b55405a51
2 changed files with 50 additions and 2 deletions

View File

@@ -104,8 +104,8 @@ open class GradientBase<C>(
if (p_quantization != 0) {
f *= float(p_quantization);
f = floor(f + 0.5);
f /= float(p_quantization);
f = floor(f);
f /= float(p_quantization) - 1.0;
}
float sf;

View File

@@ -0,0 +1,48 @@
package gradients
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.loadFont
import org.openrndr.extra.camera.Camera2D
import org.openrndr.extra.color.presets.BLUE_STEEL
import org.openrndr.extra.shadestyles.fills.FillFit
import org.openrndr.extra.shadestyles.fills.FillUnits
import org.openrndr.extra.shadestyles.fills.SpreadMethod
import org.openrndr.extra.shadestyles.fills.gradients.gradient
import org.openrndr.extra.shapes.primitives.grid
import org.openrndr.math.Vector2
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin
fun main() = application {
configure {
width = 720
height = 720
}
program {
extend(Camera2D())
extend {
val grid = drawer.bounds.grid(48, 1)
drawer.stroke = null
for ((index, cell) in grid.flatten().withIndex()) {
drawer.shadeStyle = gradient<ColorRGBa> {
quantization = index + 2
stops[0.0] = ColorRGBa.WHITE
stops[ (quantization) / (quantization+1.0)] = ColorRGBa.BLACK
fillUnits = FillUnits.BOUNDS
fillFit = FillFit.COVER
spreadMethod = SpreadMethod.PAD
linear {
start = Vector2(0.5, 0.0)
end = Vector2(0.5, 1.0)
}
}
drawer.rectangle(cell)
}
}
}
}