Name

directionalLight()

Description

Adds a directional light. Directional light comes from one direction and is stronger when hitting a surface squarely and weaker if it hits at a gentle angle. After hitting a surface, a directional lights scatters in all directions. Lights need to be included in the draw() to remain persistent in a looping program. Placing them in the setup() of a looping program will cause them to only have an effect the first time through the loop. The affect of the v1, v2, and v3 parameters is determined by the current color mode. The nx, ny, and nz parameters specify the direction the light is facing. For example, setting ny to -1 will cause the geometry to be lit from below (the light is facing directly upward).

Examples

  • size(400, 400, P3D);
    background(0);
    noStroke();
    directionalLight(51, 102, 126, -1, 0, 0);
    translate(80, 200, 0);
    sphere(120);
    Image output for example 1
  • size(400, 400, P3D);
    background(0);
    noStroke();
    directionalLight(51, 102, 126, 0, -1, 0);
    translate(320, 200, 0);
    sphere(120);
    Image output for example 2

Syntax

  • directionalLight(v1, v2, v3, nx, ny, nz)

Parameters

  • v1(float)red or hue value (depending on current color mode)
  • v2(float)green or saturation value (depending on current color mode)
  • v3(float)blue or brightness value (depending on current color mode)
  • nx(float)direction along the x‑axis
  • ny(float)direction along the y‑axis
  • nz(float)direction along the z‑axis

Return

  • void