More Cairo fun. This is really just a variant of my last post on the same subject. It uses a radial gradient in both the alpha channel and the hue spectrum. What is more signficant, is that the code to do this has all been "reified" so that doing it is starting to look like Smalltalk code, instead of a bunch of DLLCC invocations.
diameter := 128.
data := CIntegerType unsignedChar gcCalloc: diameter * 4 * diameter.
surface := ImageSurface
format: #alphaColor
extent: diameter asPoint
usingBits: data
stride: diameter * 4.
center := surface extent half.
radius := diameter half asDouble.
colorGradient := RadialGradient
from: center
radius: 0
to: center
radius: radius.
0 to: radius
do:
[:n |
colorGradient addStopAt: n / radius
colorValue: (ColorValue hue: n / radius)].
alphaGradient := RadialGradient
from: center
radius: 0
to: center
radius: radius.
alphaGradient addStopAt: 0 alpha: 0.
alphaGradient addStopAt: 0.5 alpha: 1.
alphaGradient addStopAt: 1 alpha: 0.
cc := surface context.
cc source: colorGradient.
cc mask: alphaGradient.
surface saveAsPng: '/home/travis/cairo_circle.png'
The one unfortunate aspect currently is that for whatever reason, I have to use an ImageSurface where I've allocated the memory locally. Otherwise, the image comes out with undefined artifacts.