Adding Color to Algorithms

Baking out the Color

A bit more complex than needed

Adding the color into my graphic design was actually much harder than I anticipated. For starters, to actually bake out the color into the curve we need to add another plug in into our Grasshopper. This plug in is called FAB TOOLS. It is used a lot for CAD drawing, when you want more control over annotations and bake attributes. My other problem was actually inside of Illustrator. When you import curves into Illustrator, they always come in as lines. If they are closed lines all you have to do is select all of them and press the swap fill and stroke button. Since we have multiple colors, it doesn't allow it. Now selecting and flipping 5000 square pieces is not something I want to do, we need to do some scripting in Illustrator too. 

Making a simple Color Example

Since we are using the diamond panel, we first need to extract the edges and close the curves like we did in our last tutorial. After that I added a flatten tree component. This is because our last components made them into branches (basically groups) and we don't want that. So we flatten them again to make them a single group of items, not multiple. 

Here is where we also use some FAB TOOLS components. If you get lost just follow the list and connect them how you see in my images.

  1. Fab Tools Tab > Bake > Add a Advanced Bake Component
  2. Fab Tools Tab > Bake > Add a Bake Attribute Component
  3. Param Tab > Input > Add a Button
  4. Param Tab > Input > Add a Boolean Toggle Component
  5. Connect the Flatten Tree into the G input of the Bake Attribute Component
  6. Connect the Image Sampler into the C input of the Bake Attribute Component
  7. Connect the Bake Attribute into the G input slot in Advanced Bake component
  8. Connect the button into the bake input slot in Advanced Bake Component
  9. Change Boolean Toggle into True and connect in to group input slot in Advanced Bake Component

Now when you press the button it will bake our curves into Rhino. They will be grouped together and all have different color. Select them all and export them as an illustrator file

Working with Illustrator 

When you open the Illustrator file it will probably be a bit small. Scale it up to size and this is what we get. We have a bunch of closed shapes that if we individually select, we can swap the line with fill

Now when we select all of them, the swap tool gets disabled. This is because we have multiple colors. Not too big of a problem in most cases, but with us, this might take hours 

Ray has your back 

Flipping thousands of little shapes for hours at a time isn't something I want anyone to do. We will use the power of programming to make this as painless as possible. Here is the script


Download this file and save it into your hard drive, make sure you only have our file open because it will invert all the things it can find. Go to the File Menu,  Scripts and click on Other scripts. Find the FlipALL.jsx and run the script. 

Now you have a nice base to start your art.


A final word  

I know what we did doesn't seem like much now, it isn't even that complex or beautiful to be honest. I had to make this lesson as basic as I could to help you understand the logic behind what Grasshopper is. If I tried to write a lesson on how to make something like you see below, it would've had many more layers and concepts. What I am trying to accomplish is, hopefully,  this sparks the drive to push you forward and learn more difficult concepts. Like I have said before, this is barely scratching the surface. If you enjoyed this and it helped you, please send me an email. Show me what you did, I love seeing it. I hope you have a great day and remember, I was exactly where you were not too long ago, just keep pushing yourself and find the artist inside you.