Alexander Solonik
Alexander Solonik

Reputation: 10230

complex hex color value in three.js

I was just messing around with three.js and came across the following example HERE. I see the following init function(i am not posting the whole function , but just a part of it):

    function init() {

        renderer = new THREE.WebGLRenderer( { antialias: true } );
        renderer.setPixelRatio( window.devicePixelRatio );
        renderer.setSize( window.innerWidth, window.innerHeight );
        container.appendChild( renderer.domElement );

        scene = new THREE.Scene();

        camera = new THREE.PerspectiveCamera( fov, window.innerWidth / window.innerHeight, 1, 1000 );
        camera.position.z = 100;
        camera.target = new THREE.Vector3();

        controls = new THREE.OrbitControls( camera, renderer.domElement );
        controls.minDistance = 50;
        controls.maxDistance = 200;

        scene.add( new THREE.AmbientLight( 0x443333 ) );

        var light = new THREE.DirectionalLight( 0xffddcc, 1 );
        light.position.set( 1, 0.75, 0.5 );
        scene.add( light );

        var light = new THREE.DirectionalLight( 0xccccff, 1 );
        light.position.set( -1, 0.75, -0.5 );
        scene.add( light );
        //.....  more code
}

Now in a couple of places i see the following line of code used :

scene.add( new THREE.AmbientLight( 0x443333 ) );

When i surf the docs for the function AmbientLight i get the following:

AmbientLight docs,

AmbientLight( color, intensity )

color — Numeric value of the RGB component of the color. intensity -- Numeric value of the light's strength/intensity.

But what exactly is 0x443333 , I have never before come across something like this. Can somebody explain what exactly does 0x443333 mean ?

Upvotes: 1

Views: 5752

Answers (1)

Wilt
Wilt

Reputation: 44356

A hex color is a hex encoded string representing the RGB values of the color.
You can split this code in three separate hexadecimal parts; one for Red, Green and Blue (RGB);

Hex encoding works as follows:

0 : 0
1 : 1
2 : 2
3 : 3
4 : 4
5 : 5
6 : 6
7 : 7
8 : 8
9 : 9
a : 10
b : 11
c : 12
d : 13
e : 14
f : 15

So your RGB values are as follows:

Red   = 44 -> 4 x 16 + 4 -> 68
Green = 33 -> 3 x 16 + 3 -> 51
Blue  = 33 -> 3 x 16 + 3 -> 51

So this color represents the following RGB color: rgb(68,51,51).

This encoding allows representation of 256 x 256 x 256 = 16777216 different colors.

white : 0x000000 = rgb(0,0,0);
black : 0xffffff = rgb(255,255,255);
red   : 0xff0000 = rgb(255,0,0);
green : 0x00ff00 = rgb(0,255,0);
blue  : 0x0000ff = rgb(0,0,255);

Check this reference for all other colors of the rainbow...

Upvotes: 2

Related Questions