2016-07-04 1 views
0

私はちょうどthree.jsを使いこなし、次の例を見つけました。HERE私は(私は全体の機能を掲示ないのですが、それのほんの一部)は、次のinit関数を参照してください。three.jsの複素数六進数の値

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 
} 

今場所のカップルで、私が使用したコードの次の行を参照してください。

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

私は機能AmbientLightのためのドキュメントをサーフィンするとき、私は以下の取得:

AmbientLightドキュメント、

AmbientLight(color、intensity)

color - 色のRGBコンポーネントの数値。 intensity - ライトの強度/強度の数値。

ちょうど0x443333とは何か、私はこのような何かに出くわすことはなかった。誰かが正確に何を説明することができます0x443333意味ですか?

+3

これは: '(例えばCSSで、またはPhotoshop)16進'#443333'と同じである0x443333' - ちょうど表明しますその数字が16進数で書かれていることを示す「0x」を付けて、javascriptがこれらを正しく解析するようにします。 (これは、あなたがjavascriptに数字「01」を書くことができない理由です。間違っているとマークされます) – somethinghere

答えて

1

16進数の色は、色のRGB値を表す16進数でエンコードされた文字列です。
このコードは、3つの別々のhexadecimal部分で分割できます。 1つは赤、緑、青(RGB)用です。次のように

進エンコーディングが機能:

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 

次のようにだからあなたのRGB値は以下のとおりです。

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

ので、この色は、次のRGBの色を表す:rgb(68,51,51)を。

このエンコードでは、256 x 256 x 256 = 16777216の異なる色を表現できます。

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); 

虹のすべての他の色のチェックthis reference ...

+0

すごく感謝してます!! :) –