about summary refs log tree commit diff
path: root/web/tvl/logo/default.nix
blob: cb09dc28ecfa9e73bdaf77b84f873e67a31a8cf5 (plain) (blame)
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
# Creates an output containing the logo in SVG format (animated and
# static, one for each background colour) and without animations in
# PNG.
{ depot, lib, pkgs, ... }:

let
  palette = {
    purple = "#CC99C9";
    blue = "#9EC1CF";
    green = "#9EE09E";
    yellow = "#FDFD97";
    orange = "#FEB144";
    red = "#FF6663";
  };

  logoShapes = builtins.readFile ./logo-shapes.svg;
  logoSvg = style: ''
    <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 2480 3508">
      <style>${style}</style>
      ${logoShapes}
    </svg>
  '';

  staticCss = colour: ''
    #armchair-background {
      fill: ${colour};
    }
  '';

  # Create an animated CSS that equally spreads out the colours over
  # the animation duration (1min).
  animatedCss = colours: let
    # Calculate at which percentage offset each colour should appear.
    stepSize = 100 / ((builtins.length colours) - 1);
    frames = lib.imap0 (idx: colour: { inherit colour; at = idx * stepSize; }) colours;
    frameCss = frame: "${toString frame.at}% { fill: ${frame.colour}; }";
  in ''
    #armchair-background {
      animation: 60s infinite alternate armchairPalette;
    }

    @keyframes armchairPalette {
    ${lib.concatStringsSep "\n" (map frameCss frames)}
    }
  '';

in depot.nix.utils.drvTargets(lib.fix (self: {
  inherit palette;

  # Create a TVL logo SVG with the specified static armchair colour.
  staticLogoSvg = colour: pkgs.writeText "logo.svg" (logoSvg (staticCss colour));

  # Create a TVL logo SVG with the specified animated armchair colour set.
  animatedLogoSvg = colours: pkgs.writeText "logo.svg" (logoSvg (animatedCss colours));

  # Create a PNG of the TVL logo with the specified static armchair colour and DPI.
  logoPng = colour: dpi: pkgs.runCommandNoCC "logo.png" {} ''
    ${pkgs.inkscape}/bin/inkscape \
      --export-area-drawing \
      --export-background-opacity 0 \
      --export-dpi ${toString dpi} \
      ${self.staticLogoSvg colour} -o $out
  '';

  # Animated SVG logo with all colours.
  pastelRainbow = self.animatedLogoSvg (lib.attrValues palette);
}

# Add individual outputs for static logos of each colour.
// (lib.mapAttrs' (k: v: lib.nameValuePair "${k}Png" (self.logoPng v 96)) palette)))