Fix gradients to use rgbx.
|
@ -11,8 +11,8 @@ let paint = Paint(
|
|||
vec2(100, 200)
|
||||
],
|
||||
gradientStops: @[
|
||||
ColorStop(color: rgba(255, 0, 0, 255).color, position: 0),
|
||||
ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0),
|
||||
ColorStop(color: rgba(255, 0, 0, 255), position: 0),
|
||||
ColorStop(color: rgba(255, 0, 0, 40), position: 1.0),
|
||||
]
|
||||
)
|
||||
|
||||
|
@ -28,4 +28,4 @@ image.fillPath(
|
|||
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
|
||||
## 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.
|
||||
|
||||
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
|
||||
if index == -1:
|
||||
# first stop solid
|
||||
color = stops[0].color
|
||||
color = stops[0].color.color
|
||||
elif index + 1 >= stops.len:
|
||||
# last stop solid
|
||||
color = stops[index].color
|
||||
color = stops[index].color.color
|
||||
else:
|
||||
let
|
||||
gs1 = stops[index]
|
||||
gs2 = stops[index+1]
|
||||
color = mix(
|
||||
gs1.color,
|
||||
gs2.color,
|
||||
gs1.color.color,
|
||||
gs2.color.color,
|
||||
(a - gs1.position) / (gs2.position - gs1.position)
|
||||
)
|
||||
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),
|
||||
],
|
||||
gradientStops: @[
|
||||
ColorStop(color: rgba(255, 0, 0, 255).color, position: 0),
|
||||
ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0),
|
||||
ColorStop(color: rgba(255, 0, 0, 255), position: 0),
|
||||
ColorStop(color: rgba(255, 0, 0, 40), position: 1.0),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
@ -78,8 +78,8 @@ block:
|
|||
vec2(50, 100)
|
||||
],
|
||||
gradientStops: @[
|
||||
ColorStop(color: rgba(255, 0, 0, 255).color, position: 0),
|
||||
ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0),
|
||||
ColorStop(color: rgba(255, 0, 0, 255), position: 0),
|
||||
ColorStop(color: rgba(255, 0, 0, 40), position: 1.0),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
@ -99,8 +99,8 @@ block:
|
|||
vec2(50, 100)
|
||||
],
|
||||
gradientStops: @[
|
||||
ColorStop(color: rgba(255, 0, 0, 255).color, position: 0),
|
||||
ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0),
|
||||
ColorStop(color: rgba(255, 0, 0, 255), position: 0),
|
||||
ColorStop(color: rgba(255, 0, 0, 40), position: 1.0),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
|