# Learn How To Manage Data by Adding Colouring a Twisted Voxel Tower

Hi there,

Today I thought we continue down the route of getting better at data management by applying some visual effects to the twisting voxel tower that we did last week.

We can apply some visual effects based on a few metrics that we can extract out of the tower. This will let us gain some experience with extracting and manipulating the data in Grasshopper. It will also give us some experience with using some more visual components that Grasshopper has to offer.

The metrics that I came up with aren't what you might be taking out from a model, they are just metrics that came to my head. But I still think it is useful to go through the process.

**Learning Features**

Data Wrangling

Grasshopper Visualisations

**Modelling**

**1. Colouring by Elevation**

So the first visual effect that I thought to apply would be to colour the building by the elevation of each floor. We can do this quite easily because we have in our script a list of groups, where each group is a floor of the building.

But first, we have to extract the elevation of each group. I am going to do this by first, ungrouping, and then taking the first voxel of each floor. The elevation of the first voxel will represent the elevation of the whole floor.

To get the elevation value of the voxel, I can use the * Volume* component to get the volumetric centroid of the voxel. Which I will then deconstruct to get the elevation of the points.

With the list of elevations per floor obtained, I can then look at applying a colouring regime to the entire tower. To do so, I am going to be making use of two components that Grasshopper offers, the * Gradient* and the

*component.*

**Custom Preview**Let's first take a look at what the * gradient* component does and how we can use our list of elevations to create colours.

The * Gradient* component, Linear interpolates a given value from a given domain. It then uses a colour scheme to output a set of colours.

You can see that with the default colour scheme, the lowest value will give us a white colour, while the highest value will give us a red colour. What this means for our list of elevations is that we can give the * gradient* component the highest and lowest elevation value and have the component spit out colours for every elevation.

To then apply this colour to the entire building, I will use the * custom preview* component which just lets us display any geometry in Grasshopper with a different colour. Here, is also where I have to be a bit more careful with the data because there is a lot of data and a mismatch could result in a lot more computations than I want. Here I have a list of 65 groups and a list of 65 colours that were created by the list of elevations.

This means the data matches and the good thing about Grasshopper, is that the * custom preview* component is able to colour groups. Plugging the two into the component gives :

I can even go back to the * gradient* component and change the colour scheme to make the colours more obvious, you can do this by right-clicking on the

*component.*

**gradient****2. Colouring by Rotation Applied **

Taking our newfound knowledge of Grasshopper's visual components, I can use it to colour the building by another metric. Like the amount of rotation that is applied to each floor. It follows a similar approach as before, except we need to extract the rotation from the body and the podium.

Then, following the exact same steps as before, I can use this list of rotations to create a list of colours which I can then apply to the voxels using the * custom preview* component. This time, I am going to use a black and white gradient.

You will notice that the colouring is not continuous because the rotation of the body is relative from the last floor of the podium. To create a continuous colour for the entire body, I need to take this into account when colouring the body.

It is just as simple as adding the final rotation of the podium to the list of rotations for the body.

**3. Colouring by Distance from the origin**

So far, I have only been looking at colouring on a per floor/group basis but to dig a little deeper into the data, I can actually apply some colouring on a per voxel basis.

A metric that I came up with is the distance from the origin itself. To do this, I have to first ungroup the list of groups that we have. Then I will use the * volume* component to get the volumetric centroid like before. Using that centroid, I can measure the distance from each centroid to the origin with the

*component.*

**distance**But now I also have to be careful as I am no longer dealing with a list but I am dealing with a data tree.

To get the maximum and minimum distance, I can *flatten* the entire list and use the * bounds* component. What the

*component will do, is find the max and min value in the list and create a domain. If I then deconstruct this domain, I can get the maximum and minimum values of the list.*

**bounds**

side note: you could have also flattened the list and sorted the list and take the first and last value as the Max and Min

Then, I can plug in my data tree of distances into the gradient component and have a data tree of colours out. But I am also double-checking the data, to make sure they align.

Which they are, I am just going to plug those both into the * custom preview* component to get my coloured building out.

The output is very similar to before, but you will notice that the voxels near the origin on the bottom left of the image are a lot redder than the rest.

But to make the colouring more obvious, I can switch out the distance from the origin with either one of the X, Y or Z components of the centroids.

Which gives a more drastic colour to the entire building.

**Final Thoughts**

We have looked at a bit of data wrangling in the past but not with the same lens as we have just seen in this article. In the past, we dabbled a bit with aligning data for geometric operations. today, we saw how to extract different bits of data and pair them up with geometry to visualize them.

In the next article, we return back to some more modelling but for now.

I hope that was helpful and as usual, you can find links to the Youtube version of this article below.

As well as a link to download the Grasshopper script (for free) that I used in this article.

As always, thanks for reading

Braden