【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)
上達の研究家 / アーティスト
独学1年9ヶ月で虎ノ門ヒルズ49階、地上250mのインフィニティプールへ作品提供・展示

言葉×コード×手書き。三位一体の表現が成長する過程の記録

【発信】クリエイティブコーディング(2024.3~) / 絵(2025.11~) / モレスキン / 思考法 / 生き方

▼運営者について
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次