use of suite.primitive.IntInt_Obj in project suite by stupidsing.
the class Render method renderPixels.
public Image renderPixels(int width, int height, IntInt_Obj<R3> f) {
int nThreads = Constants.nThreads;
int[] txs = Ints_.toArray(nThreads + 1, i -> width * i / nThreads);
R3[][] pixels = new R3[width][height];
List<Thread> threads = //
Ints_.range(//
nThreads).map(t -> Thread_.newThread(() -> {
for (int x = txs[t]; x < txs[t + 1]; x++) for (int y = 0; y < height; y++) pixels[x][y] = f.apply(x, y);
})).toList();
Thread_.startJoin(threads);
Image image = new Image(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) {
R3 pixel = limit(pixels[x][y]);
image.setRGB(x, y, new Color(pixel.x, pixel.y, pixel.z).getRGB());
}
return image;
}
use of suite.primitive.IntInt_Obj in project suite by stupidsing.
the class Render method render.
public Image render(int width, int height, BiFun<Float, R3> f) {
float scale = 1f / max(width, height);
int centerX = width / 2, centerY = height / 2;
float[] xs = Floats_.toArray(width + 1, x -> (x - centerX) * scale);
float[] ys = Floats_.toArray(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) {
LogUtil.error(new RuntimeException("at (" + x + ", " + y + ")", ex));
color = new R3(1d, 1d, 1d);
}
return color;
});
}
Aggregations