LightsGL
(Library->OpenGL->LightsGL)
【改造例】
・画面サイズ変更
・boxと同じ場所にsphereを置いてみた
・noStroke()をコメントアウトしてみる
微妙な光の具合の変化を観察してみましょう。
大量のキューブを3種のライトで描きます。
3D->Lights->Lights2のOpenGLライブラリを使った改良版
/**
* LightsGL.
* Modified from an example by Simon Greenwold.
*
* Display a box with three different kinds of lights.
*/
//ProcessingでOpenGLを使うための宣言
import processing.opengl.*;
void setup()
{
size(1024, 768, OPENGL); //画面が大きすぎる人はこの数字を変えましょう
noStroke(); //コメントアウトすると違った雰囲気になります
}
void draw()
{
defineLights();
background(0);
for (int x = 0; x <= width; x += 100) {
for (int y = 0; y <= height; y += 100) {
//OpenGLで大量に描画するときはpushMatrix()〜popMatrix()を使います
pushMatrix();
translate(x, y); // for 文を使ってちょっとずつずらして描画
//mouseの入力を0〜π、つまり0〜180度にmap関数をつかって置き換えます
rotateY(map(mouseX, 0, width, 0, PI));
rotateX(map(mouseY, 0, height, 0, PI));
box(90); //立方体を描画
popMatrix();
}
}
}
void defineLights() {
// Orange point light on the right
pointLight(150, 100, 0, // Color
200, -150, 0); // Position
// Blue directional light from the left
directionalLight(0, 102, 255, // Color
1, 0, 0); // The x-, y-, z-axis direction
// Yellow spotlight from the front
spotLight(255, 255, 109, // Color
0, 40, 200, // Position
0, -0.5, -0.5, // Direction
PI / 2, 2); // Angle, concentration
}