Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: CI

on:
push:
branches: [master]
pull_request:
workflow_call:

permissions:
contents: read

jobs:
test:
name: Test (${{ matrix.os }}, Node ${{ matrix.node }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest]
# The minimum version from package.json engines, the active LTS, and the current release.
node: ['22.2.0', 'lts/*', 'current']
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm test

smoke:
# Exercises the real OS integration. Hosted runners may not expose a desktop the way a
# real machine does, so this is informational rather than a required check.
name: Monitor detection (${{ matrix.os }})
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: lts/*
cache: npm
- run: npm ci
- name: List monitors
run: node --input-type=module -e "const p = await (await import('./lib/wallpaper/index.mjs')).loadPlatform(); console.log(await p.listMonitors());"

old-node:
# npx installs despite engines.node, so an unsupported Node must get a readable error.
name: Readable error on unsupported Node
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 20
- name: Run the CLI
run: |
if output="$(node cli.mjs --help 2>&1)"; then
echo "::error::Expected a non-zero exit code on Node $(node -v)"
exit 1
fi
echo "$output"
grep -q "wallangle needs Node.js" <<< "$output"
75 changes: 75 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Release

# Push a tag matching the package.json version to release, e.g.:
# npm version minor && git push --follow-tags
on:
push:
tags: ['v*']

permissions:
contents: read

concurrency:
group: release
cancel-in-progress: false

jobs:
test:
uses: ./.github/workflows/ci.yml

publish:
name: Publish to npm
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # npm trusted publishing (OIDC); also generates provenance
outputs:
prerelease: ${{ steps.version.outputs.prerelease }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: lts/*
registry-url: https://registry.npmjs.org
- name: Check tag matches package.json
id: version
run: |
version="$(node -p "require('./package.json').version")"
if [ "v$version" != "$GITHUB_REF_NAME" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match package.json version $version"
exit 1
fi
if [[ "$version" == *-* ]]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
echo "dist_tag=next" >> "$GITHUB_OUTPUT"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
echo "dist_tag=latest" >> "$GITHUB_OUTPUT"
fi
# Trusted publishing needs npm >= 11.5.1.
- run: npm install -g npm@latest
- run: npm publish --tag ${{ steps.version.outputs.dist_tag }}

github-release:
# A separate job so that a failure here can be re-run without re-publishing to npm.
name: Create GitHub release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: lts/*
- run: npm pack
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "$GITHUB_REF_NAME" wallangle-*.tgz \
--verify-tag \
--generate-notes \
--title "$GITHUB_REF_NAME" \
${{ needs.publish.outputs.prerelease == 'true' && '--prerelease' || '' }}
54 changes: 37 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ A CLI utility to set algorithmically generated triangle art as your desktop wall

---

Uses the awesome [Trianglify](https://github.com/qrohlf/trianglify) to randomly generate a low-poly triangle art desktop wallpaper:
Randomly generates a low-poly triangle art wallpaper for each of your monitors, at each monitor's native resolution:

![Preview Image](images/example.png 'Preview Image')

## Install

Requires [Node.js](https://nodejs.org/) >= 14.
Requires [Node.js](https://nodejs.org/) >= 22.2, on Windows 10+ or macOS.

Run it without installing:

```
$ npx wallangle@latest
```

Or install it globally:

```
$ npm install -g wallangle
Expand All @@ -28,42 +36,54 @@ $ npm install -g wallangle
$ wallangle
```

With `npx`, put the flags after the package name, e.g. `npx wallangle@latest --colors=YlGnBu`.

Every run prints the seed it used. Pass it back with `--seed` to recreate the same wallpapers.

### With Config

```
$ wallangle --width=2560 --height=1440 --variance=0.75 --cellSize=250 --seed=helloworld --colors="#083d77,#ebebd3,#da4167,#f4d35e,#f78764"
$ wallangle --variance=0.75 --cellSize=250 --seed=helloworld --colors="#083d77,#ebebd3,#da4167,#f4d35e,#f78764"
```

## Flags

These flags set specific options for Trianglify:
Flags apply to every monitor. Anything left unset is chosen randomly for each monitor, derived from the seed.

### --width
### --width / --height

Resolution width of your display. Defaults to `3840`.

### --height

Resolution height of your display. Defaults to `2160`.
Image size in pixels. Defaults to each monitor's resolution, so you normally won't need these.

### --variance

Decimal value between 0 and 1 (inclusive), defaults to `Math.random()`. Specify the amount of randomness used when generating triangles.
Decimal value between 0 and 1 (inclusive). Specify the amount of randomness used when generating triangles. 0 gives a regular grid.

### --cellSize

Integer, defaults to `Math.floor(Math.random() * 200 + 40)`. Specify the size of the mesh used to generate triangles. Larger values will result in coarser patterns, smaller values will result in finer patterns. Note that very small values may dramatically increase the runtime of Trianglify.
Integer, at least 10. Defaults to a random value between 40 and 239. Specify the size of the mesh used to generate triangles. Larger values will result in coarser patterns, smaller values will result in finer patterns.

### --seed

Number or string, defaults to `null`. Seeds the random number generator to create repeatable patterns. When set to null, the random number will be seeded with random values from the environment.
Any string or number. Seeds the random number generator to create repeatable patterns. Defaults to a random seed.

### --colors

Comma-separated string of CSS-formatted colors. Defaults to `'random'`. You can use a tool such as [Coolors](https://coolors.co/) to generate color palettes. Example is `--colors="#083d77,#ebebd3,#da4167,#f4d35e,#f78764"`
One of:

- A comma-separated list of CSS colours, e.g. `--colors="#083d77,#ebebd3,#da4167,#f4d35e,#f78764"`. You can use a tool such as [Coolors](https://coolors.co/) to generate palettes.
- The name of a sequential or diverging [ColorBrewer](https://colorbrewer2.org/) palette, e.g. `--colors=YlGnBu` or `--colors=Spectral`.
- `random` (the default), which picks a ColorBrewer palette.

## Where wallpapers are stored

- Windows: `%LOCALAPPDATA%\wallangle`
- macOS: `~/Library/Application Support/wallangle`

Each run writes new files. Wallpapers from the 10 most recent runs are kept, older ones are removed. On macOS, the wallpaper is set for the current Space on each display.

## Libraries Used

- [Trianglify](https://github.com/qrohlf/trianglify)
- [wallpaper](https://github.com/sindresorhus/wallpaper)
- [minimist](https://github.com/substack/minimist)
- [delaunator](https://github.com/mapbox/delaunator) for triangulation
- [chroma.js](https://github.com/gka/chroma.js) for colour scales and ColorBrewer palettes

Inspired by the awesome [Trianglify](https://github.com/qrohlf/trianglify).
53 changes: 13 additions & 40 deletions cli.mjs
Original file line number Diff line number Diff line change
@@ -1,42 +1,15 @@
#!/usr/bin/env node

import parseArgs from 'minimist';
import Trianglify from 'trianglify';
import wallpaper from 'wallpaper';
import fs from 'fs';

(async () => {
const parsedArgs = parseArgs(process.argv.slice(2));

const screenWidth = parsedArgs.width ?? 3840;
const screenHeight = parsedArgs.height ?? 2160;
const variance = parsedArgs.variance ?? Math.random();
const cellSize = parsedArgs.cellSize ?? Math.floor(Math.random() * 200 + 40);
const seed = parsedArgs.seed ?? null;
const colors = parsedArgs.colors?.split(',') ?? 'random';

const pngURI = Trianglify({
width: screenWidth,
height: screenHeight,
cell_size: cellSize,
x_colors: colors,
y_colors: 'match_x',
variance,
seed,
}).png();

const data = pngURI.substr(pngURI.indexOf('base64') + 7);

const buffer = new Buffer.from(data, 'base64');

const wallpaperFileName = 'wallpaper.png';

fs.writeFile(wallpaperFileName, buffer, async () => {
await wallpaper.set(wallpaperFileName);
console.log(
`Wallpaper generated & set with screenWidth: ${screenWidth}, screenHeight: ${screenHeight}, variance: ${variance}, cellSize: ${cellSize}, seed: ${seed} & colors: ${
Array.isArray(colors) ? colors.join(',') : colors
}.`
);
});
})();
// The real CLI is loaded dynamically: its static imports (e.g. zlib.crc32) fail with a cryptic
// error on older Node versions, before any check inside it could run.
import { MINIMUM_NODE_VERSION, isSupportedNodeVersion } from './lib/node-version.mjs';

if (isSupportedNodeVersion(process.versions.node)) {
import('./lib/main.mjs').then(({ run }) => run(process.argv.slice(2)));
} else {
console.error(
'wallangle needs Node.js ' + MINIMUM_NODE_VERSION + ' or newer, but this is ' + process.version + '.\n' +
'Update Node.js from https://nodejs.org/ and try again.'
);
process.exitCode = 1;
}
Loading
Loading