From c3feedb74a9698d0d25563566dd345ed6e53f929 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sat, 24 Jul 2021 19:25:29 +0200 Subject: [PATCH] pkgs/nix-gscheits.artwork: init Since OpenSCAD has only limited SVG export capabilities, this implementation exports the image as PNG. Also, because OpenSCAD lacks transparency and anti-aliasing, the background colour is replaced by transparency and the image is then scaled down. --- .gitattributes | 2 + flake.nix | 5 +++ pkgs/artwork/artwork/.gitignore | 3 ++ pkgs/artwork/artwork/Makefile | 26 ++++++++++++ pkgs/artwork/artwork/lasercutter.jpg | 3 ++ pkgs/artwork/artwork/logo.scad | 61 ++++++++++++++++++++++++++++ pkgs/artwork/artwork/wallpaper.svg | 3 ++ pkgs/artwork/default.nix | 32 +++++++++++++++ pkgs/default.nix | 4 ++ 9 files changed, 139 insertions(+) create mode 100644 pkgs/artwork/artwork/.gitignore create mode 100644 pkgs/artwork/artwork/Makefile create mode 100644 pkgs/artwork/artwork/lasercutter.jpg create mode 100644 pkgs/artwork/artwork/logo.scad create mode 100644 pkgs/artwork/artwork/wallpaper.svg create mode 100644 pkgs/artwork/default.nix diff --git a/.gitattributes b/.gitattributes index f769614..a676483 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,5 @@ **/secrets.yaml diff=sops +*.jpg filter=lfs diff=lfs merge=lfs -text *.png filter=lfs diff=lfs merge=lfs -text +*.svg filter=lfs diff=lfs merge=lfs -text diff --git a/flake.nix b/flake.nix index d287280..a779145 100644 --- a/flake.nix +++ b/flake.nix @@ -110,6 +110,11 @@ (flake-utils.lib.flattenTree { inherit (pkgs) fablab; + + nix-gscheits = lib.recurseIntoAttrs { + inherit (pkgs.nix-gscheits) + artwork; + }; }); }) // { overlay = import ./pkgs; diff --git a/pkgs/artwork/artwork/.gitignore b/pkgs/artwork/artwork/.gitignore new file mode 100644 index 0000000..6291140 --- /dev/null +++ b/pkgs/artwork/artwork/.gitignore @@ -0,0 +1,3 @@ +/icon-*.png +/logo.png +/wallpaper.jpg diff --git a/pkgs/artwork/artwork/Makefile b/pkgs/artwork/artwork/Makefile new file mode 100644 index 0000000..847e6fa --- /dev/null +++ b/pkgs/artwork/artwork/Makefile @@ -0,0 +1,26 @@ +ICON_RESOLUTIONS = 16 32 48 64 128 256 512 1024 +ICONS = $(foreach resolution,$(ICON_RESOLUTIONS),icon-$(resolution).png ) + +default: wallpaper.jpg $(ICONS) + +logo.png: logo.scad + xvfb-run openscad -q -o $@ $< --camera=0,0,0,0,0,0,150 --projection=ortho --imgsize=4096,4096 + mogrify -transparent "#ffffe5" -filter Mitchell -resize 2048 logo.png + +icon-%.png: logo.png + convert -filter Mitchell -resize $(basename $(@:icon-%=%)) $< $@ + oxipng -q $@ + +wallpaper.jpg: wallpaper.svg logo.png + inkscape -o - --export-type=png wallpaper.svg | convert -quality 92 - $@ + jpegoptim -q -s $@ + +.PHONY: clean install +install: wallpaper.jpg $(ICONS) + install -Dm444 wallpaper.jpg $(PREFIX)/share/backgrounds/nix-gscheits.jpg + for resolution in $(ICON_RESOLUTIONS); do \ + install -Dm444 icon-$${resolution}.png $(PREFIX)/share/icons/hicolor/$${resolution}x$${resolution}/nix-gscheits.png; \ + done + +clean: + rm -f logo.png wallpaper.jpg $(ICONS) diff --git a/pkgs/artwork/artwork/lasercutter.jpg b/pkgs/artwork/artwork/lasercutter.jpg new file mode 100644 index 0000000..6701ab3 --- /dev/null +++ b/pkgs/artwork/artwork/lasercutter.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f628ac0a690dd0992e2087deca3cdf52e47eb0ad0af68419c39d09dce505d90 +size 10696485 diff --git a/pkgs/artwork/artwork/logo.scad b/pkgs/artwork/artwork/logo.scad new file mode 100644 index 0000000..ce5285d --- /dev/null +++ b/pkgs/artwork/artwork/logo.scad @@ -0,0 +1,61 @@ +// constants +$fn=64; + +LABCUBE_COLOURS = [ "#c93841", "#4164b0", "#14a95d" ]; +NIX_FLAKE_COLOURS = [ "#5277c3", "#7ebae4" ]; + +// lib +module axonometric2rectangular(angle) { + scale([tan(angle), 1, 1]) rotate(45) children(); +} + +module shear2d(x, y) { + multmatrix(m = [[ 1, tan(x)], + [tan(y), 1]]) scale([cos(y), cos(x)]) children(); +} + +// nix flake +module axonometric_lambda() { + polygon([ + [0, 0], + [-8, 0], + [-8, -9], + [-21, -9], + [-21, -13], + [-17, -17], + [-8, -17], + [-8, -26], + [0, -34] + ]); +} + +module lambda() { + axonometric2rectangular(30) axonometric_lambda(); +} + + +module nix_flake(gap = 0.5, hexagon_size = 10) { + for (angle = [0:60:360]) { + color(NIX_FLAKE_COLOURS[(angle%120)/60]) rotate(angle) translate([-hexagon_size, -gap, 0]) lambda(); + } +} + +// lab cube +module labcube_face(radius = .33, neck = .32) { + translate([-1/2, -1/2]) + difference() { + square(); + translate([1/2, 1/2]) circle(radius); + translate([(1-neck)/2, 0]) square(neck); + } +} + +module labcube(size = 10) { + for (i = [0:2]) { + color(LABCUBE_COLOURS[i]) rotate(i*120) shear2d(-30, 0) translate([size/2, size/2]) mirror([0, 1, 0]) scale(size) labcube_face(); + } +} + +// composition +nix_flake(gap = 0.5); +labcube(size = 10-0.5); diff --git a/pkgs/artwork/artwork/wallpaper.svg b/pkgs/artwork/artwork/wallpaper.svg new file mode 100644 index 0000000..86aa5a8 --- /dev/null +++ b/pkgs/artwork/artwork/wallpaper.svg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d3f6cfa1d24bb50c496c88c5599308f1b5903aaaaa9c7749cd58410eb57a312 +size 3137 diff --git a/pkgs/artwork/default.nix b/pkgs/artwork/default.nix new file mode 100644 index 0000000..ffccaad --- /dev/null +++ b/pkgs/artwork/default.nix @@ -0,0 +1,32 @@ +{ lib, stdenv, imagemagick, inkscape, jpegoptim, mesa, openscad, oxipng, xvfb-run }: + +stdenv.mkDerivation { + name = "nix-gscheits-artwork"; + + src = ./artwork; + + nativeBuildInputs = [ + imagemagick + inkscape + jpegoptim + openscad + oxipng + xvfb-run + ]; + + preBuild = '' + export LIBGL_DRIVERS_PATH=${mesa.drivers}/lib/dri + export LD_LIBRARY_PATH=${mesa.drivers}/lib + ''; + + enableParallelBuilding = true; + + makeFlags = [ "PREFIX=$(out)" ]; + + meta = with lib; { + description = "Artwork for nix-gscheits"; + license = licenses.cc-by-sa-40; + maintainers = with maintainers; [ sbruder ]; + platforms = platforms.unix; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index f9ac13a..400c16b 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -4,4 +4,8 @@ let in { fablab = recurseIntoAttrs (callPackage ./fablab { }); + + nix-gscheits = prev.recurseIntoAttrs { + artwork = callPackage ./artwork { }; + }; } -- 2.51.2