Search in sources :

Example 1 with BiFun

use of primal.fp.Funs2.BiFun 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;
    });
}
Also used : Color(java.awt.Color) Friends.min(suite.util.Friends.min) LogUtil(suite.os.LogUtil) BufferedImage(java.awt.image.BufferedImage) Constants(suite.Constants) R3(suite.math.R3) IntInt_Obj(suite.primitive.IntInt_Obj) Thread_(suite.util.Thread_) Friends.max(suite.util.Friends.max) List(java.util.List) Floats_(suite.primitive.Floats_) JLabel(javax.swing.JLabel) ImageIcon(javax.swing.ImageIcon) Ints_(suite.primitive.Ints_) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) BiFun(suite.util.FunUtil2.BiFun) R3(suite.math.R3)

Example 2 with BiFun

use of primal.fp.Funs2.BiFun 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 ImageIcon (javax.swing.ImageIcon)2 JFrame (javax.swing.JFrame)2 JLabel (javax.swing.JLabel)2 R3 (suite.math.R3)2 Math.max (java.lang.Math.max)1 Math.min (java.lang.Math.min)1 List (java.util.List)1 BiFun (primal.fp.Funs2.BiFun)1 Log_ (primal.os.Log_)1 IntInt_Obj (primal.primitive.IntInt_Obj)1 NewInt (primal.primitive.IntVerbs.NewInt)1 Constants (suite.Constants)1 Defaults (suite.cfg.Defaults)1 LogUtil (suite.os.LogUtil)1 Floats_ (suite.primitive.Floats_)1 IntInt_Obj (suite.primitive.IntInt_Obj)1 Ints_ (suite.primitive.Ints_)1