Parcourir la source

gestion des cercles et de leurs couleurs

master
MEUNIER Thibaud il y a 7 ans
Parent
révision
09d51c6bba
9 fichiers modifiés avec 514 ajouts et 14 suppressions
  1. +0
    -0
      1
  2. +25
    -0
      global/inc/colors.php
  3. +73
    -0
      methode2/circle/draw.php
  4. +81
    -0
      methode2/circle_line/draw.php
  5. +112
    -0
      methode2/circle_spline/draw.php
  6. +83
    -0
      methode2/circles/draw.php
  7. +138
    -0
      methode2/circles_spline/draw.php
  8. +1
    -1
      methode2/robot.sh
  9. +1
    -13
      methode2/splinelineblack/draw.php

+ 0
- 0
1 Voir le fichier


+ 25
- 0
global/inc/colors.php Voir le fichier

@ -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;
}
?>

+ 73
- 0
methode2/circle/draw.php Voir le fichier

@ -0,0 +1,73 @@
<?php
function DrawBlock($the_block, $vImage, $parametres)
{
// valeurs par défaut
$type = 1;
// Ces variables vont permettre de caler les lignes
// dans la zone de dessin en se laissant des marges
// en haut et en bas
$somme = 0;
$min =-1;
$max = 0;
$marge_x = 10;
$marge_y = 10;
$facteur_max = 2.5;
// Détermine si on dessine les tx, les fees ou la récompense
if (isset($parametres['type'])) $type = $parametres['type'];
// Paramètres de dessin
if (isset($parametres['x'])) $x = $parametres['x'];
if (isset($parametres['y'])) $y = $parametres['y'];
if (isset($parametres['width'])) $width = $parametres['width'];
if (isset($parametres['height'])) $height = $parametres['height'];
if (isset($parametres['font_color'])) $vFgColor = $parametres['font_color'];
if (isset($parametres['background_color'])) $vBgColor = $parametres['background_color'];
if (isset($parametres['font_RGB'])) $vFgRGB = $parametres['font_RGB'];
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;
}
// 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 360 couleurs entre la couleur de dessin et le blanc
$vColor = getGDcolorGradientArray($vImage, 360, $couleurRGB, $fondRGB, $alpha);
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
$xc = $x + ($width / 2);
$yc = $y + ($height / 2);
foreach($data as $transaction)
{
for($i=0;$i<360;$i++)
{
$valeur = hexdec($transaction['hash'][$i%TX_HASH_LEN]);
if ($valeur != 0) $valeur += $valeur - 8;
$r = ($width/4)+($valeur*3);
$xi = $xc + $r*cos(deg2rad($i));
$yi = $yc + $r*sin(deg2rad($i));
imagesetpixel($vImage, $xi, $yi, $vColor[$i]->color);
}
}
}
?>

+ 81
- 0
methode2/circle_line/draw.php Voir le fichier

@ -0,0 +1,81 @@
<?php
function DrawBlock($the_block, $vImage, $parametres)
{
// valeurs par défaut
$type = 1;
// Ces variables vont permettre de caler les lignes
// dans la zone de dessin en se laissant des marges
// en haut et en bas
$somme = 0;
$min =-1;
$max = 0;
$marge_x = 10;
$marge_y = 10;
$facteur_max = 2.5;
// Détermine si on dessine les tx, les fees ou la récompense
if (isset($parametres['type'])) $type = $parametres['type'];
// Paramètres de dessin
if (isset($parametres['x'])) $x = $parametres['x'];
if (isset($parametres['y'])) $y = $parametres['y'];
if (isset($parametres['width'])) $width = $parametres['width'];
if (isset($parametres['height'])) $height = $parametres['height'];
if (isset($parametres['font_color'])) $vFgColor = $parametres['font_color'];
if (isset($parametres['background_color'])) $vBgColor = $parametres['background_color'];
if (isset($parametres['font_RGB'])) $vFgRGB = $parametres['font_RGB'];
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;
}
// 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 360 couleurs entre la couleur de dessin et le blanc
$vColor = getGDcolorGradientArray($vImage, 360, $couleurRGB, $fondRGB, $alpha);
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
$xc = $x + ($width / 2);
$yc = $y + ($height / 2);
foreach($data as $transaction)
{
$r0 = $width/4;
$x0 = $xc + $r0*cos(deg2rad(0));
$y0 = $yc + $r0*sin(deg2rad(0));
for($i=0;$i<TX_HASH_LEN;$i++)
{
$valeur = hexdec($transaction['hash'][$i]) - 8;
$r = $r0+($valeur*rand(0,3));
$xi = floor($xc + $r*cos(deg2rad($i*(360/TX_HASH_LEN))));
$yi = floor($yc + $r*sin(deg2rad($i*(360/TX_HASH_LEN))));
imageline($vImage, $x0, $y0, $xi, $yi, $vColor[$i]->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);
}
}
?>

