Skip to content

Commit 3ebf001

Browse files
committed
[css-paint-api] Add heading example.
1 parent 2b7a93b commit 3ebf001

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

css-paint-api/Overview.bs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,38 @@ Example 3: Conic-gradient {#example-3}
435435
--------------------------------------
436436

437437
Issue: Add conic-gradient as a use case.
438+
439+
Example 4: Different color based on geometry {#example-4}
440+
---------------------------------------------------------
441+
442+
<pre class='lang-markup'>
443+
&lt;h1&gt;
444+
Heading 1
445+
&lt;/h1&gt;
446+
&lt;h1&gt;
447+
Another heading
448+
&lt;/h1&gt;
449+
450+
&lt;style&gt;
451+
h1 {
452+
background-image: paint(heading-color);
453+
}
454+
&lt;/style&gt;
455+
</pre>
456+
457+
<pre class='lang-javascript'>
458+
// Inside PaintWorkletGlobalScope.
459+
registerPaint('heading-color', class {
460+
static get inputProperties() { return []; }
461+
paint(ctx, geom, properties) {
462+
// Select a color based on the width and height of the image.
463+
const width = geom.width;
464+
const height = geom.height;
465+
const color = colorArray[(width * height) % colorArray.length];
466+
467+
// Draw just a solid image.
468+
ctx.fillStyle = color;
469+
ctx.fillRect(0, 0, width, height);
470+
}
471+
});
472+
</pre>

0 commit comments

Comments
 (0)