import { Sampler2D } from "../../../engine/graphics/texture/sampler/Sampler2D.js";
import sampler2D2Canvas from "../../../engine/graphics/texture/sampler/sampler2d_to_html_canvas.js";
import { CanvasView } from "../../../view/elements/CanvasView.js";
import { lerp } from "../../math/lerp.js";
import { sRGB_to_linear } from "../sRGB/sRGB_to_linear.js";
import { kelvin_to_rgb } from "./kelvin_to_rgb.js";

const view = new CanvasView();

view.css({
    position: 'fixed',
    left: '10px',
    top: '10px',
    zIndex: 5
});
view.size.set(400, 50);

document.body.append(view.el);

view.link();

const sampler = Sampler2D.float32(4, 400, 50);

const color = [1, 1, 1, 1];
for (let i = 0; i < sampler.width; i++) {
    const f = i / (sampler.width - 1);
    const k = lerp(1500, 20000, f);
    kelvin_to_rgb(color, 0, k);

    sRGB_to_linear(color, 0, color, 0);

    for (let j = 0; j < sampler.height; j++) {
        sampler.write(i, j, color);
        // sampler.write(i, j, [f, f, f, 1]);

    }
    // sampler.write(i, sampler.height - 1, [f, f, f, 1]);
}

console.log(sampler);

sampler2D2Canvas(sampler, 255, 0, view.el);


