我需要编写自己的Radial Gradient生成器(不使用像RadialGradientBrush这样的东西)。
目前,我的代码如下所示:
public float[,] radGrad(int width, int height, float threshold) {
float[,] grad = new float[width, height];
float cX = width * 0.5f;
float cY = height * 0.5f;
for (int y = 0; y < height; ++y) {
for(int x = 0; x < width; ++x) {
float pixel = (Math.Max(y, cY) - Math.Min(y, cY)) / (Math.Max(x, cX) - Math.Min(x, cX));
pixel = fLerp(pixel, 0, 255);
grad[x, y] = pixel;
}
}
return grad;
}
- 编辑: 接近@ 31eee384的建议......
public float[,] radGrad(int width, int height, float threshold) {
float[,] grad = new float[width, height];
float cX = width * 0.5f;
float cY = height * 0.5f;
for (int y = 0; y < height; ++y) {
for(int x =0; x < width; ++x) {
float distFromCenter = distance(cX, cY, x, y);
float pixel = (Math.Max(distFromCenter, cY) - Math.Min(distFromCenter, cY)) / (Math.Max(distFromCenter, height) - Math.Min(distFromCenter, height));
pixel = fLerp(pixel, 0, 255);
grad[x, y] = pixel;
}
}
return grad;
}
答案 0 :(得分:0)
我相信你应该犯罪!
public float[,] radGrad(int width, int height, float threshold) {
float[,] grad = new float[width, height];
int cX = width * 0.5f;
int cY = height * 0.5f;
for (int y = 0; y < cx; ++y) {
for(int x = 0; x < cy; ++x) {
float pixel = (Math.Sin(x / y));
pixel = fLerp(pixel, 0, 255);
grad[cx + x, cy + y] = pixel;
grad[cx + x, cy - y] = pixel;
grad[cx - x, cy + y] = pixel;
grad[cx - x, cy - y] = pixel;
}
}
return grad;
}
远非完美,但应该让你走上正确的道路。