apply random colour from palette to objects

General discussions about Inkscape.
JuliaFlowers2
Posts: 40
Joined: Tue Jul 31, 2018 4:47 am

apply random colour from palette to objects

Postby JuliaFlowers2 » Tue Jul 31, 2018 4:51 am

Hello everybody, first post :)

I have created a canvas full of stars and want to randomly apply three colours from a palette (red, white and blue) to each of the stars.
Doing it manually is a lot of work because i have so many stars, is there a script that does this ?

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: apply random colour from palette to objects

Postby Lazur » Tue Jul 31, 2018 6:08 am

Hi.

Can't think of a script/current extension at hand (however I'm using an outdated version...) that would do exactly as per se.

If it's for a raster export as a final output format and not a printable pdf etc., I'd use the tweak tool to colour the stars to random luminance levels, then use a colormap filter to map 3 colours to the full luminance range.
That filter can be generated with an extension, so the goal can be achieved in minutes.


If it wasn't for existing stars, you could have used the spray tool with clones, tracing the colours beneath them.
And/or use cloning, random alignment through the align and distribute panel etc.

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: apply random colour from palette to objects

Postby Moini » Tue Jul 31, 2018 7:49 am

You could just select one third of your stars, give them a color, repeat for the other two thirds, then distribute the stars randomly (if it doesn't matter where exactly they are).

Else the touch selection might be useful. Hold Alt and drag mouse to select objects that are touched by mouse.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

JuliaFlowers2
Posts: 40
Joined: Tue Jul 31, 2018 4:47 am

Re: apply random colour from palette to objects

Postby JuliaFlowers2 » Tue Jul 31, 2018 8:35 am

Lazur wrote:If it's for a raster export as a final output format and not a printable pdf etc., I'd use the tweak tool to colour the stars to random luminance levels, then use a colormap filter to map 3 colours to the full luminance range.
That filter can be generated with an extension, so the goal can be achieved in minutes.

Dear Lazur,
what is this colormap filter that can be generated with an extension ?
Can you give me the steps please.

Moini wrote:You could just select one third of your stars, give them a color, repeat for the other two thirds, then distribute the stars randomly (if it doesn't matter where exactly they are).

Dear Moini,
is there a script to randomly select objects ? Like deselect 66% of my selected objects ?

Doing it by hand is too much work, and hard to get at the right amount.
Last edited by JuliaFlowers2 on Tue Jul 31, 2018 2:58 pm, edited 1 time in total.

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: apply random colour from palette to objects

Postby Lazur » Tue Jul 31, 2018 2:50 pm

Hi.

This is something similar how "it should work": https://youtu.be/ihv8dzc9slo.

But actually had issues when applying the extension, maybe sharex-the screen capturer used- interfered with the window.

It is supposed to generate a custom filter from a gradient, which then you could apply on any selected objects -including raster images too. Similr in style to the "hope" poster.

Surprisingly the filter editor shown it wasn't applied to any object but everything was rendered with it. My guessing somehow the whole document's parent layer got the filter, somewhere hidden in the defs section.

JuliaFlowers2
Posts: 40
Joined: Tue Jul 31, 2018 4:47 am

Re: apply random colour from palette to objects

Postby JuliaFlowers2 » Tue Jul 31, 2018 3:13 pm

Lazur wrote:Hi.

This is something similar how "it should work": https://youtu.be/ihv8dzc9slo.


Thank you for making the video for me.
I dont have a Modify Colour in my Extensions list. My Inkscape is version 0.92.3.

Is this something i can download ?

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: apply random colour from palette to objects

Postby Lazur » Tue Jul 31, 2018 4:40 pm

Mea culpa. Thought it made it onto the branch. Extension was added by Suv, not sure about a download link.

However the filter is quite simple, will upload one in a minute.

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: apply random colour from palette to objects

Postby Lazur » Tue Jul 31, 2018 4:49 pm

Here is that filter.
You can edit the colours in the filter editor by the flood fill primitives.
Attachments
redwhiteblue.svg
(5.51 KiB) Downloaded 222 times

JuliaFlowers2
Posts: 40
Joined: Tue Jul 31, 2018 4:47 am

Re: apply random colour from palette to objects

Postby JuliaFlowers2 » Tue Jul 31, 2018 5:43 pm

Lazur wrote:Here is that filter.
You can edit the colours in the filter editor by the flood fill primitives.

Thank you. I was able to use your filter for my stars.

There are two problems with this method:

1.) the stars form big colour clumps (its not random enough)

2.) there are strange glitches where two colours seemingly overlap. what can be done about that ?

