Skip to content

Shift a color treatment

Read as Markdown

Compare grayscale, hue rotation, and inversion independently against a colorful original.

Plain source. Run as a browser module after the document body exists. TSX uses jsx: "react-jsx" and jsxImportSource: "@pibbl/core".

import { pibbl, Group, Circle, Rectangle, Text } from "@pibbl/core";
import {
grayscale,
hueRotate,
invert,
type PibblFilter,
type PibblGrayscaleFilterOptions,
type PibblHueRotateFilterOptions,
type PibblInvertFilterOptions,
} from "@pibbl/core/filters";
const gray: PibblGrayscaleFilterOptions = { amount: 1 };
const hue: PibblHueRotateFilterOptions = { degrees: 150 };
const inversion: PibblInvertFilterOptions = { amount: 1 };
const comparisons: [string, PibblFilter | undefined][] = [
["Original", undefined],
["Grayscale 1", grayscale(gray)],
["Hue rotation 150 degrees", hueRotate(hue)],
["Invert 1", invert(inversion)],
];
function Subject() {
return (
<>
<Rectangle
style={{ left: 22, top: 30, width: 60, height: 92, fill: "#277e99" }}
/>
<Rectangle
style={{ left: 82, top: 30, width: 60, height: 92, fill: "#dc7764" }}
/>
<Rectangle
style={{ left: 142, top: 30, width: 60, height: 92, fill: "#ddb84f" }}
/>
<Circle style={{ cx: 112, cy: 73, radius: 32, fill: "#23333a" }} />
<Text
style={{
left: 112,
top: 82,
textAlign: "center",
font: "bold 23px sans-serif",
fill: "#fff",
}}
>
Pibbl
</Text>
</>
);
}
const grid = document.createElement("div");
grid.style.cssText =
"display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:16px;max-width:480px";
document.body.append(grid);
const controllers = comparisons.map(([label, filter]) => {
const figure = document.createElement("figure");
figure.style.margin = "0";
const caption = document.createElement("figcaption");
caption.textContent = label;
const canvas = document.createElement("canvas");
canvas.width = 224;
canvas.height = 156;
figure.append(caption, canvas);
grid.append(figure);
return pibbl(
canvas,
<>
<Rectangle style={{ width: 224, height: 156, fill: "#f1f4f5" }} />
{Array.from({ length: 70 }, (_, i) => (
<Rectangle
key={i}
style={{
left: (i % 10) * 24,
top: Math.floor(i / 10) * 24,
width: 24,
height: 24,
fill: (i + Math.floor(i / 10)) % 2 ? "#e0e6e9" : "#f1f4f5",
}}
/>
))}
<Group style={{ filter }}>
<Subject />
</Group>
</>,
);
});
window.addEventListener(
"pagehide",
() => controllers.forEach((controller) => controller.dispose()),
{ once: true },
);
  • The option objects are typed before their factories create opaque filters.

Documentation built with @pibbl/core 0.0.2, revision 2dccb19. ALPHA — NOT FOR PRODUCTION USE.