Search in sources :

Example 1 with IntInt_Obj

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;
}
Also used : Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage) R3(suite.math.R3) To(suite.util.To) Math.min(java.lang.Math.min) IntInt_Obj(primal.primitive.IntInt_Obj) Log_(primal.os.Log_) Streamlet_.forInt(suite.util.Streamlet_.forInt) Defaults(suite.cfg.Defaults) JLabel(javax.swing.JLabel) Math.max(java.lang.Math.max) ImageIcon(javax.swing.ImageIcon) As(suite.streamlet.As) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) NewInt(primal.primitive.IntVerbs.NewInt) BiFun(primal.fp.Funs2.BiFun) R3(suite.math.R3) Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage)

Example 2 with IntInt_Obj

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;
    });
}
Also used : Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage) R3(suite.math.R3) To(suite.util.To) Math.min(java.lang.Math.min) IntInt_Obj(primal.primitive.IntInt_Obj) Log_(primal.os.Log_) Streamlet_.forInt(suite.util.Streamlet_.forInt) Defaults(suite.cfg.Defaults) JLabel(javax.swing.JLabel) Math.max(java.lang.Math.max) ImageIcon(javax.swing.ImageIcon) As(suite.streamlet.As) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) NewInt(primal.primitive.IntVerbs.NewInt) BiFun(primal.fp.Funs2.BiFun) R3(suite.math.R3)

Aggregations

BorderLayout (java.awt.BorderLayout)2 Color (java.awt.Color)2 BufferedImage (java.awt.image.BufferedImage)2 Math.max (java.lang.Math.max)2 Math.min (java.lang.Math.min)2 ImageIcon (javax.swing.ImageIcon)2 JFrame (javax.swing.JFrame)2 JLabel (javax.swing.JLabel)2 BiFun (primal.fp.Funs2.BiFun)2 Log_ (primal.os.Log_)2 IntInt_Obj (primal.primitive.IntInt_Obj)2 NewInt (primal.primitive.IntVerbs.NewInt)2 Defaults (suite.cfg.Defaults)2 R3 (suite.math.R3)2 As (suite.streamlet.As)2 Streamlet_.forInt (suite.util.Streamlet_.forInt)2 To (suite.util.To)2