GSDP:GAM100/CProcessing/randomFloat()

From Inside
Jump to: navigation, search

randomFloat()

Description

Gives a random float in the range 0.0 to 1.0.

Example

static float val1;
static float val2;
static float val3;

void init()
{
    // Set initial values
    val1 = randomFloat();
    val2 = randomFloat();
    val3 = randomFloat();

    // Set draw mode to center
    rectMode(CENTER);
}

void update() 
{
    // Draw a white background
    background(color(255, 255, 255, 255));

    // Every ten frames change the color
    if(frameCount % 10 == 0)
    {
        val1 = randomFloat();
        val2 = randomFloat();
        val3 = randomFloat();
    }

    // Set the draw color
    fill(color(val1*255, val2*255, val3*255, 255));

    // Draw a square in the center of the screen
    rect((float)canvasWidth/2, (float)canvasHeight/2, 50.0f, 50.0f);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>