-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
62 lines (53 loc) · 1.97 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* This file is part of szczyglis/php-ulam-spiral-generator.
*
* (c) Marcin Szczyglinski <szczyglis@protonmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require __DIR__ . '/vendor/autoload.php';
use Szczyglis\UlamSpiralGenerator\UlamSpiral;
/**
* @package szczyglis/php-ulam-spiral-generator
* @author Marcin Szczyglinski <szczyglis@protonmail.com>
* @copyright 2022 Marcin Szczyglinski
* @license http://www.opensource.org/licenses/MIT The MIT License
* @link https://github.com/szczyglis-dev/php-ulam-spiral-generator
*/
$config = [
'raw' => false, // if true then displays raw spiral (without CSS)
'append_css' => true, // enables CSS stylizing
'append_js' => true, // enables JS features
'no_append_jquery' => false, // disables jQuery script appending if true
'counters_mode' => 'count', // sets counters mode (sum of values or occurencies count)
'row_counters' => true, // enables vertical counters
'col_counters' => true, // enables horizontal counters
'cell_width' => 35, // sets width of cell in pixels,
'cell_height' => 35, // sets height of cell in pixels
'cell_font_size' => 12, // sets font size in pixels
];
$dataset = range(1, 1000); // create dataset
$ulam = new UlamSpiral($config); // create new generator
$ulam->setDataset($dataset); // define dataset
$ulam->addCounter('sum', function($value) { // add custom callbacks for counters ( optional )
return true;
});
$ulam->addCounter('prime', function($value) {
if (is_integer($value)) {
if (UlamSpiral::isPrime($value)) {
return true;
}
}
});
$ulam->addMarker('prime', function($value) { // add custom callbacks for markers ( optional )
if (is_integer($value)) {
if (UlamSpiral::isPrime($value)) {
return '#e9e9e9';
}
}
});
$ulam->buildMatrix(); // build Ulam spiral matrix
echo $ulam->render(); // render spiral
$matrix = $ulam->getMatrix(); // returns spiral's matrix