Inkscape.org
Beyond the Basics Random Swatches Fill
  1. #1
    Abdo Mohamed Abdo Mohamed @shahba_design

    Hello there,

    I saw this video from Juna https://youtu.be/2u926lWxBDA?t=101 where he created a pattern in Affinity Designer then started to colorize each object manually randomly to create a colorful geometric pattern.

    Someone commented in his video:

    "If you set colors in your palette as global colors (before coloring objects), you can then make easly recoloring in Affinity Designer."

    I don't know what this does mean here in Inkscape? Anyway....

    I thought how to make that colorize part automatic? So I thought of Tiled clone feature in Inkscape from Edit menu > Clone > Create Tiled Clones, and go to color tab and start to generate random colored objects. (Before doing the clone process, I must set the object that I will clone to "Unset Paint = the question mark" from Fill and Stroke tab > Fill)

    But tiled clone with random colors doesn't work here with grouped objects, I think it works only with one object, and it can't colorize multiple objects.

    So I saw another video https://youtu.be/CBrBPI49Ew4 , but this time it's a JavaScript for Illustrator where it enables you to randomly fill the objects, and here is the script:

    mySelection = app.activeDocument.selection;
    myDoc = app.activeDocument;
    if (mySelection instanceof Array)
    {
    selSwatches = myDoc.swatches.getSelected();
    
        if(selSwatches.length != 0)
            for (i=0; i<mySelection.length; i++)
            {
    if(mySelection[i].typename == "PathItem" || mySelection[i].typename == "CompoundPathItem")
                {
                    selItem = mySelection[i];
                    selItem.filled = true;
    
                    swatchIndex = Math.round( Math.random() * (selSwatches.length - 1 ));
    
                    if(selItem.typename == "PathItem")
                        selItem.fillColor = selSwatches[swatchIndex].color;
                    else
                        selItem.pathItems[0].fillColor = selSwatches[swatchIndex].color;
    
                }
            }
    }

    Could we do the same thing in Inkscape like this JavaScript file does?

    Thank you for your time.

     

     

     

  2. #2
    Tyler Durden Tyler Durden @TylerDurden

    Seems to work here. Was the initial color set to something other than black?

  3. #3
    Abdo Mohamed Abdo Mohamed @shahba_design

    I guess it works when the grouped objects are the same color, but not in my case:

     

    I would like to ask about a behavior, when I group objects, you I see it "Unset" as in my gif, while the objects keeps their colors? And If I right-click on the fill and chose "Unset" all objects turns black as in your gif!

     

  4. #4
    Tyler Durden Tyler Durden @TylerDurden

    Unset colors will look back, they simply have no color assigned. This will visually distinguish them from a color assignment specifically to "none", which will appear transparent. 

  5. #5
    Abdo Mohamed Abdo Mohamed @shahba_design
    *

    I see.

    Actually, in the previous gif I didn't put a value in the randomize field.

    Anyway, I changed the color of the original tile, and it seems that the strokes of generated clones are colored and not the fill itself!

    The svg file is in attachments.

  6. #6
    Tyler Durden Tyler Durden @TylerDurden
    *

    By definition, groups' color are unset, but to get the objects within the group to also be unset, the group can be reset to unset and the contents will inherit the assignment, or the group can be entered and the objects can be changed to unset (fill and stroke). After that, the group can be cloned and the random colors will be generated with the clones.

    Note that if the unset group is cloned, the objects in the cloned groups will be the same random color. If different colors for each object are desired, each object will need to be cloned separately.

  7. #7
    Abdo Mohamed Abdo Mohamed @shahba_design

    I see, thank you for following up with me.

    There is one things I would like to mention:

    1. In case of dealing with multiple groups, could we clone that object in the image with your approach? Because I tried, but it didn't work for me.

     

     

    I love the concept where you can choose the colors of your cloned tiles, like the script I mentioned. I hope to see it implemented in Inkscape. 👍

  8. #8
    inklinea inklinea @inklinea⛰️

    From the javascript you have posted, it looks like this is randomise from an existing palette.

    So we are looking at picking colours randomly from a set list. 

    If the number of colours in the palette is longer than the number of objects in the selection then it's possible not to repeat colours.

    However that script just seems to pick a random colour from the list without removing that colour from the list.

    If this is something that would be useful I could possibly add it to the indexed colour extension I wrote, as that extension is already able to extract palettes from gimp files / gradients / bitmap images.

     

  9. #9
    Abdo Mohamed Abdo Mohamed @shahba_design

    @inklinea thank you for your detailed explanation on how the extension works.

    inklinea

    it looks like this is randomise from an existing palette.

    In the video https://youtu.be/CBrBPI49Ew4 ,he opened the color panel and chose the colors he wanted to be in the pattern.

    inklinea

    However that script just seems to pick a random colour from the list without removing that colour from the list.

    Could you elaborate more?

     

     
  10. #10
    inklinea inklinea @inklinea⛰️

    It's the difference between rolling a dice with 6 sides and pulling a number out of a bag which contains 6 tokens labeled 1-6

    With the dice, you can roll the same number more than once, in theory you could have 5 5 5 5 5 5 for example.

    With pulling numbers out of a bag, ( provided the tokens are not put back in the bag ) you cannot choose the same number twice.

  11. #11
    Abdo Mohamed Abdo Mohamed @shahba_design

    Thank you for your response.

    Well, I don't know what to say. But thanks for your initiative.

  12. #12
    inklinea inklinea @inklinea⛰️

    A random swatch fill would look something like this in Inkscape.

     

    Autumnleaves
  13. #13
    Abdo Mohamed Abdo Mohamed @shahba_design
    *

    Sorry for being late.

    I see, this is great, thank you for your efforts.