From 09d51c6bba736b370112acf66c9d7fbb87060ef7 Mon Sep 17 00:00:00 2001 From: MEUNIER Thibaud Date: Sat, 10 Nov 2018 10:01:06 +0100 Subject: [PATCH] gestion des cercles et de leurs couleurs --- 1 | 0 global/inc/colors.php | 25 ++++++ methode2/circle/draw.php | 73 ++++++++++++++++ methode2/circle_line/draw.php | 81 ++++++++++++++++++ methode2/circle_spline/draw.php | 112 ++++++++++++++++++++++++ methode2/circles/draw.php | 83 ++++++++++++++++++ methode2/circles_spline/draw.php | 138 ++++++++++++++++++++++++++++++ methode2/robot.sh | 2 +- methode2/splinelineblack/draw.php | 14 +-- 9 files changed, 514 insertions(+), 14 deletions(-) create mode 100644 1 create mode 100644 methode2/circle/draw.php create mode 100644 methode2/circle_line/draw.php create mode 100644 methode2/circle_spline/draw.php create mode 100644 methode2/circles/draw.php create mode 100644 methode2/circles_spline/draw.php diff --git a/1 b/1 new file mode 100644 index 0000000..e69de29 diff --git a/global/inc/colors.php b/global/inc/colors.php index c1b7bc6..82ec7f9 100644 --- a/global/inc/colors.php +++ b/global/inc/colors.php @@ -120,4 +120,29 @@ class ColorGradient } } +function getGDcolorGradientArray($vImage, $nb_colors, $couleurRGB, $fondRGB, $alpha = 0) +{ + $vColor = array(); + + // Calculer un gradient de couleurs + $hex1 = ColorGradient::rgb2hex($couleurRGB); + $hex2 = ColorGradient::rgb2hex([255,255,255]); + if ($hex2 == ColorGradient::rgb2hex($fondRGB)) $hex2 = ColorGradient::rgb2hex([0,0,0]); + $hex_val = array( $hex1, $hex2 ); + $gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors); + + // Pour chaque couleur, on rajoute deux informations + // - un pourcentage + // - une couleur GD + for($i=0;$i<$nb_colors;$i++) + { + $rgbval = ColorGradient::hex2rgb($gradient[$i]); + $vColor[$i] = new ColorGradient(); + $vColor[$i]->pct = ($i * 1.0) / $nb_colors; + $vColor[$i]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha); + } + + return $vColor; +} + ?> diff --git a/methode2/circle/draw.php b/methode2/circle/draw.php new file mode 100644 index 0000000..5c0efb7 --- /dev/null +++ b/methode2/circle/draw.php @@ -0,0 +1,73 @@ +color); + } + } +} + +?> diff --git a/methode2/circle_line/draw.php b/methode2/circle_line/draw.php new file mode 100644 index 0000000..d928b0a --- /dev/null +++ b/methode2/circle_line/draw.php @@ -0,0 +1,81 @@ +color); + + $x0 = $xi; + $y0 = $yi; + } + $xi = floor($xc + $r*cos(deg2rad(360))); + $yi = floor($yc + $r*sin(deg2rad(360))); + imageline($vImage, $x0, $y0, $xi, $yi, $vColor[$i]->color); + } +} + +?> diff --git a/methode2/circle_spline/draw.php b/methode2/circle_spline/draw.php new file mode 100644 index 0000000..19d4cdc --- /dev/null +++ b/methode2/circle_spline/draw.php @@ -0,0 +1,112 @@ + 5) $coef = 0.3; + if ($c > 7) $coef = 0.8; + if ($c > 9) $coef = 1.2; + + foreach($bornes as $b) + { + // 1er 1/2 cercle + $aCoords = array(); + $x0 = $xc; + $x1 = $xc; + for($i=$b[0];$i<$b[1];$i++) + { + $valeur = hexdec($transaction['hash'][$i%TX_HASH_LEN]) - 8; + $r = $r0+($valeur*$coef); + + $xi = $xc + $r*cos(deg2rad($i)); + $yi = $yc + $r*sin(deg2rad($i)); + + $aCoords[$xi] = $yi; + + if ($xi < $x0) $x0 = $xi; + if ($xi > $x1) $x1 = $xi; + } + if ($oCurve) + { + $oCurve->setInitCoords($aCoords); + $r = $oCurve->processCoords(); + if ($r) + { + $curveGraph = new Plot($r); + $curveGraph->drawLine($vImage, $vColor, $x0, $x1); + } + } + } + } +} + +?> diff --git a/methode2/circles/draw.php b/methode2/circles/draw.php new file mode 100644 index 0000000..e3a9e86 --- /dev/null +++ b/methode2/circles/draw.php @@ -0,0 +1,83 @@ + $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; + + + $xc = $x + ($width / 2); + $yc = $y + ($height / 2); + + foreach($data as $transaction) + { + // Le rayon du cercle dépend du montant de la transaction + $r = $width / 3; + if ($n_data > 1) $r *= ($transaction['value'] - $min) / ($max - $min); + + for($i=0;$i<360;$i++) + { + $xi = $xc + $r*cos(deg2rad($i)); + $yi = $yc + $r*sin(deg2rad($i)); + imagesetpixel($vImage, $xi, $yi, $vColor[$i]->color); + } + } +} + +?> diff --git a/methode2/circles_spline/draw.php b/methode2/circles_spline/draw.php new file mode 100644 index 0000000..f31ced6 --- /dev/null +++ b/methode2/circles_spline/draw.php @@ -0,0 +1,138 @@ + $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; + + // Plus il y a de transactions plus la couleur de tracé sera transparente + $alpha = 115; + $nb = count($data); + if ($nb < 50) $alpha = 110; + if ($nb < 20) $alpha = 105; + if ($nb < 5) $alpha = 0; + + // Dégradé de 360 couleurs entre la couleur de dessin et le blanc + $vColor = getGDcolorGradientArray($vImage, 360, $couleurRGB, $fondRGB, $alpha); + + // Le rayon du cercle dépend du montant de la transaction + //$r0 = $width / 3; + //if ($n_data > 1) $r0 *= ($transaction['value'] - $min) / ($max - $min); + + // Un calculateur de Spline + $oCurve = new CubicSplines(); + $bornes = [[0,180],[180,360]]; + + $xc = $x + ($width / 2); + $yc = $y + ($height / 2); + $coef = 0.3; + + foreach($data as $transaction) + { + // Le rayon du cercle dépend du montant de la transaction + $r0 = $width / 3; + if ($n_data > 1) $r0 *= ($transaction['value'] - $min) / ($max - $min); + for($i=0;$i<360;$i++) + { + $xi = $xc + $r0*cos(deg2rad($i)); + $yi = $yc + $r0*sin(deg2rad($i)); + imagesetpixel($vImage, $xi, $yi, $vColor[$i]->color); + } + + // Pas de splines sur les r0 trop petits + if ($r0 < 20) continue; + + // Un coef aléatoire + $coef = 0.1; + $c = rand(0,10); + if ($c > 5) $coef = 0.3; + if ($c > 7) $coef = 0.8; + if ($c > 9) $coef = 1.2; + + foreach($bornes as $b) + { + // 1er 1/2 cercle + $aCoords = array(); + $x0 = $xc; + $x1 = $xc; + for($i=$b[0];$i<$b[1];$i++) + { + $valeur = hexdec($transaction['hash'][$i%TX_HASH_LEN]) - 8; + $r = $r0+($valeur*$coef); + + $xi = $xc + $r*cos(deg2rad($i)); + $yi = $yc + $r*sin(deg2rad($i)); + + $aCoords[$xi] = $yi; + + if ($xi < $x0) $x0 = $xi; + if ($xi > $x1) $x1 = $xi; + } + if ($oCurve) + { + $oCurve->setInitCoords($aCoords); + $r = $oCurve->processCoords(); + if ($r) + { + $curveGraph = new Plot($r); + $curveGraph->drawLine($vImage, $vColor, $x0, $x1); + } + } + } + } +} + +?> diff --git a/methode2/robot.sh b/methode2/robot.sh index 575de42..190ab68 100755 --- a/methode2/robot.sh +++ b/methode2/robot.sh @@ -11,7 +11,7 @@ fi if [ -f $flag ]; then - echo "$METHODE_bot is already running !" + echo "${METHODE}_bot is already running ! [$flag]" exit 0 fi diff --git a/methode2/splinelineblack/draw.php b/methode2/splinelineblack/draw.php index 5e2d6af..9f63d47 100644 --- a/methode2/splinelineblack/draw.php +++ b/methode2/splinelineblack/draw.php @@ -29,18 +29,6 @@ function DrawBlock($the_block, $vImage, $parametres) if (isset($parametres['background_RGB'])) $vBgRGB = $parametres['background_RGB']; // Une chance sur deux d'inverser entre fg et bg - if (rand(0,100) < 50) { - $fond = $vBgColor; - $couleur = $vFgColor; - $fondRGB = $vBgRGB; - $couleurRGB = $vFgRGB; - } else { - $fond = $vFgColor; - $couleur = $vBgColor; - $fondRGB = $vFgRGB; - $couleurRGB = $vBgRGB; - } - $fondRGB=[0,0,0]; $fond=imagecolorallocate($vImage,$fondRGB[0],$fondRGB[1],$fondRGB[2]); $couleurRGB=[240,147,43]; @@ -49,8 +37,8 @@ function DrawBlock($the_block, $vImage, $parametres) // Remplir le fond imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $fond); - // Dégradé de 192 couleurs entre la couleur de dessin et le blanc $vColor = array(); + // Dégradé de 192 couleurs entre la couleur de dessin et le blanc $nb_colors = 192; $hex_val = array( ColorGradient::rgb2hex($couleurRGB),