intermédiaire - no use
This commit is contained in:
409
methode/line/inc/draw.1.php
Normal file
409
methode/line/inc/draw.1.php
Normal file
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
|
||||
class topisto_spline2
|
||||
{
|
||||
|
||||
public static function DefaultDrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, $type=1)
|
||||
{
|
||||
topisto_spline2::DrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, 3.5, 1, $type);
|
||||
topisto_spline2::DrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, 5, 30, $type);
|
||||
}
|
||||
|
||||
//
|
||||
// modes
|
||||
// - 0 : une droite de couleur uniforme
|
||||
// - 1 : une droite en dégradé de couleur
|
||||
// - 2 : une spline en dégradé de couleur passant les valeurs du hash de la transaction
|
||||
// - 3 : la spline dessinée en 2 est atténuée à gauche et amplifiée à droite
|
||||
// - 3.5 : idem mode 3, mais avec de la transparence
|
||||
// - 4 : $iterations splines oscillants autour de la spline dessinée en 2
|
||||
// - 4.5 : les splines sont desssinées en transparence
|
||||
//
|
||||
public static function DrawBlock($the_block, $vImage, $parametres)
|
||||
{
|
||||
|
||||
return topisto_spline2::DrawLine($the_block, $vImage, $parametres);
|
||||
|
||||
$somme = 0;
|
||||
$min =-1;
|
||||
$max = 0;
|
||||
$type = 1;
|
||||
$local_iterations = 200;
|
||||
|
||||
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['methode'])) $mode = $parametres['methode'];
|
||||
if (isset($parametres['type'])) $type = $parametres['type'];
|
||||
if (isset($parametres['iterations'])) $local_iterations = $parametres['iterations'];
|
||||
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'];
|
||||
|
||||
$local_iterations = 150;
|
||||
|
||||
$data = blockchain::getTransactionData($the_block, $type);
|
||||
$n_data = count($data);
|
||||
|
||||
$fond = $vBgColor;
|
||||
if (rand(0,100) < 50) $fond = $vFgColor;
|
||||
imagefilledrectangle($vImage, $x, $y, $x+$width-1, $y+$height-1, $fond);
|
||||
|
||||
// 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;
|
||||
|
||||
// ---
|
||||
// --- On se limite à 40 000 traits
|
||||
// --- Pour des questions de performance
|
||||
// ---
|
||||
while(($n_data * $local_iterations)>40000) $local_iterations--;
|
||||
|
||||
$vColor = array();
|
||||
|
||||
// Gestion de la transparence
|
||||
$alpha = 125;
|
||||
if ($mode < 4.5) $alpha = 0;
|
||||
if ($mode == 3.5) $alpha = 100;
|
||||
|
||||
// On choisit des couleurs au hasard
|
||||
$hex_val = array(
|
||||
ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)]),
|
||||
ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)]),
|
||||
ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)])
|
||||
);
|
||||
// Dégradé de couleurs entre bgcolor et blanc
|
||||
$hex_val = array(
|
||||
ColorGradient::rgb2hex([0,0,0]),
|
||||
ColorGradient::rgb2hex($vFgRGB)
|
||||
);
|
||||
|
||||
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], TX_HASH_LEN);
|
||||
for($i=0;$i<TX_HASH_LEN;$i++)
|
||||
{
|
||||
$rgbval = ColorGradient::hex2rgb($gradient[$i]);
|
||||
$vColor[$i] = new ColorGradient();
|
||||
$vColor[$i]->pct = ($i*1.0) / TX_HASH_LEN;
|
||||
$vColor[$i]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha);
|
||||
}
|
||||
|
||||
//////////
|
||||
$oCurve = new CubicSplines();
|
||||
|
||||
$marge_x = 10;
|
||||
$marge_y = 20;
|
||||
|
||||
$coef = ($height - (2*$marge_y)) / $somme;
|
||||
$dx = $width;
|
||||
if ($mode > 0) $dx = round($dx / (TX_HASH_LEN+1));
|
||||
|
||||
$limite_x = $x + $width - $marge_x;
|
||||
|
||||
$h0 = 0;
|
||||
$hauteur = $y + $marge_y;
|
||||
$special_draw = (count($data) == 1);
|
||||
|
||||
foreach($data as $transaction)
|
||||
{
|
||||
//
|
||||
// La nouvelle hauteur : cumule des montants de transaction
|
||||
//
|
||||
$hauteur += $coef * $transaction['value'];
|
||||
|
||||
//
|
||||
// Cas des blocks qui n'ont qu'une seule transaction
|
||||
//
|
||||
if ($special_draw) $hauteur = $y + ($height / 2);
|
||||
|
||||
//
|
||||
// Ne pas tracer 2 lignes à la même hauteur
|
||||
//
|
||||
if ((floor($hauteur)-$h0)<2) continue;
|
||||
$h0 = floor($hauteur);
|
||||
|
||||
//
|
||||
// On va faire des itérations sur la transaction courante.
|
||||
// A chaque itération, on va s'appuyer sur le hash de la transaction
|
||||
// mais en introduisant du bruit.
|
||||
// On va donc statistiquement tracer une courbe représentant le hash
|
||||
//
|
||||
for($j=0;$j<$local_iterations;$j++)
|
||||
{
|
||||
//
|
||||
// On recommence en début de ligne
|
||||
//
|
||||
$x0 = $x + $marge_x;
|
||||
|
||||
//
|
||||
// La première partie est une ligne droite
|
||||
//
|
||||
imageline($vImage, $x0, $h0, $x0+$dx, $h0, $vColor[0]->color);
|
||||
$x0 += $dx;
|
||||
|
||||
//
|
||||
// Le mode 0 consiste à tracer une droite de couleur uniforme
|
||||
//
|
||||
if (($mode == 0)||($x0 >= $limite_x)) continue;
|
||||
|
||||
$aCoords = array();
|
||||
$facteur = 1;
|
||||
|
||||
if ($mode > 2) $facteur = 0.04;
|
||||
|
||||
//
|
||||
// On découpe la ligne en fonction du nombre de DIGIT
|
||||
// dans le hash des transactions
|
||||
//
|
||||
$aCoords[$x0] = $h0;
|
||||
for ($i = 0; $i < (TX_HASH_LEN-1); $i++)
|
||||
{
|
||||
$y0 = $h0;
|
||||
if ($mode > 1)
|
||||
{
|
||||
$y0 += (hexdec($transaction['hash'][$i]) - 8) * $facteur;
|
||||
$valeur = rand(-16, 16) * $facteur;
|
||||
if ($mode > 2) $facteur += 0.02;
|
||||
if ($mode > 3) $y0 += $valeur;
|
||||
}
|
||||
$x0 += $dx;
|
||||
$aCoords[$x0] = $y0;
|
||||
}
|
||||
if ($oCurve)
|
||||
{
|
||||
$oCurve->setInitCoords($aCoords);
|
||||
$r = $oCurve->processCoords();
|
||||
if ($r)
|
||||
{
|
||||
$curveGraph = new Plot($r);
|
||||
$curveGraph->drawLine($vImage, $vColor, $x0, $limite_x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function DrawLine($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;
|
||||
|
||||
// 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'];
|
||||
|
||||
// Une chance sur deux d'inverser entre fg et bg
|
||||
if (rand(0,100) < 50) {
|
||||
$fond = $vBgColor;
|
||||
$couleur = $vFgColor;
|
||||
} else {
|
||||
$fond = $vFgColor;
|
||||
$couleur = $vBgColor;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
$coef = ($height - (2*$marge_y)) / $somme;
|
||||
$dx = $width - (2*$marge_x);
|
||||
$limite_x = $x + $dx;
|
||||
|
||||
$h0 = 0;
|
||||
$hauteur = $y + $marge_y;
|
||||
$special_draw = (count($data) == 1);
|
||||
|
||||
foreach($data as $transaction)
|
||||
{
|
||||
//
|
||||
// La nouvelle hauteur : cumule des montants de transaction
|
||||
//
|
||||
$hauteur += $coef * $transaction['value'];
|
||||
|
||||
//
|
||||
// Cas des blocks qui n'ont qu'une seule transaction
|
||||
// On se cale au milieu
|
||||
//
|
||||
if ($special_draw) $hauteur = $y + ($height / 2);
|
||||
|
||||
//
|
||||
// Ne pas tracer 2 lignes à la même hauteur
|
||||
// => c'est possible du fait de l'arrondi
|
||||
// si la transaction a un montant faible
|
||||
//
|
||||
if ((floor($hauteur)-$h0)<2) continue;
|
||||
$h0 = floor($hauteur);
|
||||
|
||||
//
|
||||
// On recommence en début de ligne
|
||||
//
|
||||
$x0 = $x + $marge_x;
|
||||
|
||||
//
|
||||
// La première partie est une ligne droite
|
||||
//
|
||||
imageline($vImage, $x0, $h0, $x0+$dx, $h0, $couleur);
|
||||
}
|
||||
}
|
||||
|
||||
public static function DrawGradientLine($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;
|
||||
|
||||
// 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'];
|
||||
|
||||
// Récup des données
|
||||
$data = blockchain::getTransactionData($the_block, $type);
|
||||
$n_data = count($data);
|
||||
|
||||
|
||||
$vColor = array();
|
||||
|
||||
// Gestion de la transparence
|
||||
$alpha = 125;
|
||||
if ($mode < 4.5) $alpha = 0;
|
||||
if ($mode == 3.5) $alpha = 100;
|
||||
|
||||
// On choisit des couleurs au hasard
|
||||
$hex_val = array(
|
||||
ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)]),
|
||||
ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)]),
|
||||
ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)])
|
||||
);
|
||||
// Dégradé de couleurs entre bgcolor et blanc
|
||||
$hex_val = array(
|
||||
ColorGradient::rgb2hex([0,0,0]),
|
||||
ColorGradient::rgb2hex($vFgRGB)
|
||||
);
|
||||
|
||||
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], TX_HASH_LEN);
|
||||
for($i=0;$i<TX_HASH_LEN;$i++)
|
||||
{
|
||||
$rgbval = ColorGradient::hex2rgb($gradient[$i]);
|
||||
$vColor[$i] = new ColorGradient();
|
||||
$vColor[$i]->pct = ($i*1.0) / TX_HASH_LEN;
|
||||
$vColor[$i]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha);
|
||||
}
|
||||
|
||||
// Une chance sur deux d'inverser entre fg et bg
|
||||
if (rand(0,100) < 50) {
|
||||
$fond = $vBgColor;
|
||||
$couleur = $vFgColor;
|
||||
} else {
|
||||
$fond = $vFgColor;
|
||||
$couleur = $vBgColor;
|
||||
}
|
||||
|
||||
// Remplir le fond
|
||||
imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $fond);
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
$coef = ($height - (2*$marge_y)) / $somme;
|
||||
$dx = $width - (2*$marge_x);
|
||||
$limite_x = $x + $dx;
|
||||
|
||||
$h0 = 0;
|
||||
$hauteur = $y + $marge_y;
|
||||
$special_draw = (count($data) == 1);
|
||||
|
||||
foreach($data as $transaction)
|
||||
{
|
||||
//
|
||||
// La nouvelle hauteur : cumule des montants de transaction
|
||||
//
|
||||
$hauteur += $coef * $transaction['value'];
|
||||
|
||||
//
|
||||
// Cas des blocks qui n'ont qu'une seule transaction
|
||||
// On se cale au milieu
|
||||
//
|
||||
if ($special_draw) $hauteur = $y + ($height / 2);
|
||||
|
||||
//
|
||||
// Ne pas tracer 2 lignes à la même hauteur
|
||||
// => c'est possible du fait de l'arrondi
|
||||
// si la transaction a un montant faible
|
||||
//
|
||||
if ((floor($hauteur)-$h0)<2) continue;
|
||||
$h0 = floor($hauteur);
|
||||
|
||||
//
|
||||
// On recommence en début de ligne
|
||||
//
|
||||
$x0 = $x + $marge_x;
|
||||
|
||||
//
|
||||
// La première partie est une ligne droite
|
||||
//
|
||||
imageline($vImage, $x0, $h0, $x0+$dx, $h0, $couleur);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
98
methode/line/inc/draw.php
Normal file
98
methode/line/inc/draw.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
class topisto_line
|
||||
{
|
||||
public static 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;
|
||||
|
||||
// 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'];
|
||||
|
||||
// Une chance sur deux d'inverser entre fg et bg
|
||||
if (rand(0,100) < 50) {
|
||||
$fond = $vBgColor;
|
||||
$couleur = $vFgColor;
|
||||
} else {
|
||||
$fond = $vFgColor;
|
||||
$couleur = $vBgColor;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
$coef = ($height - (2*$marge_y)) / $somme;
|
||||
$dx = $width - (2*$marge_x);
|
||||
$limite_x = $x + $dx;
|
||||
|
||||
$h0 = 0;
|
||||
$hauteur = $y + $marge_y;
|
||||
$special_draw = (count($data) == 1);
|
||||
|
||||
foreach($data as $transaction)
|
||||
{
|
||||
//
|
||||
// La nouvelle hauteur : cumule des montants de transaction
|
||||
//
|
||||
$hauteur += $coef * $transaction['value'];
|
||||
|
||||
//
|
||||
// Cas des blocks qui n'ont qu'une seule transaction
|
||||
// On se cale au milieu
|
||||
//
|
||||
if ($special_draw) $hauteur = $y + ($height / 2);
|
||||
|
||||
//
|
||||
// Ne pas tracer 2 lignes à la même hauteur
|
||||
// => c'est possible du fait de l'arrondi
|
||||
// si la transaction a un montant faible
|
||||
//
|
||||
if ((floor($hauteur)-$h0)<2) continue;
|
||||
$h0 = floor($hauteur);
|
||||
|
||||
//
|
||||
// On recommence en début de ligne
|
||||
//
|
||||
$x0 = $x + $marge_x;
|
||||
|
||||
//
|
||||
// La première partie est une ligne droite
|
||||
//
|
||||
imageline($vImage, $x0, $h0, $x0+$dx, $h0, $couleur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user