EDIT: why dont my images show up ?

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: apply random colour from palette to objects

Postby Moini » Tue Jul 31, 2018 8:02 pm

@JuliaFlowers2
If the current arrangement of stars doesn't matter (i.e. it's okay to re-arrange, as it's random anyway), then you just need to drag a selection box with the mouse to change the color for one third.

The re-arrangement can be done by using the random functionality of the Align-and-Distribute-Dialog.

I don't know of any functionality or extension that randomly selects/deselects objects (this is, in part, due to the fact that in versions up to and including 0.92.3, after applying an extension, everything is deselected - will change with the next version, where selection is kept).
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

User avatar
Xav
Posts: 1209
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: apply random colour from palette to objects

Postby Xav » Tue Jul 31, 2018 9:09 pm

Here's another approach: use the Objects dialog (Object ‣ Objects…).

If your stars are randomly distributed then just selecting the first 1/3 of them as listed should get you what you want. Just click the first one, then hold Shift and click the last one, then click the colour swatch to set the fill. If that approach works, repeat for the next third and the last third.

In practice there's a difference between "random" and "what humans perceive as random", so there's likely to be some clumping that you don't like. In that case you can hold Shift to de-select individual items on the canvas, and select others. That will lead to a non-contiguous block of selected entries in the Objects dialog, so you might want to group them all (at least temporarily) so that they get out of the way when you select the next third.

If they're not so randomly arranged that selecting a block gets you close to what you want, you can still use the Objects dialog but will need to do more clicking. Holding Ctrl while clicking on an entry will let you add/remove it from the selection, so you'll need to do that on every third entry. It may take a while, but it will likely be faster than trying to pick out 1/3 of them on the canvas. Again, once you've got your selection you should probably group them to avoid them being selected for the second pass (where you will then select every second entry).


[I did wonder if it might be possible to select roughly 1/3 of the stars using the Find/Replace dialog, on the basis that they've probably got a reasonable distribution of generated IDs. My thinking was to select all those with IDs ending in 0, 1 or 2, then all those ending in 3, 4 or 5, then finally those ending in 6, 7, 8 or 9. Unfortunately it doesn't look like the search field allows for wildcards, or for a way to indicate that the term has to be found at the end of the ID.]
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: apply random colour from palette to objects

Postby Lazur » Tue Jul 31, 2018 9:15 pm

JuliaFlowers2 wrote:1.) the stars form big colour clumps (its not random enough)

2.) there are strange glitches where two colours seemingly overlap. what can be done about that ?


Hi.

With the tweak tool :tool_tweak: you can randomize the luminosity, resulting in different colour arrangement on the filtered results.
Although randomness mathematically means there are "clusters" here and there

This is a filtered solution, meaning the effect is added on in the rendering level -theoretically the objects on the canvas could be substituted with a raster double, the output would look the same.
If you zoom in or increase the resolution, the details should be rendered much clearer.
In that vein if you export the result in a larger size and downscale the png, the result should look way better.


Not sure why your images not showing up.
Try using an online host and then use

Code: Select all

[img][/img]
tags around the image's url for hotlinking.

tylerdurden
Posts: 2344
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: apply random colour from palette to objects

Postby tylerdurden » Tue Jul 31, 2018 11:03 pm

Seems like a "Random Select" extension could be handy. Maybe something simple?

    Randomly select from:
      Entire document
      Selected objects
      Visible objects
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

JuliaFlowers2
Posts: 40
Joined: Tue Jul 31, 2018 4:47 am

Re: apply random colour from palette to objects

Postby JuliaFlowers2 » Wed Aug 01, 2018 2:42 am

Moini wrote:The re-arrangement can be done by using the random functionality of the Align-and-Distribute-Dialog.


This seems the most simple and obvious method so far. I cant understand why i didnt try this.
Thank you so much for telling me !

Is there a place on the internet where i can find detailed information about this particular subsection of the Arrange & Distribution Dialogue ?

Xav wrote:Here's another approach: use the Objects dialog (Object ‣ Objects…).

