I'm trying to create hexagonal pattern of slightly offset colors. Similar to Code Review's background, but with hexagons.

I've attempted to draw a hexagon and slightly change the colors but doing this ~800 times would be highly impractical.

So essentially, how would I create a group objects with slightly different colors for each

Here's a rough example of what I've tried so far.

Rough Example

  • Please formulate your question more clearly. What is it you want to achieve and have problems with? Thanks! – Vincent Jan 5 '16 at 9:24
  • A simple google query lead me to this: forums.adobe.com/thread/450301?start=0&tstart=0, which really looks like what you are after. – usr2564301 Jan 5 '16 at 10:15
  • @Jongware Im not sure that qualifies if he wants every item to have different color and not just swatches but yes randomizing scripts exist. – joojaa Jan 5 '16 at 10:17

A quickly written Javascript to randomize the RGB fill color of a selected set of objects:

var adjustRanges = {
  red:{min:-40, max:40},
  green:{min:-40, max:40},
  blue:{min:-40, max:40}

objects = app.selection;
for (i=0; i<objects.length; i++)
  color = objects[i].fillColor;
  if (color instanceof RGBColor)
    r = color.red+adjustRanges.red.min+Math.random()*(adjustRanges.red.max-adjustRanges.red.min);
    if (r < 0) r = 0; if (r > 255) r = 255;

    g = color.green+adjustRanges.green.min+Math.random()*(adjustRanges.green.max-adjustRanges.green.min);
    if (g < 0) g = 0; if (g > 255) g = 255;

    b = color.blue+adjustRanges.blue.min+Math.random()*(adjustRanges.blue.max-adjustRanges.blue.min);
    if (b < 0) b = 0; if (b > 255) b = 255;

    c = new RGBColor();
    c.red = r; c.green = g; c.blue = b;

    objects[i].fillColor = c;

Save as "changeColors.jsx" in your local Illustrator's Scripts folder so it will appear in the File > Scripts menu next time you restart Illustrator, or anywhere else (and you'll have to browse for its location).

You can change the min/max adjustment values at will; for example, setting these values to 0 for both red and blue will only change the Green component.

| improve this answer | |
  • 2
    +1 you might want to randomize in HSB space though And make the channel randomize a function ;) DRY is after all a thing... yeah i know. – joojaa Jan 5 '16 at 11:20

To get uniform graphics use the snap to grid setting, you can then scale it to your desired size in Illustrator. Check out Chris Spooners blog post about a similar sort of project.


| improve this answer | |
  • Hello and welcome. I dont think he is asking about how to align the hexagons. As that should be easy. Its the changing of the colors bit thats a problem. – joojaa Jan 5 '16 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.