You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

83 rivejä
2.6 KiB

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