GSDP:GAM100/CProcessing/dt()

From Inside
Jump to: navigation, search

dt()

Description

A function that returns the time between frames in seconds.

Example

static PColor Red;
static PColor Blue;
int Up = 1;
float Count = 0.0f;

void init()
{
    Red = color(255,0,0,255);
    Blue = color(0,0,255,255);
}

// This program shifts between red and blue every second
void update()
{
    // Check if going from red to blue
    if(Up)
    {
        Count += dt();

        // Reverse direction if needed
        if(Count > 1.0f)
        {
            Up = 0;
            Count = 1.0f;
        }
    }

    // Else going from blue to red
    else
    {
        Count -= dt();

        // Reverse direction if needed
        if(Count < 0.0f)
        {
            Up = 1;
            Count = 0.0f;
        }
    }

    // Use count to lerp between red and blue
    PColor lerp = lerpColor(Red, Blue, Count);
    backgroundColor(lerp);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>