rainwall
- 8 Devlogs
- 22 Total hours
šļø apply a wallpaper based on the weather outside
šļø apply a wallpaper based on the weather outside
Setting wallpapers for multiple monitors on macOS is tediously hard! Thereās gotta be a Swift application in the middle accepting this call, soā¦
Would you rather:
LET ME KNOW IN THE COMMENTS! Or something. Iām not a YouTuber
Today I learned that the CIEDE2000 algorithm never worked in the first place and was outputting numbers opposite to on the colour wheel. Why? I have no clue and I donāt intend to find out, because Iāve decided Iāve had enough of typing in sine and cosine and was just going to use the library colordx instead. The whole project was refactored, including the analyze API, so if youāve had an index file generated previously make sure to regenerate it!
I just spent four hours doing genuinely the most annoying thing on the planet: building for Windows.
I found a neat little Stack Overflow thread that seemed to do what I wanted it to: write a PowerShell script that could set the wallpaper on Windows machines. Not too shabby, I thought. I could probably ask one of my friends to test on their machine. It wouldnāt take too long, maybe half an hour at max.
Boy, was I wrong.
I forced the poor bloke to install ImageMagick, then sent him a CI build. We gave the program a test run, and I ran into my first real challenge: paths.
Oh my God, I hate Windows paths.
Nothing would workāmaking folders, writing files, any of that until I replaced every single forward slash with Denoās fromFileUrl. And being a person with not so great memory, I sent over at least five builds before I fixed every single path in the way. Honourable mentions include:
fromFileUrl("C:/..") because that is definitely a file:/// URLpath.join(`${imageDir}, ${image.name}`)Part 2: PowerShell. I thought (
) that zx would run on PowerShell out of the box. Nope! It depends (and it actually says this in the README too) that it depends almost exclusively on Bash and Bash escaping. Thereās a usePowerShell() command, but I genuinely donāt have the energy right now to figure out the refactors required to make that workāon someone elseās machine.
So I make the guy install Git Bash, and also Deno so I can just send him diffs instead of having to send the Full Deno Runtime⢠every time I had a new build. At this point, rainwall-analyze finally works (yay!) and dumps the correct paths to the cache folder. We run rainwall-apply, I find four new cases of paths I did not fix, and I go back into VSCode hell.
Part 3: the actual PowerShell script. Usually, on Linux, I just use Bashās eval whenever I need to run something enclosed in a string, because zx will automatically quote and escape everything youāve passed in through a variable. Thereās no eval with PowerShell, so I do an insane amount of googling. At this point, I send him a total of twelve diffs just to test to see what the heck is going on. We eventually settled on using Deno.Command instead of zx for this one, running pwsh C:\path\to\script C:\path\to\image. Later, after I logged off for the night (at 2:00! I thought Iād be in bed by 22:00!), I did realize one thingāwhile we were installing Deno, I saw that they had an install script irm https://deno.land/install.ps1 | iex. I figured a much, much easier way wouldāve been to just run 'C\path\to\script' | iex instead, but my brain at that insane hour was not having it.
Thatās the whole Windows saga, for now. I still have to adjust the lightness curves a little bit, but other than that, we should be nearing completion. Today, I want to test the script with my macOS friend⦠provided she wakes up earlier than 21:00. Almost there!
There I was, scrolling through my Discord servers, when I saw this link: https://www.keithcirkel.co.uk/whats-my-jnd/
It was a small program to calculate the Just Noticeable Difference between two colours, or the JND. Reading the blogpost linked, it mentioned an algorithm called the āCIEDE2000.ā And thatās when it hit meāthe CIE is a real organization. Of course they would have a formula to calculate the similarities between two colours. That meant that I didnāt have to iterate through my array of wallpaper colours and do simple less-than checksāusing CIEDE2000 would be much more accurate. Thankfully, thereās an npm library for this: color-diff. (I was NOT about to implement all that myself.) I also added a bit of randomization to the algorithm, so that should ensure youāre not getting the same wallpaper all the time if you live somewhere where thereās consistent weather patterns.
All in all, this probably constitutes a reship, doesnāt it? Iāll probably be tweaking the algorithm slightly as I continue to use it, so stay tunedā¦
Wrote a README, and my very first PKGBUILD! Arch Linux is pretty cool :)
Dumping all the sun data times to ensure the algorithmās as accurate as possible! (-0.833 is the angle of the sun at sunrise/sunset.)
Done!!! YEAH! I had to reimplement the output so that it wouldnāt sort into categories, as that turned out to be harder for the final algorithm to find a matching wallpaper. Currently hueRange is unimplemented as Iām not super sure how to go about it, and Iāve got to clean up the easing function code somehow, but other than that, this should be pretty much ready to ship!
Been formatting this into a full Deno project from an isolated zx idea. Never done anything config-related before, so making something to read/write the config was pretty cool.
A lot of writing the analysis code was processing the bash output into something manipulate-able with TypeScript. That was annoying as shitāsplitting, filtering, mapping⦠I never want to process text again in my entire life.
Something really unexpected had to be the floating point errors I found in the loop. I was thinking there had to be a better way to populate the better array in the first place, but there didnāt seem to be, so there I was doing let i = 0, i < 1, i += 0.1 and fighting for my life against 0.60000001. I eventually got so tired of it I just made it a percentage out of 100% instead. Surely this wonāt bite me in the back later :)
Weāve got cloud cover, shortwave radiation, and sun altitude with the help of Open-Meteo and suncalc. Theyāre going to map to parameters chroma, lightness, and hue respectively! Thisāll be funā¦.