Fix gradients to use rgbx.
|
@ -11,8 +11,8 @@ let paint = Paint(
|
||||||
vec2(100, 200)
|
vec2(100, 200)
|
||||||
],
|
],
|
||||||
gradientStops: @[
|
gradientStops: @[
|
||||||
ColorStop(color: rgba(255, 0, 0, 255).color, position: 0),
|
ColorStop(color: rgba(255, 0, 0, 255), position: 0),
|
||||||
ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0),
|
ColorStop(color: rgba(255, 0, 0, 40), position: 1.0),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,4 +28,4 @@ image.fillPath(
|
||||||
paint
|
paint
|
||||||
)
|
)
|
||||||
|
|
||||||
image.writeFile("examples/paint.png")
|
image.writeFile("examples/gradient.png")
|
||||||
|
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
|
@ -24,7 +24,7 @@ type
|
||||||
|
|
||||||
ColorStop* = object
|
ColorStop* = object
|
||||||
## Color stop on a gradient curve.
|
## Color stop on a gradient curve.
|
||||||
color*: Color ## Color of the stop
|
color*: ColorRGBX ## Color of the stop
|
||||||
position*: float32 ## Gradient Stop position 0..1.
|
position*: float32 ## Gradient Stop position 0..1.
|
||||||
|
|
||||||
proc toLineSpace(at, to, point: Vec2): float32 =
|
proc toLineSpace(at, to, point: Vec2): float32 =
|
||||||
|
@ -46,17 +46,17 @@ proc gradientPut(image: Image, x, y: int, a: float32, stops: seq[ColorStop]) =
|
||||||
var color: Color
|
var color: Color
|
||||||
if index == -1:
|
if index == -1:
|
||||||
# first stop solid
|
# first stop solid
|
||||||
color = stops[0].color
|
color = stops[0].color.color
|
||||||
elif index + 1 >= stops.len:
|
elif index + 1 >= stops.len:
|
||||||
# last stop solid
|
# last stop solid
|
||||||
color = stops[index].color
|
color = stops[index].color.color
|
||||||
else:
|
else:
|
||||||
let
|
let
|
||||||
gs1 = stops[index]
|
gs1 = stops[index]
|
||||||
gs2 = stops[index+1]
|
gs2 = stops[index+1]
|
||||||
color = mix(
|
color = mix(
|
||||||
gs1.color,
|
gs1.color.color,
|
||||||
gs2.color,
|
gs2.color.color,
|
||||||
(a - gs1.position) / (gs2.position - gs1.position)
|
(a - gs1.position) / (gs2.position - gs1.position)
|
||||||
)
|
)
|
||||||
image.setRgbaUnsafe(x, y, color.rgba.toPremultipliedAlpha())
|
image.setRgbaUnsafe(x, y, color.rgba.toPremultipliedAlpha())
|
||||||
|
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 5 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 5.5 KiB |
|
@ -58,8 +58,8 @@ block:
|
||||||
vec2(100, 50),
|
vec2(100, 50),
|
||||||
],
|
],
|
||||||
gradientStops: @[
|
gradientStops: @[
|
||||||
ColorStop(color: rgba(255, 0, 0, 255).color, position: 0),
|
ColorStop(color: rgba(255, 0, 0, 255), position: 0),
|
||||||
ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0),
|
ColorStop(color: rgba(255, 0, 0, 40), position: 1.0),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -78,8 +78,8 @@ block:
|
||||||
vec2(50, 100)
|
vec2(50, 100)
|
||||||
],
|
],
|
||||||
gradientStops: @[
|
gradientStops: @[
|
||||||
ColorStop(color: rgba(255, 0, 0, 255).color, position: 0),
|
ColorStop(color: rgba(255, 0, 0, 255), position: 0),
|
||||||
ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0),
|
ColorStop(color: rgba(255, 0, 0, 40), position: 1.0),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -99,8 +99,8 @@ block:
|
||||||
vec2(50, 100)
|
vec2(50, 100)
|
||||||
],
|
],
|
||||||
gradientStops: @[
|
gradientStops: @[
|
||||||
ColorStop(color: rgba(255, 0, 0, 255).color, position: 0),
|
ColorStop(color: rgba(255, 0, 0, 255), position: 0),
|
||||||
ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0),
|
ColorStop(color: rgba(255, 0, 0, 40), position: 1.0),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|