#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Shining a spotlight at the background

edited April 2016

I want to be able to simply shine a spotlight straight into the screen onto the background in a sort of 2D manner. I found that using ortho() eliminates the perspective which is good. The next issue is that the lights need a surface to shine onto. I found that shining onto a sphere creates the effect I need but I want to shine onto the entire window so I tried to use a square but I get really weird results. Below is simple code which shows a spotlight shining straight down (Z) onto a sphere but I try to shine down onto a square (XY plane) it only shows up near the corners. Ellipse has interesting black hole light results. Any ideas? I basically want a 2D program but want to use lights to control translucent areas of color.

void setup()
{
size(1240, 660, P3D);
ortho();
//noStroke();
sphereDetail(120);
colorMode(RGB, 255);
rectMode(CENTER);
}

int A, B, Ax, Ay, Bx, By;

void draw()
{
background(20);
ambientLight(50, 50, 50);

spotLight(255, 0, 0, width/2, height/2, 600, 0, 0, -1, PI/2, 100);

spotLight(0, A, 0, Ax, Ay, 600, 0, 0, -1, PI/2, 100);
spotLight(0, 0, B, Bx, By, 600, 0, 0, -1, PI/2, 100);

translate(mouseX, mouseY, 0);

sphere(300);
//ellipse(0,0,300,300);
//box(300);
//rect(0,0,300,300);

/*if (A > 0)
A-=5;
if (B > 0)
B-=5;
*/
}

boolean alt;
void mouseClicked()
{
alt = !alt;
if (alt)
{
Ax = mouseX;
Ay = mouseY;
A = 255;
} else
{
Bx = mouseX;
By = mouseY;
B = 255;
}
}
Tagged: