SVG wallpaper color randomizer

Hi folks! :smiley:

I’m working on a “random wallpaper generator”. I’ve seen many wallpaper downloaders but no one generator, then I started thinking on how to do one. I wrote some lines of Python and used a SVG draw to get the first part done: it randomizes the colors!

As I can edit the SVG with Inkscape, I can do any “template” I want, but it stops there.

The part two is to find a way to randomize the forms of the SVG. Could anyone give me suggestions? :bulb:

PS.: I will upload the code at GitHub :octopus: in case someone gets interested.


Here, the initial working code:

Set the “wall.svg” as your wallpaper and run “./randwall”. You can edit the “template.svg” as you want :wink:

I have wanted to do similar things on multiple occasion, but my issue has always been actually displaying the images, as it’s usually necessary convert then to a raster format first.

However, when it comes to SVG, I do think I have a fair understanding of it, so if you have specific question, I’ll be happy to do what I can to help.

To render, I usually call Inkscape (with an --export-png=FILENAME ), but I got a suggestion of librsvg2-bin too. But at least on GNOME/XFCE-based desktop environments, I can set SVG files as backgrounds, and if I change the file, it automatically reloads on screen.

Both code and ideas are welcome :blush: My point now is how to generate interesting forms and patterns.

I got a PR using Delaunay Triangulation (using numpy and scipy) to generate some interesting fractal patterns. I am now studying it.

Really? On XFCE? Well, it has been a long time since I used XFCE. :wink:

Anyway, I’m eager to see what you come up with, so what are your issues more precisely?

Also, using templates made in inkscape really isn’t the best idea since there’s usually a lot of translations going, due to the fact that Inkscape treats the lower left corner as 0,0 instead of the correct top left corner. This can be remedied somewhat, by using the inkscape xml editor and moving your objects outside of the block (or whatever it’s called) that takes care of said translation. (I can provide a couple of examples if need be.) Furthermore inkscape used certain features that isn’t really supported by the SVG standard.

1 Like

One thing you could try, just for the fun of it, is a simple closed patch. Choosing a number of points, say 50, at random and also connection them at random. The result should be fairly interesting and unexpected, and if you furthermore overlay several of these random shapes, with various color and degrees of transparency, the end result should be interesting indeed. After that you can mess around with bezier curves and such, but that’s rather difficult to randomize I think. :wink:

Another thought.
I suspect working with multiple completely random colors will rarely work particular well. I suggest limiting your.
Personally I rather enjoy the non standard color scheme, with only 4 values per channel 0, 85, 170 and 255 (or the hex equivalent 0, 55, AA and FF), giving you a total of 64 colors, plus a few more potentially, if you include the alpha channel, though of course effect will be unpredictable.
You could of course also limit yourself even further, but I find this to work well.

Not much happening eh?

Well, here’s some C to confuse you. :wink:

[code]#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define WIDTH 1920
#define HEIGHT 1080
#define MIN_POINTS 3
#define MAX_POINTS 16

int main()
srand( time( 0 ) );
int n_points = MIN_POINTS + rand() % (MAX_POINTS-MIN_POINTS+1);

printf("<polyline opacity=\"%f\" stroke=\"none\" fill=\"#%06x\" points=\"", (1 + rand() % 3) / 3.0, ( ( 85 * ( rand() % 4 ) ) << 16 ) | ( ( 85 * ( rand() % 4 ) ) << 8 ) | 85 * ( rand() % 4 ));
for(int i = 0; i < n_points-1; i++)
    printf("%d %d, ", rand() % WIDTH, rand() % HEIGHT);
printf("%d %d\" />\n", rand() % WIDTH, rand() % HEIGHT);
return 0;


1 Like

:laughing: as long as it’s not C++, I am not confused at all.

Sorry, I got a bit more busy than expected these days :tired_face: I’m gonna study and code some discrete/combinatorial geometry to this project ASAP

I like your way of thinking. :wink: (I loathe C++)

Forum kindly sponsored by