# Full rotation using pointLight();

Hello, my brain hurts. I am using the pointLight method on this sphere. I want the light to rotate around the sphere, but I can’t figure out how to do a complete rotation. I am incrementing the z position, but it stops when it gets to the middle of the sphere (max z). Any pointers on how I can get this to have a seemingly full rotation around the sphere? I’m thinking that I have to incorporate the x or y positions of the light, but I’m struggling to figure it out. Thanks in advance.

``````const ballcolor = [30, 180, 255]; // COLOR TO CHANGE (H, S, B)
let brightness = 40;
let z = -40;

function setup() {
createCanvas(400, 400, WEBGL);
colorMode(HSB,255);
frameRate(10);
}

function draw() {

background(30,20,brightness);
brightness += 5;
if (brightness >= 161) brightness = 70;

// CENTRAL SPHERE
push();
noStroke();

//HELP
z += 20;
if (z >= 800) z = -40;
pointLight(ballcolor, 200, -200, z);

specularMaterial(250);
shininess(70);
sphere(75);
pop();
}
``````
1 Like

Hi @achip30,

What you want is simple trigonometry:

Try to think about how you would compute the position of a point at a certain radius on a circle centered on another point in space. (hint)

4 Likes

you want cos and sin to make a circle from an angle going from 0…360

the circle you get:

``````float x = cos (radians(angle)) * radius + centerX;
``````
3 Likes

Helped a lot, thanks @Chrisir and @josephh.
Updated code:

``````const ballcolor = [30, 180, 255]; // COLOR TO CHANGE (H, S, B)
let brightness = 40;

//let y = -200;
function setup() {
createCanvas(400, 400, WEBGL);
colorMode(HSB,255);
frameRate(10);
}

function draw() {
background(20);
/*background(30,20,brightness);
brightness += 5;
if (brightness >= 161) brightness = 70;*/

// CENTRAL SPHERE
push();
noStroke();
pointLight(ballcolor, x, -y, z);
specularMaterial(250);
shininess(100);
sphere(75);
pop();
}
``````
3 Likes

Hello,

This may be of interest:

I used the Cartesian coordinates (x, y, z) directly and stepped through Φ phi and θ theta over time.

`:)`