Repository navigation
Expand file tree
/
Copy pathsunburst.php
More file actions
69 lines (52 loc) · 1.57 KB
/
Copy pathsunburst.php
File metadata and controls
69 lines (52 loc) · 1.57 KB
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
63
64
65
66
67
68
69
<?php
if (in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
Vector Sunburst Generator - Digital Phantom
Usage:
<?php echo $argv[0]; ?> [file] [sides] [radius]
[file] - file name where SVG file will be saved
[sides] - the number of rays the sunburst will have
[radius] - radius of the sunburst
(c) 2013 Digital Phantom - http://www.digitalphantom.net/
authored by: Yoel Nunez http://www.yoelnunez.com/
<?php
exit;
}
else if($argc < 4) {
exit("\nERROR: Pleasy type {$argv[0]} -h for help.\n\n");
}
$filename = $argv[1];
$sides = $argv[2];
$radius = $argv[3];
if(trim($filename) == "") {
exit("\nERROR: filename cannot be please refer to the usage details for instructions.\n\n");
} else if(!is_numeric($sides)) {
exit("\nERROR: The number of sides \"{$sides}\" has to be an integer value.\n\n");
}
else if(!is_numeric($radius)) {
$radius = 50;
}
$points = 5 * $sides;
$angle = 360 / $points;
$coordinates = "";
for($i = 0; $i < $points; $i++) {
$ix = sin(deg2rad($i * $angle)) * $radius;
$iy = cos(deg2rad($i * $angle)) * - 1 * $radius;
$x = $radius + $ix;
$y = $radius + $iy;
if($i % 5 == 0) {
$x = $y = $radius;
}
$coordinates .= "{$x},{$y} ";
}
$handle = fopen($filename, "w+");
if($handle) {
fwrite($handle, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">');
fwrite($handle, '<polygon points="'.trim($coordinates).'" style="fill:#000;"/>');
fwrite($handle, '</svg>');
fclose($handle);
echo "\nYour vector file \"{$filename}\" was succesfully generated.\n\n";
}
else {
echo "\nERROR: The file \"{$filename}\" could not be opened.\n\n";
}