+ 112
- 0
methode2/circle_spline/draw.php Voir le fichier

@ -0,0 +1,112 @@
<?php
function DrawBlock($the_block, $vImage, $parametres)
{
// valeurs par défaut
$type = 1;
// Ces variables vont permettre de caler les lignes
// dans la zone de dessin en se laissant des marges
// en haut et en bas
$somme = 0;
$min =-1;
$max = 0;
$marge_x = 10;
$marge_y = 10;
$facteur_max = 2.5;
// Détermine si on dessine les tx, les fees ou la récompense
if (isset($parametres['type'])) $type = $parametres['type'];
// Paramètres de dessin
if (isset($parametres['x'])) $x = $parametres['x'];
if (isset($parametres['y'])) $y = $parametres['y'];
if (isset($parametres['width'])) $width = $parametres['width'];
if (isset($parametres['height'])) $height = $parametres['height'];
if (isset($parametres['font_color'])) $vFgColor = $parametres['font_color'];
if (isset($parametres['background_color'])) $vBgColor = $parametres['background_color'];
if (isset($parametres['font_RGB'])) $vFgRGB = $parametres['font_RGB'];
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;
}
// Remplir le fond
imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $fond);
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
// Plus il y a de transactions plus la couleur de tracé sera transparente
$alpha = 120;
$nb = count($data);
if ($nb < 50) $alpha = 115;
if ($nb < 20) $alpha = 110;
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);
// Un calculateur de Spline
$oCurve = new CubicSplines();
$bornes = [[0,180],[180,360]];
$xc = $x + ($width / 2);
$yc = $y + ($height / 2);
$r0 = $width / 3;
$coef = 0.3;
foreach($data as $transaction)
{
// 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);
}
}
}
}
}
?>

+ 83
- 0
methode2/circles/draw.php Voir le fichier

@ -0,0 +1,83 @@
<?php
function DrawBlock($the_block, $vImage, $parametres)
{
// valeurs par défaut
$type = 1;
// Ces variables vont permettre de caler les lignes
// dans la zone de dessin en se laissant des marges
// en haut et en bas
$somme = 0;
$min =-1;
$max = 0;
$marge_x = 10;
$marge_y = 10;
$facteur_max = 2.5;
// Détermine si on dessine les tx, les fees ou la récompense
if (isset($parametres['type'])) $type = $parametres['type'];
// Paramètres de dessin
if (isset($parametres['x'])) $x = $parametres['x'];
if (isset($parametres['y'])) $y = $parametres['y'];
if (isset($parametres['width'])) $width = $parametres['width'];
if (isset($parametres['height'])) $height = $parametres['height'];
if (isset($parametres['font_color'])) $vFgColor = $parametres['font_color'];
if (isset($parametres['background_color'])) $vBgColor = $parametres['background_color'];
if (isset($parametres['font_RGB'])) $vFgRGB = $parametres['font_RGB'];
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;
}
// 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 360 couleurs entre la couleur de dessin et le blanc
$vColor = getGDcolorGradientArray($vImage, 360, $couleurRGB, $fondRGB, $alpha);
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
// Calcul des min max
foreach($data as $v)
{
if ($v['value'] > $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);
}
}
}
?>

+ 138
- 0
methode2/circles_spline/draw.php Voir le fichier

@ -0,0 +1,138 @@
<?php
function DrawBlock($the_block, $vImage, $parametres)
{
// valeurs par défaut
$type = 1;
// Ces variables vont permettre de caler les lignes
// dans la zone de dessin en se laissant des marges
// en haut et en bas
$somme = 0;
$min =-1;
$max = 0;
$marge_x = 10;
$marge_y = 10;
$facteur_max = 2.5;
// Détermine si on dessine les tx, les fees ou la récompense
if (isset($parametres['type'])) $type = $parametres['type'];
// Paramètres de dessin
if (isset($parametres['x'])) $x = $parametres['x'];
if (isset($parametres['y'])) $y = $parametres['y'];
if (isset($parametres['width'])) $width = $parametres['width'];
if (isset($parametres['height'])) $height = $parametres['height'];
if (isset($parametres['font_color'])) $vFgColor = $parametres['font_color'];
if (isset($parametres['background_color'])) $vBgColor = $parametres['background_color'];
if (isset($parametres['font_RGB'])) $vFgRGB = $parametres['font_RGB'];
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;
}
// Remplir le fond
imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $fond);
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
// Calcul des min max
foreach($data as $v)
{
if ($v['value'] > $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);
}
}
}
}
}
?>

+ 1
- 1
methode2/robot.sh Voir le fichier

@ -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

+ 1
- 13
methode2/splinelineblack/draw.php Voir le fichier

@ -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),

Chargement…
Annuler
Enregistrer