-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhoudini-stripes.js
More file actions
36 lines (33 loc) · 1.17 KB
/
Copy pathhoudini-stripes.js
File metadata and controls
36 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Houdini CSS Paint Worklet — Diagonal Stripes
* Draws subtle diagonal stripes as a background.
* Controlled via CSS custom properties:
* --stripe-color : stripe color (default rgba(255,255,255,0.08))
* --stripe-width : width of each stripe in px (default 6)
* --stripe-gap : gap between stripes in px (default 18)
*/
registerPaint('diagonal-stripes', class {
static get inputProperties() {
return [
'--stripe-color',
'--stripe-width',
'--stripe-gap',
];
}
paint(ctx, size, props) {
const color = props.get('--stripe-color').toString().trim() || 'rgba(255,255,255,0.08)';
const sw = parseFloat(props.get('--stripe-width')) || 6;
const gap = parseFloat(props.get('--stripe-gap')) || 18;
const step = sw + gap;
ctx.fillStyle = color;
// Draw diagonal stripes at 45 degrees across the element
const hyp = Math.sqrt(size.width * size.width + size.height * size.height);
ctx.save();
ctx.translate(size.width / 2, size.height / 2);
ctx.rotate(Math.PI / 4);
for (let x = -hyp; x < hyp; x += step) {
ctx.fillRect(x, -hyp, sw, hyp * 2);
}
ctx.restore();
}
});