# Custom Colors explainer

#1

The aim of this puzzle: Draw one box that is colored magenta.
Walkthrough of the solution: Magenta is not a color that the grasshopper concept drawBox() recognizes. However, you can still create magenta by using a Red, Green, Blue (RGB) object inside drawBox(). Red, green and blue can have any value between 0 and 255; adjusting them you can create almost any color you could think of, including magenta. To create magenta you need red and blue to be at their maximum values (255) and green to have no value (0).
Sample code solution:
(Tap below to reveal)

var someCustomColor = {
red : 255,
green : 0,
blue : 255
}
drawBox(someCustomColor)

JavaScript Concepts: Calling Functions, Identifiers, Variable Declaration, Data Structures (object), Code Block (object)
Grasshopper Concepts: drawBox()

Could someone tell me how to use 225 instead of 225?
#2

I feel that this topic missed some important information. I didnāt understand how the values were passed into the drawbox routine, so in the following quiz I got it totally wrong. I think that the explanation would have better suited the learning stage, not the quiz answer.

#3

Whatās the concept behind this quiz,
Is it an object?
What does those numbers depict?
Why they need to be equal?
Is drawbox a predefined function?

Why this combination gives black?

#4

You actually have very dark red there. Each value, R, G, and B, represent how much of each to mix. 0 is the least, 255 is the most. 0, 0, 0 is black, and 255, 255, 255 is white. 5, 0, 0 is very near 0, 0, 0, and so appears nearly black. The reddest Red is 255, 0 , 0. Magenta has maximum Red plus maximum Blue, and no Green at all, so its RGB code is 255, 0, 255. Hope that helps!

#5

It is not working anyway!!!

#6

Iām doing it right and they are saying set blue from 225 to 225!!!

#7

If you look closely, itās asking you to set the value to two-hundred fifty-five.

This number comes from being 1 less than 256 which is 2 to the 8th power (2āø). This is the number of ways you can choose 1 and 0 if you choose eight 1ās and 0ās. Since our first combination represents 0, our second combination represents 1, our final representation (the two-hundred fifty-sixth one) represents 255.

āFrankie

#8

#9

Whoops, I screwed that up. I did 225 instead of 255. Sorry about that!

#10

With most programming languages they arenāt very forgiving. Sometimes just stepping away for a bit or just looking at it with a different angle helps you solve the problem. Just with more practice you get better but even the greatest minds can make simple mistakes. Donāt let that discourage you but motivate you to do better. Have fun coding

#11

In that situation maybe is showing an error, but the color is correct? I mean i wrote as well 5 for green 255 for blue and red, and the color was correct, but generelly of course was that solution not correct.

Soā¦ my question is: why?

#12

And one question more āāļø
Im trying to understand var, const and let obejects. And the difference between all of them.

So what is an var object in that example? The colors? Which i can change or put more than that one because is the var object?

Probably i mixed all new informationsā¦
Im looking forward for your help āāļø
Thank u!!!

#13

This puzzle is looking for a box whose color is exactly: 255 Red, 0 Green, and 255 Blue. Changing any of those values, even by 1, will give you a different color although it may look very similar.

We could create a puzzle, or modify this one to accept a larger range of colors. For example, instead of looking for exactly (255, 0, 255), we could check if the red and blue parts are greater than 200 and the green is less than 50. Many other of the puzzle are more lenient in this way, but we chose to look for a very specific color here.

āFrankie

#14

We donāt have any puzzle that talk about const yet, but in Fundamentals II there are lessons about the differences between var and let.

In this puzzle, you wouldnāt see a difference between var, let, or const. They create a variable called someCustomColor that stores an object. The object is all the data between the curly brackets {}. An object is a list of properties. Each property has a Name and Value. In the someCustomColor object, there are 3 properties, named red, green, and blue. And the values of each property are the numbers you entered, either 0 or 255.

Itās common to refer to a variable as being identical to the value its storing. So if we have var x = 10, we can say, "x is a number". Other examples:

let y = 'abc';
"y is a string"

let o = {
a: 22,
b: 11
};

"o is an object with 2 properties: a and b"

āFrankie

#15

Thank u Frankie for your help!