File tree 1 file changed +35
-0
lines changed 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -435,3 +435,38 @@ Example 3: Conic-gradient {#example-3}
435
435
--------------------------------------
436
436
437
437
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
+ <h1>
444
+ Heading 1
445
+ </h1>
446
+ <h1>
447
+ Another heading
448
+ </h1>
449
+
450
+ <style>
451
+ h1 {
452
+ background-image: paint(heading-color);
453
+ }
454
+ </style>
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>
You can’t perform that action at this time.
0 commit comments