Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Processing allows you to specify colors in several different systems or color spaces. Now the most common one is the RGB, Red, Green, Blue, or you can use either a three numbers on a 0 to 255 scale or you can use a single hex code. The other of choice is what's called an HSB system, which stands for Hue, Saturation and Brightness which is also common. Although it tends to use a different scale system where the Hue part is specified on the 360 degree circle and the Saturation and Brightness are specified on 100% scale.
In this movie I want to show you how to use each of these different color spaces to get what you want in your drawings. I'm going to start by just putting a little comment with the name of this sketch. Like the last movie I'm going to start by specifying the size of the window, I'm also going to turn on anti-aliasing. I'm going to turn off the strokes on the shapes. I'm going to put in a background, let's say relatively dark gray and I'm going to position the rectangles by their centers.
Then I'm going to use two variables that help me position the rectangles. The first one is the number of rectangles that I want to draw. I want to use four in this case and then I'm going to use a float variable for X to help me get the positions for each one of this, and that'll be the width of the window divided by n+1, that'll give me the center points for each of the rectangles. Then what I do, because I put in the code for the rectangles, I'll do X times 1 and we'll put them the center halfway down and I'll make them 100 pixels wide and 100 pixels tall.
Now what I'm going to do though is I'm going to start specifying the colors. I'm going to use a green that I had from the previous movie and I'll specify this in the default RGB way that we normally like to use in Processing. So what I'm going to do is I can specify fill and I'm going to put in 116, 173, 146. And when I do that I get a green box here on my gray background. Now as you've seen a number of times, you can also use hex code to specify these. Now if it turns out that you have a color that you like and you know either the three RGB codes or you know the hex code, there is a way to get from one to another.
What you do is you come up to Tools and you come to Color Selector and what you can do here is you can enter the colors that you have, so right now my RGB is 116 and the G is 173 and the Blue component is 146 and then you see that that's the same one that I have up here on the top and right down here is the hex code that I need. It's 748092, so I'm just going to copy that, I'll put it down here for a second, because now I'm going to copy this, the rectangle information and I'm going to specify fill by putting in this hex code, I can delete this line, and I'll move this over to the next space.
So, what I have here is the same color specified two ways, this is the three number RGB code, and the next one is the unitary hex code, which actually is a version of the RGB code. And so when I press Run, I get to identical squares right next to each other. Now it turns out that there is an interesting alternative, you saw also that there was the HSB system, if I can go back to that window, that's where hue, saturation and brightness, and when I put that in here, what I have to do is I have to tell Processing that I'm using the HSB, Hue, Saturation, Brightness color mode, so I put in colorMode and I'll put in HSB.
Now, by default it's RGB, and if I wanted to, I can copy that and put it up here earlier, and put RGB, but that is the default, I don't need to do that. What I'm going to do down here is I'm going to put in HSB, but HSB uses a different set of dimensions. Now by default, Processing will try to use the 0 to 255 system, even though on the color selector it gave me the hue in terms of degrees around in a circle, and the saturation and brightness in terms of 0 to 100%, so you need to actually specify that and what you can do here is when you put the color mode, you put HSB, you can then put numbers to specify what is the maximum value for each of the components.
In this case, I say that the Hue, it has a maximum value of 360, Saturation and Brightness, each of them maximum 100. Then what I can do is I can come down and I can specify the fill using those numbers. If I go back to the Color Selector, I see they're 151, 32 and 67; 151, 32 and 67, and then I'm going to draw a rectangle again, and put that down right here and then I've a third rectangle with an identical shade of green.
Now I'm going to show you one other trick, there is a fourth way of working with colors that is similar to the color selector. If you go up to Tools in the menu and go to the bottom to Add Tool, one of the choice is, is what's called the Color Selector Plus, if you click on that and click Install, let me close that. Now we come back to Tools and the Color Selector Plus is an option near the bottom. This is a similar tool, but you see it's got a lot more choices and it let's you to do some other things that you couldn't do otherwise.
What I'm going to do here is I'm going to take the hex code that I have for the color and I'll just paste it in right there and it brings up the one. And now what you see here is we have the RGB codes, the 116, 173 and the 146, that's the same. And then we have Hue, Saturation and Value. Now what's interesting is this one is using a slightly different system here to do the things. This one is actually using a 0 to 255 scale for the Saturation and the Value, so what I'm going to do now, actually I'll just copy all of this.
It's still an HSV and HSB are the same thing or Value and Brightness, just two different terms for the same thing, so I can leave it as HSB, but I do need to specify that I'm on a 255 scale for this. It would be nice if that were indicated more clearly on this, but we have what we have. And so the Hue is still 151, but the Saturation goes from 32 to 84, because I'm on a different scale, and the brightness or Value goes from 67 to 173, and otherwise, I draw in my fourth rectangle, I can close this, it floats and stays on the top of everything.
I'm going to Save this and Run, and there you go. And I've noticed that some times you get very slight variations in color, because I assume things like rounding errors, but these are different ways of specifying the same colors, four different ways these three number RGB system, the hex code for the RGB. You can specify the Hue, Saturation, Brightness using Processing with 360, 100, 100 system or you can use the Color Selector Plus, which also uses the HSB or HSV with 360, 255, 255 system.
Anyhow, these are different ways of specifying colors, and depending on your purposes, each one of this can be very useful in producing your own images and visualizations.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101498 Viewers
61 Video lessons · 88258 Viewers
71 Video lessons · 72129 Viewers
56 Video lessons · 103894 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.