In practice there's a difference between "random" and "what humans perceive as random", so there's likely to be some clumping that you don't like. In that case you can hold Shift to de-select individual items on the canvas, and select others. That will lead to a non-contiguous block of selected entries in the Objects dialog, so you might want to group them all (at least temporarily) so that they get out of the way when you select the next third.


Yes, its true what you say about perceived randomness.
Using the Object Dialogue for manually re-arraning single objects is a good tip.


Lazur wrote:With the tweak tool :tool_tweak: you can randomize the luminosity, resulting in different colour arrangement on the filtered results.
Although randomness mathematically means there are "clusters" here and there.


Another good tip to fix the cluster problem !


tylerdurden wrote:Seems like a "Random Select" extension could be handy. Maybe something simple ?


Yes, a random select extension would come in very handy.

On the other hand, re-coloring seems like a common task and shouldnt be too difficult to do.

How about an extension that lets you define a number of colours, or link to a swatch, then apply the colours randomly to a selection of objects ?!

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: apply random colour from palette to objects

Postby Lazur » Wed Aug 01, 2018 4:08 am

Image

Press Shift+Ctrl+A for the panel, select th objects and click the bottom left icon -Image- of the distribute options.

JuliaFlowers2
Posts: 40
Joined: Tue Jul 31, 2018 4:47 am

Re: apply random colour from palette to objects

Postby JuliaFlowers2 » Wed Aug 01, 2018 4:29 am

Lazur wrote:Press Shift+Ctrl+A for the panel, select th objects and click the bottom left icon -Image- of the distribute options.


your screenshot is missing the button Moini recommend
is was looking for a documentation on the new rearrange buttons, because they are not in the manual

Top

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: apply random colour from palette to objects

Postby Moini » Wed Aug 01, 2018 8:17 am

Lazur indeed pointed at the icon I meant, random arrangement.

what does "exchange position of selected objects - clockwise rotate" mean ?


It exchanges the positions of the selected objects in a way that things that previously were in position 1 on an imaginary clock face are in position 2 after the click on the button. This is relevant when you select more than 2 objects. It swaps positions in a circular fashion, things move clockwise.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

JuliaFlowers2
Posts: 40
Joined: Tue Jul 31, 2018 4:47 am

Re: apply random colour from palette to objects

Postby JuliaFlowers2 » Wed Aug 01, 2018 9:37 am

Moini wrote:Lazur indeed pointed at the icon I meant, random arrangement.

what does "exchange position of selected objects - clockwise rotate" mean ?


It exchanges the positions of the selected objects in a way that things that previously were in position 1 on an imaginary clock face are in position 2 after the click on the button. This is relevant when you select more than 2 objects. It swaps positions in a circular fashion, things move clockwise.

Thanks for clearing that up !

I took your advice, recoloured each third of the stars into my desired color, then shuffled the objects with the "exchange position of selected objects - clockwise rotate" button. This doesnt break the arrangement of the stars, just the position. Which is what i needed.

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: apply random colour from palette to objects

Postby Moini » Wed Aug 01, 2018 10:05 am

So you had 'constellations' in your night sky? Smart way to solve the problem, I wouldn't have thought of this.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

JuliaFlowers2
Posts: 40
Joined: Tue Jul 31, 2018 4:47 am

Re: apply random colour from palette to objects

Postby JuliaFlowers2 » Wed Aug 01, 2018 10:47 am

Moini wrote:So you had 'constellations' in your night sky? Smart way to solve the problem, I wouldn't have thought of this.

its for a flag, and i just discovered this option because of you :)

User avatar
Xav
Posts: 1209
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: apply random colour from palette to objects

Postby Xav » Wed Aug 01, 2018 4:57 pm

JuliaFlowers2 wrote:Is there a place on the internet where i can find detailed information about this particular subsection of the Arrange & Distribution Dialogue ?


Sounds like you don't really need it any more, but I covered this dialog in parts 38 & 39 of my tutorial series: viewtopic.php?f=6&t=11981
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: apply random colour from palette to objects

Postby brynn » Thu Aug 02, 2018 2:10 am

I realize this is mostly solved by now. But I wanted to mention a different approach: Edit menu > Clones > Tiled Clones. Besides making tiled type of arrays, that can create the randomly placed, randomly sized and randomly colored stars, or any kind of object.

For the stars being only 3 colors, I would probably create 3 random arrays - one for each color. That's how I made the fireworks in this image: https://forum.inkscapecommunity.com/ind ... 34#msg1234


Return to “General Discussions”