You can start with the Asymptote
, which is included in TeXLive 2012
but can be used with other distributions as well.
It is able to handle both vector and raster graphics.
Following example gblur.asy
file
(which can be improved in many ways) draws a color matrix and then
applies a Gaussian filter matrix (from the wiki) to it once and twice:
size(200);
real[][] gFilt={
{0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067},
{0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292},
{0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117},
{0.00038771, 0.01330373, 0.11098164, 0.22508352, 0.11098164, 0.01330373, 0.00038771},
{0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117},
{0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292},
{0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067},
};
import pm;
import palette;
pen[][] matrix2pen(triple[][] pm){
int n=pm.length;
triple t;
pen[][] v=new pen[n][n];
for(int i=0; i < n; ++i){
for(int j=0; j < n; ++j){
t=pm[n-1-j][i];
v[i][j]=rgb(t.x/255,t.y/255,t.z/255);
}
}
return v;
}
triple[][] gBlur(triple[][] pm){
int n=pm.length;
int m=gFilt.length;
int di=floor((real)m/2);
triple[][]pmb=new triple[n][n];
triple t,s;
pen[][] v=new pen[n][n];
for(int i=0; i < n; ++i){
for(int j=0; j < n; ++j){
s=(0,0,0);
for(int gi=-di; gi <= di; ++gi){
for(int gj=-di; gj <=di; ++gj){
s+=pm[(n+i+gi)%n][(n+j+gj)%n]*gFilt[gi+di][gj+di];
}
}
pmb[i][j]=s;
}
}
return pmb;
}
image(matrix2pen(pm),(0,0),(1,1));
image(matrix2pen(gBlur(pm)),(1,0),(2,1));
image(matrix2pen(gBlur(gBlur(pm))),(2,0),(3,1));
It uses a sample color matrix in pm.asy
below:
triple[][] pm={
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,252),(255,255,255),(255,205,156),(255,205,156),(255,255,255),(255,254,252),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,253),(255,255,255),(255,248,240),(255,135,29),(255,135,29),(255,248,240),(255,255,255),(255,254,253),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,253,250),(255,255,255),(255,196,137),(255,120,0),(255,120,0),(255,196,137),(255,255,255),(255,253,250),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,253),(255,255,255),(255,232,211),(255,131,17),(255,126,1),(255,126,1),(255,131,17),(255,232,211),(255,255,255),(255,254,253),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,253),(255,255,255),(255,172,101),(255,117,0),(255,130,3),(255,130,3),(255,117,0),(255,172,101),(255,255,255),(255,254,253),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,253,251),(255,255,255),(255,213,172),(255,122,5),(255,128,3),(255,127,0),(255,127,0),(255,128,3),(255,122,5),(255,213,172),(255,255,255),(255,253,251),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,254),(255,254,253),(255,255,255),(255,152,57),(255,120,0),(255,129,3),(255,127,0),(255,127,0),(255,129,3),(255,120,0),(255,152,57),(255,255,255),(255,254,253),(255,255,254),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,253,252),(255,255,255),(255,201,145),(255,121,0),(255,128,4),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,128,4),(255,121,0),(255,201,145),(255,255,255),(255,253,252),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,253),(255,255,255),(255,239,224),(255,135,32),(255,122,0),(255,129,2),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,129,2),(255,122,0),(255,135,32),(255,239,224),(255,255,255),(255,254,253),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,252),(255,255,255),(255,189,130),(255,117,0),(255,130,5),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,130,5),(255,117,0),(255,189,130),(255,255,255),(255,254,252),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,254,252),(255,255,255),(255,230,207),(255,130,23),(255,126,0),(255,128,1),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,128,1),(255,126,0),(255,130,23),(255,230,207),(255,255,255),(255,254,252),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,254,252),(255,255,255),(255,165,80),(255,117,0),(255,130,3),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,130,3),(255,117,0),(255,165,80),(255,255,255),(255,254,252),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,253,251),(255,255,255),(255,219,182),(255,126,11),(255,127,1),(255,128,1),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,128,1),(255,127,1),(255,126,11),(255,219,182),(255,255,255),(255,253,251),(255,255,255),(255,255,255),},
{(255,255,255),(255,254,254),(255,255,255),(255,246,237),(255,147,54),(255,120,0),(255,129,3),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,129,3),(255,120,0),(255,147,54),(255,246,237),(255,255,255),(255,254,254),(255,255,255),},
{(255,255,255),(255,254,252),(255,255,255),(255,201,151),(255,118,0),(255,129,4),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,129,4),(255,118,0),(255,201,151),(255,255,255),(255,254,252),(255,255,255),},
{(255,254,254),(255,255,255),(255,239,223),(255,130,17),(255,125,0),(255,128,1),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,128,1),(255,125,0),(255,130,17),(255,239,223),(255,255,255),(255,254,254),},
{(255,252,250),(255,255,255),(255,182,109),(255,120,0),(255,131,7),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,131,7),(255,120,0),(255,182,109),(255,255,255),(255,252,250),},
{(255,255,255),(255,219,184),(255,119,7),(255,118,0),(255,120,1),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,120,1),(255,118,0),(255,119,7),(255,219,184),(255,255,255),},
{(255,255,255),(255,225,195),(255,197,142),(255,204,157),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,204,157),(255,197,142),(255,225,195),(255,255,255),},
{(252,252,253),(252,253,254),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,253,254),(252,252,253),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),},
{(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),},
{(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),},
};
To get a standalone gblur.eps
just run asy gblur.asy
,
to get gblur.pdf
run asy -f pdf gblur.asy
.
Best Answer
What you could do is layer lots of ellipses on top of each other, each one a little bit smaller and darker than the previous one. This gives the illusion of a smooth gradient, providing there are enough ellipses. In the code below I'm using ten ellipses, but you can adjust that to your liking.
Code
Result
In the code below, I used 100 ellipses. I also adjusted the opacity by a factor of
0.02
. There's no method to this, I just fiddled with the numbers until it looked "right".