-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormal_distribution.php
64 lines (53 loc) · 1.99 KB
/
normal_distribution.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
63
64
<?php
function array_distribute($mean,$sd,$min,$max){
$result = array();
$total_mean = intval($mean*$sd);
while($sd>1){
$allowed_max = $total_mean - $sd - $min;
$allowed_min = intval($total_mean/$sd);
$random = mt_rand(max($min,$allowed_min),min($max,$allowed_max));
$result[]=$random;
$sd--;
$total_mean-=$random;
}
$result[] = $total_mean;
return $result;
}
function element_children(&$elements, $sort = FALSE) {
// Do not attempt to sort elements which have already been sorted.
$sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort;
// Filter out properties from the element, leaving only children.
$children = array();
$sortable = FALSE;
foreach ($elements as $key => $value) {
if ($key === '' || $key[0] !== '#') {
$children[$key] = $value;
if (is_array($value) && isset($value['#weight'])) {
$sortable = TRUE;
}
}
}
// Sort the children if necessary.
if ($sort && $sortable) {
uasort($children, 'element_sort');
// Put the sorted children back into $elements in the correct order, to
// preserve sorting if the same element is passed through
// element_children() twice.
foreach ($children as $key => $child) {
unset($elements[$key]);
$elements[$key] = $child;
}
$elements['#sorted'] = TRUE;
}
return array_keys($children);
}
header("Content-Type: image/svg+xml");
echo '<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">';
echo '<svg xmlns="http://www.w3.org/2000/svg" height="600" width="600" xmlns:xlink="http://www.w3.org/1999/xlink" style="background-color:black" >';
$x = array_distribute(300,1000,100,400);
$y = array_distribute(300,1000,100,400);
$alpha = array_distribute(.5,1000,.1,1);
foreach(element_children($y) as $key) {
echo '<circle cx="' . $x[$key] . '" cy="' . $y[$key] . '" r="2" fill="white"/>';
}
echo '</svg>';