javascript - complex hex color value in three.js -
i messing around three.js , came across following example here. see following init function(i not posting whole function , 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 couple of places see following line of code used :
scene.add( new three.ambientlight( 0x443333 ) );
when surf docs function ambientlight
following:
ambientlight docs,
ambientlight( color, intensity )
color — numeric value of rgb component of color. intensity -- numeric value of light's strength/intensity.
but 0x443333
, have never before come across this. can explain 0x443333
mean ?
a hex color hex encoded string representing rgb values of color.
can split code in 3 separate hexadecimal parts; 1 red, green , blue (rgb);
hex encoding works follows:
0 : 0 1 : 1 2 : 2 3 : 3 4 : 4 5 : 5 6 : 6 7 : 7 8 : 8 9 : 9 : 10 b : 11 c : 12 d : 13 e : 14 f : 15
so rgb values follows:
red = 44 -> 4 x 16 + 4 -> 68 green = 33 -> 3 x 16 + 3 -> 51 blue = 33 -> 3 x 16 + 3 -> 51
so color represents 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 other colors of rainbow...
Comments
Post a Comment