use of primal.primitive.IntInt_Obj in project suite by stupidsing.
the class Render method renderPixels.
public Image renderPixels(int width, int height, IntInt_Obj<R3> f) {
var nThreads = Defaults.nThreads;
var txs = NewInt.array(nThreads + 1, i -> width * i / nThreads);
var pixels = new R3[width][height];
forInt(nThreads).collect(As.executeThreadsByInt(t -> {
for (var x = txs[t]; x < txs[t + 1]; x++) for (var y = 0; y < height; y++) pixels[x][y] = f.apply(x, y);
}));
var image = new Image(width, height, BufferedImage.TYPE_INT_RGB);
for (var x = 0; x < width; x++) for (var y = 0; y < height; y++) {
var pixel = limit(pixels[x][y]);
image.setRGB(x, y, new Color(pixel.x, pixel.y, pixel.z).getRGB());
}
return image;
}
use of primal.primitive.IntInt_Obj in project suite by stupidsing.
the class Render method render.
public Image render(int width, int height, BiFun<Float, R3> f) {
var scale = 1f / max(width, height);
int centerX = width / 2, centerY = height / 2;
var xs = To.vector(width + 1, x -> (x - centerX) * scale);
var ys = To.vector(height + 1, y -> (y - centerY) * scale);
return renderPixels(width, height, (IntInt_Obj<R3>) (x, y) -> {
R3 color;
try {
color = f.apply(xs[x], ys[y]);
} catch (Exception ex) {
Log_.error(new RuntimeException("at (" + x + ", " + y + ")", ex));
color = new R3(1d, 1d, 1d);
}
return color;
});
}
Aggregations