summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/DankMaterialShell/quickshell/Modules/BuiltinDesktopPlugins/OrganicBlobHourBulges.qml
blob: cced1a4127ad0084d683056ff7ddc8392aa669be (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import QtQuick
import QtQuick.Shapes

Item {
    id: root

    property color fillColor: "transparent"

    property int lobes: 12
    property real lobeAmount: 0.070
    property real roundness: 0.22
    property real hillPower: 0.78
    property real paddingFrac: 0.020
    property real inset: 0
    property int segments: 120
    property real rotationDeg: -90

    layer.enabled: true
    layer.samples: 4

    function sgn(v) {
        return v < 0 ? -1 : 1;
    }
    function clamp(v, a, b) {
        return Math.max(a, Math.min(b, v));
    }

    function squircleMap(u, v, p) {
        const ax = sgn(u) * Math.pow(Math.abs(u), p);
        const ay = sgn(v) * Math.pow(Math.abs(v), p);
        return {
            x: ax,
            y: ay
        };
    }

    function buildPathD(w, h) {
        const x0 = inset, y0 = inset;
        const x1 = w - inset, y1 = h - inset;
        const iw = Math.max(2, x1 - x0);
        const ih = Math.max(2, y1 - y0);

        const cx = x0 + iw * 0.5;
        const cy = y0 + ih * 0.5;

        const rx = iw * 0.5;
        const ry = ih * 0.5;
        const rMin = Math.min(rx, ry);

        const amp = clamp(lobeAmount, 0.0, 0.14) * rMin;
        const extraPad = paddingFrac * rMin + 1.5;
        const pad = amp + extraPad;

        const rxBase = Math.max(2, rx - pad);
        const ryBase = Math.max(2, ry - pad);

        const blend = clamp(roundness, 0.0, 0.45);
        const squirclePow = 1.0 + blend * 2.8;

        const N = Math.max(48, segments);
        const rot = rotationDeg * Math.PI / 180.0;
        const dt = (Math.PI * 2.0) / N;

        function hillWave(a) {
            const t = (Math.cos(lobes * a) + 1.0) * 0.5;
            return Math.pow(t, hillPower);
        }

        function P(t) {
            const a = t + rot;
            const u = Math.cos(a);
            const v = Math.sin(a);

            const m = 1.0 + (amp / rMin) * hillWave(a);

            const ex = u * rxBase * m;
            const ey = v * ryBase * m;

            const sm = squircleMap(u, v, 1.0 / squirclePow);
            const sx = sm.x * rxBase * m;
            const sy = sm.y * ryBase * m;

            const x = ex * (1.0 - blend) + sx * blend;
            const y = ey * (1.0 - blend) + sy * blend;
            return {
                x: cx + x,
                y: cy + y
            };
        }

        function dP(t) {
            const eps = dt * 0.25;
            const p1 = P(t - eps);
            const p2 = P(t + eps);
            return {
                x: (p2.x - p1.x) / (2 * eps),
                y: (p2.y - p1.y) / (2 * eps)
            };
        }

        const p0 = P(0.0);
        let d = `M ${p0.x.toFixed(2)} ${p0.y.toFixed(2)} `;

        for (let i = 0; i < N; i++) {
            const tA = i * dt;
            const tB = (i + 1) * dt;

            const A = P(tA);
            const B = P(tB);
            const dA = dP(tA);
            const dB = dP(tB);

            const c1x = A.x + (dt / 3.0) * dA.x;
            const c1y = A.y + (dt / 3.0) * dA.y;
            const c2x = B.x - (dt / 3.0) * dB.x;
            const c2y = B.y - (dt / 3.0) * dB.y;

            d += `C ${c1x.toFixed(2)} ${c1y.toFixed(2)}, ${c2x.toFixed(2)} ${c2y.toFixed(2)}, ${B.x.toFixed(2)} ${B.y.toFixed(2)} `;
        }

        d += "Z";
        return d;
    }

    Shape {
        anchors.fill: parent

        ShapePath {
            fillColor: root.fillColor
            strokeColor: "transparent"

            PathSvg {
                path: root.buildPathD(root.width, root.height)
            }
        }
    }
}