PHP code example of sqonk / phext-visualise
1. Go to this page and download the library: Download sqonk/phext-visualise library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sqonk / phext-visualise example snippets
use sqonk\phext\visualise\Visualiser;
use sqonk\phext\plotlib\BulkPlot;
$visualiser = new Visualiser;
$windowID = $visualiser->open(title:'graphs', width:1000, height:850, imageCount:4, posX:20, posY:25);
$values = [];
$xs = [];
foreach (sequence(start:1, end:100) as $i)
{
$values[] = rand(1,30);
$xs[] = $i;
$plot = new BulkPlot;
$plot->add(type:'line', series:[$values], options:[
'title' => 'Lines',
'xseries' => $xs,
]);
$plot->add(type:'bar', series:[$values], options:[
'title' => 'Bars',
'xseries' => $xs,
]);
$plot->add(type:'linefill', series:[$values], options:[
'title' => 'Area',
'xseries' => $xs,
]);
$plot->add(type:'scatter', series:[$values], options:[
'title' => 'Scatter Plot',
'xseries' => $xs,
]);
$images = $plot->render(writeToFile:false, width:500, height:400);
$visualiser->update(images:$images, windowID:$windowID);
}
ask('press any key to continue.'); // pause script.
use sqonk\phext\visualise\Visualiser;
$visualiser = new Visualiser;
function adjust($sq): void {
$sq->size = $sq->dir ? $sq->size + $sq->step : $sq->size - $sq->step;
if ($sq->size > 350)
$sq->dir = false;
else if ($sq->size < 5)
$sq->dir = true;
}
$Sq = named_objectify('size', 'dir', 'step', 'r', 'g', 'b');
$squares = [
$Sq(5, true, 10, 147,17,50),
$Sq(20, true, 5, 148,32,146),
$Sq(20, true, 15, 0,0,200)
];
foreach ($visualiser->animate(400, 400, title:'Squares', frames:1000, posX:20, posY:50) as $count => $img)
{
# prefill white background
$white = imagecolorallocate($img, 255,255,255);
imagefilledrectangle(image:$img, x1:0, y1:0, x2:399, y2:399, color:$white);
imagesetthickness($img, 3);
foreach ($squares as $s) {
$r = $s->size / 2;
$clr = imagecolorallocate(image:$img, red:$s->r, green:$s->g, blue:$s->b);
imagerectangle(image:$img, x1:200-$r, y1:200-$r, x2:200+$r, y2:200+$r, color:$clr);
adjust($s);
}
}
println('completed.');