Skip to content

Using AWDY

Robert Wesner edited this page Aug 24, 2024 · 2 revisions

Example:

<?php

use RobertWesner\AWDY\AWDY;
use RobertWesner\AWDY\Template\Templates\SimpleTemplate;

require __DIR__ . '/../vendor/autoload.php';

const LIMIT = 1337;
const PROGRESS_AFTER = 100;

// Set up AWDY with a simple template
AWDY::setUp(new SimpleTemplate()/*, [width], [height] */);

$i = 0;
while (true) {
    if ($i >= LIMIT) {
        break;
    }

    if (($i % 77) === 0) {
        // print to the logging section
        AWDY::printf('%d is your lucky number!' . PHP_EOL, $i);
    }

    $i++;

    if ($i >= LIMIT || ($i % PROGRESS_AFTER) === 0) {
        // update the progress (floating point number 0 to 1)
        AWDY::progress($i / LIMIT);
    }
}
Clone this wiki locally