Simple Mood light code

Hi guys, I came across an instructables page for making a mood light with LEDs and a light diffuser. Ive implemented the provided code and it actually works a treat!

However, the code being does not fully make sense to me

// Smooth RGB mood lamp
// Changes an RGB LED's color smoothly 

// ---------------------------------------------------
// The brightness of the leds follows these equations:
// Red = sin(x)
// Green = sin(x + PI/3)
// Blue = sin(x + 2PI/3)
// for x from 0 to PI
// ---------------------------------------------------

float RGB[3];
int redLed   = 11;  // red LED in Digital Pin 11 (PWM)
int greenLed = 5;  // green LED in Digital Pin 5 (PWM)
int yellowLed  = 3 ;   // yellow LED in Digital Pin 3 (PWM)

void setup(){
  pinMode(redLed,OUTPUT);  // tell arduino it's an output
  pinMode(greenLed,OUTPUT);// tell arduino it's an output
  pinMode(yellowLed,OUTPUT); // tell arduino it's an output

  // set all the outputs to low 

void loop(){
  for (float x=0;x<PI;x=x+0.00001){
    RGB[0]=255*abs(sin(x*(180/PI)));           // calculate the brightness for the red led
    RGB[1]=255*abs(sin((x+PI/3)*(180/PI)));    // calculate the brightness for the green led
    RGB[2]=255*abs(sin((x+(2*PI)/3)*(180/PI)));// calculate the brightness for the blue led

    analogWrite(redLed, RGB[0]);
    analogWrite(greenLed, RGB[1]);
    analogWrite(yellowLed, RGB[2]);

    for(int i=0;i<3;i++){

I dont understand the point of using the sin PI business…i mean…is that really necessary ?

Could someone please enlighten me?

Thanks in advance

The sin() function takes care that the values increase/decrease gradually like a wave. You could use any waveform linear triangle etc but sin() is build in ....

Oh i see, so thats actually like an arduino pre-written functions or something?

Cool :) I never realised I could use that.

it is a standard math function - -

Yes I'm aware of that, just didn't know it worked with Arduino.