From 4455798ad8994c0ba7f8791a903af376fb2e5125 Mon Sep 17 00:00:00 2001 From: MEUNIER Thibaud Date: Sat, 6 Jul 2019 14:51:23 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20de=20la=20m=C3=A9thode=20spirale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- methode2/spirale/draw.php | 135 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 methode2/spirale/draw.php diff --git a/methode2/spirale/draw.php b/methode2/spirale/draw.php new file mode 100644 index 0000000..dab3883 --- /dev/null +++ b/methode2/spirale/draw.php @@ -0,0 +1,135 @@ + $max) $max = $v['value']; + if (($v['value'] < $min)||($min == -1)) $min = $v['value']; + $somme += $v['value']; + } + if ($min == $max) $max = $min + 1; + if ($somme == 0) return; + + // On commence au centre de l'image + $xc = $x + ($width / 2); + $yc = $y + ($height / 2); + $r = $width / 3; + $cur = 0; + $n = 0; + $x1 = $xc; + $y1 = $yc; + $x2 = $xc; + $y2 = $yc; + + // Trouver le max + $max=0; + while(true){ + $r1 = 0.05 * $max; + $x2 = $xc + $r1*cos($r1); + $y2 = $yc + $r1*sin($r1); + if (($x2 > $width) || ($x2 < 0)) break; + if (($y2 > $height) || ($y2 < 0)) break; + imageline($vImage, $x1, $y1, $x2, $y2, $couleurs[0]); + $x1 = $x2; + $y1 = $y2; + $max++; + } + $coef = floatval($max) / floatval($somme); + + $cur = 0; + $n = 0; + $x1 = $xc; + $y1 = $yc; + $x2 = $xc; + $y2 = $yc; + + foreach($data as $transaction) + { + // chaque fois que toutes les couleurs ont été utilisées + // on mélange leur ordre + if (!($n%$nb_couleurs)) shuffle($couleurs); + // S'il n'y a qu'une transaction + // Ou Si la transaction courante représente plus du 5eme de la somme des tx + // On s'interdit la couleur de fond + if (($n_data == 1)||($transaction['value'] > ($somme/5))) + while ($couleurs[$n%$nb_couleurs] == $fond) $n++; + $couleur = $couleurs[$n%$nb_couleurs]; + + // le segment de couleur est de longueur proportionnelle + // à la valeur de sa transaction + $next = $cur + ($coef*$transaction['value']); + if ($next > $max) $next = $max; + + while($cur<$next) + { + $r1 = 0.05 * $cur; + $x2 = $xc + $r1*cos($r1); + $y2 = $yc + $r1*sin($r1); + imageline($vImage, $x1, $y1, $x2, $y2, $couleur); + $x1 = $x2; + $y1 = $y2; + $cur++; + } + $n++; + } +} + +?>