【Processing】directionalLight()関数の使い方【3Dシーンで特定の方向から光を当てる】

【Processing】directionalLight()関数の使い方【3Dシーンで特定の方向から光を当てる】
  • URLをコピーしました!
ワタタク

今回の記事の目的はProcessingの「directionalLight()関数」を理解し、自分なりに使ってみること。

記事内のProcessingのバージョンは4.3。

目次

【Processing】directionalLight()関数について

directionalLight()関数について
  • directionalLight()は「方向性のある光」という意味
  • directionalLight()関数は、3Dシーンで特定の方向から光を当てるために使う
    • 太陽の光のように、特定の方向から一様に照らす光

【Processing】directionalLight()関数の主な書き方【構文】

以下のように書きます。

directionalLight(色の赤成分, 色の緑成分, 色の青成分, 光の方向X, 光の方向Y, 光の方向Z);

【Processing】directionalLight()関数の使い方【画像とコード】

xを1に設定

xを1に設定
size(400, 400, P3D);
background(0);
noStroke();
directionalLight(255, 165, 0, 1, 0, 0);
translate(200, 200, 0);
sphere(120);

xを-1に設定

xを-1に設定
size(400, 400, P3D);
background(0);
noStroke();
directionalLight(255, 165, 0, -1, 0, 0);
translate(200, 200, 0);
sphere(120);
save("2.jpg");

yを1に設定

yを1に設定
size(400, 400, P3D);
background(0);
noStroke();
directionalLight(255, 165, 0, 0, 1, 0);
translate(200, 200, 0);
sphere(120);

yを-1に設定

yを-1に設定
size(400, 400, P3D);
background(0);
noStroke();
directionalLight(255, 165, 0, 0, -1, 0);
translate(200, 200, 0);
sphere(120);

zを1に設定

zを1に設定
size(400, 400, P3D);
background(0);
noStroke();
directionalLight(255, 165, 0, 0, 0, 1);
translate(200, 200, 0);
sphere(120);

zを-1に設定

zを-1に設定
size(400, 400, P3D);
background(0);
noStroke();
directionalLight(255, 165, 0, 0, 0, -1);
translate(200, 200, 0);
sphere(120);

yを1, zを1に設定

yを1, zを1に設定
size(400, 400, P3D);
background(0);
noStroke();
directionalLight(255, 165, 0, 0, 1, 1);
translate(200, 200, 0);
sphere(120);

【Processing】directionalLight()関数はどんな表現で使えそうか

月とか太陽とかの表現で使える。

【Processing】directionalLight()関数を使ってみた感想

今回の記事のdirectionalLight()関数で、yを1, zを1に設定して描かれた月みたいなのが好きですね。

ワタタク

それでは今日もレッツワクワクコーディング。

ワタタク(Watataku)
上達の研究家
アナログ絵画(2025.11~) × クリエイティブコーディング(2024.3~)

「不完全な人間(Analog)」が、「完全な論理(Algorithm)」を武器にどこまで行けるか。

手描きの一本の線(One)をコードで無限(All)に拡張し、再び一つの作品へ定着させる。「才能」ではなく「発見」と「システム」で描く、人生をかけた実験記録。

溢れる思考を、独自の脳内OS「Watataku Blueprint」で整理し、初心者から世界で活躍するまでの「激闘」と「攻略本」を公開しています。

▼【創作×上達】思考を「作品」に変える、モレスキン6冊の運用設計図
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次