diff --git a/blockchain/inc/block.php b/blockchain/inc/block.php index a234112..f900e26 100644 --- a/blockchain/inc/block.php +++ b/blockchain/inc/block.php @@ -336,6 +336,8 @@ class blockchain imagefilledpolygon($vImage, $points2, (count($points2)/2), $fond); imagepolygon($vImage, $points2, (count($points2)/2), $black); + imagefilledrectangle($vImage, 0, $hauteur, $w, $h-$hauteur, $black); + // Rajout des textes $the_name = blockchain::hash2SpecialName($the_block->hash); if ($the_name == $the_block->hash) $the_name = date('Ymd H:i:s', $the_block->time); diff --git a/global/inc/colors.php b/global/inc/colors.php new file mode 100644 index 0000000..c1b7bc6 --- /dev/null +++ b/global/inc/colors.php @@ -0,0 +1,123 @@ += 2) { // for at least 3 colors + $GradientSizeRed = (hexdec(substr($endcol, 0, 2)) - $RedOrigin) / $graduations; //Graduation Size Red + $GradientSizeGrn = (hexdec(substr($endcol, 2, 2)) - $GrnOrigin) / $graduations; + $GradientSizeBlu = (hexdec(substr($endcol, 4, 2)) - $BluOrigin) / $graduations; + for ($i = 0; $i <= $graduations; $i++) { + $RetVal[$i] = strtoupper("#" . str_pad(dechex($RedOrigin + ($GradientSizeRed * $i)), 2, '0', STR_PAD_LEFT) . + str_pad(dechex($GrnOrigin + ($GradientSizeGrn * $i)), 2, '0', STR_PAD_LEFT) . + str_pad(dechex($BluOrigin + ($GradientSizeBlu * $i)), 2, '0', STR_PAD_LEFT)); + } + } elseif ($graduations == 1) { // exactlly 2 colors + $RetVal[] = $from_color; + $RetVal[] = $to_color; + } else { // one color + $RetVal[] = $from_color; + } + return $RetVal; + } + + public static function hex2rgb($hex) + { + return sscanf($hex, "#%02x%02x%02x"); + } + + // --- + // --- Local fonctions + // --- + public static function rgb2hex($rgb) + { + $hex = "#"; + $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT); + $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT); + $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT); + + return $hex; // returns the hex value including the number sign (#) + } +} + +?> diff --git a/global/inc/config.php b/global/inc/config.php index 9b883b9..73c0518 100644 --- a/global/inc/config.php +++ b/global/inc/config.php @@ -20,6 +20,8 @@ define('SOLD_PATH', TOPISTO_PATH.'/sold'); define('OFFLINE_PATH', RESS_PATH.'/offline'); +define('TX_HASH_LEN',64); + define('GRAPH_WIDTH', 400); define('GRAPH_HEIGHT', 300); diff --git a/global/inc/cubic.php b/global/inc/cubic.php new file mode 100644 index 0000000..04f810a --- /dev/null +++ b/global/inc/cubic.php @@ -0,0 +1,153 @@ +aCoords = &$aCoords; + } + + public function drawLine($vImage, $vColor, $iPosX = 0, $imaxX = false) + { + $maxX = $imaxX; + if ($imaxX === false) $maxX = imagesx($vImage); + + reset($this->aCoords); + list($iPrevX, $iPrevY) = each($this->aCoords); + + while (list ($x, $y) = each($this->aCoords)) + { + $laCouleur = null; + if (!is_array($vColor)) $laCouleur = $vColor; + else + { + $s = count($vColor) - 1; + $laCouleur = $vColor[$s]->color; + $pct = $x / $maxX; + while(($s>0)&&($pct < $vColor[$s]->pct)) + { + $s -= 1; + $laCouleur = $vColor[$s]->color; + } + } + imageline($vImage, round($iPrevX), round($iPrevY), round($x), round($y), $laCouleur); + $iPrevX = $x; + $iPrevY = $y; + } + } + + public function drawDots($vImage, $vColor, $iPosX = 0, $iPosY = false, $iDotSize = 1) { + if ($iPosY === false) + $iPosY = imagesy($vImage); + $vBorderColor = imagecolorallocate($vImage, 0, 0, 0); + foreach ($this->aCoords as $x => $y) { + imagefilledellipse($vImage, $iPosX + round($x), $iPosY - round($y), $iDotSize, $iDotSize, $vColor); + imageellipse($vImage, $iPosX + round($x), $iPosY - round($y), $iDotSize, $iDotSize, $vBorderColor); + } + } + + public function drawAxis($vImage, $vColor, $iPosX = 0, $iPosY = false) { + if ($iPosY === false) $iPosY = imagesy($vImage); + $vImageWidth = imagesx($vImage); + imageline($vImage, $iPosX, $iPosY, $iPosX, 0, $vColor); + imageline($vImage, $iPosX, $iPosY, $vImageWidth, $iPosY, $vColor); + imagefilledpolygon($vImage, array($iPosX, 0, $iPosX - 3, 5, $iPosX + 3, 5), 3, $vColor); + imagefilledpolygon($vImage, array($vImageWidth, $iPosY, $vImageWidth - 5, $iPosY - 3, $vImageWidth - 5, $iPosY + 3), 3, $vColor); + } +} + +class CubicSplines +{ + protected $aCoords; + protected $aCrdX; + protected $aCrdY; + protected $aSplines = array(); + protected $iMinX; + protected $iMaxX; + protected $iStep; + protected function prepareCoords(&$aCoords, $iStep, $iMinX = -1, $iMaxX = -1) { + $this->aCrdX = array(); + $this->aCrdY = array(); + $this->aCoords = array(); + ksort($aCoords); + foreach ($aCoords as $x => $y) { + $this->aCrdX[] = $x; + $this->aCrdY[] = $y; + } + $this->iMinX = $iMinX; + $this->iMaxX = $iMaxX; + if ($this->iMinX == -1) + $this->iMinX = min($this->aCrdX); + if ($this->iMaxX == -1) + $this->iMaxX = max($this->aCrdX); + $this->iStep = $iStep; + } + public function setInitCoords(&$aCoords, $iStep = 1, $iMinX = -1, $iMaxX = -1) { + $this->aSplines = array(); + if (count($aCoords) < 4) { + return false; + } + $this->prepareCoords($aCoords, $iStep, $iMinX, $iMaxX); + $this->buildSpline($this->aCrdX, $this->aCrdY, count($this->aCrdX)); + } + public function processCoords() { + for ($x = $this->iMinX; $x <= $this->iMaxX; $x += $this->iStep) { + $this->aCoords[$x] = $this->funcInterp($x); + } + return $this->aCoords; + } + private function buildSpline($x, $y, $n) { + for ($i = 0; $i < $n; ++$i) { + $this->aSplines[$i]['x'] = $x[$i]; + $this->aSplines[$i]['a'] = $y[$i]; + } + $this->aSplines[0]['c'] = $this->aSplines[$n - 1]['c'] = 0; + $alpha[0] = $beta[0] = 0; + for ($i = 1; $i < $n - 1; ++$i) { + $h_i = $x[$i] - $x[$i - 1]; + $h_i1 = $x[$i + 1] - $x[$i]; + $A = $h_i; + $C = 2.0 * ($h_i + $h_i1); + $B = $h_i1; + $F = 6.0 * (($y[$i + 1] - $y[$i]) / $h_i1 - ($y[$i] - $y[$i - 1]) / $h_i); + $z = ($A * $alpha[$i - 1] + $C); + $alpha[$i] = - $B / $z; + $beta[$i] = ($F - $A * $beta[$i - 1]) / $z; + } + for ($i = $n - 2; $i > 0; --$i) { + $this->aSplines[$i]['c'] = $alpha[$i] * $this->aSplines[$i + 1]['c'] + $beta[$i]; + } + for ($i = $n - 1; $i > 0; --$i) { + $h_i = $x[$i] - $x[$i - 1]; + $this->aSplines[$i]['d'] = ($this->aSplines[$i]['c'] - $this->aSplines[$i - 1]['c']) / $h_i; + $this->aSplines[$i]['b'] = $h_i * (2.0 * $this->aSplines[$i]['c'] + $this->aSplines[$i - 1]['c']) / 6.0 + ($y[$i] - $y[$i - 1]) / $h_i; + } + } + private function funcInterp($x) { + $n = count($this->aSplines); + if ($x <= $this->aSplines[0]['x']) { + $s = $this->aSplines[1]; + } else { + if ($x >= $this->aSplines[$n - 1]['x']) { + $s = $this->aSplines[$n - 1]; + } else { + $i = 0; + $j = $n - 1; + while ($i + 1 < $j) { + $k = $i + ($j - $i) / 2; + if ($x <= $this->aSplines[$k]['x']) { + $j = $k; + } else { + $i = $k; + } + } + $s = $this->aSplines[$j]; + } + } + $dx = ($x - $s['x']); + return $s['a'] + ($s['b'] + ($s['c'] / 2.0 + $s['d'] * $dx / 6.0) * $dx) * $dx; + } +} + +?> diff --git a/methode/line/inc/draw.1.php b/methode/line/inc/draw.1.php new file mode 100644 index 0000000..61e3448 --- /dev/null +++ b/methode/line/inc/draw.1.php @@ -0,0 +1,409 @@ + $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;$ipct = ($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;$ipct = ($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); + } + } + +} + +?> diff --git a/methode/line/inc/draw.php b/methode/line/inc/draw.php new file mode 100644 index 0000000..bc437f6 --- /dev/null +++ b/methode/line/inc/draw.php @@ -0,0 +1,98 @@ + $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); + } + } +} + +?> diff --git a/methode/line/robot.php b/methode/line/robot.php new file mode 100644 index 0000000..0159d7b --- /dev/null +++ b/methode/line/robot.php @@ -0,0 +1,86 @@ +hash); +if ($the_name == $the_block->hash) $the_name =''; + +$bandeau = 50; +$marge = 25; +$text_border = 20; +$width = GRAPH_WIDTH; +$height = GRAPH_HEIGHT; + +// Pour que l'image simple ait les proportions que l'image full +$width = $marge + ($width*2) + (2*$text_border); +$height = $marge + ($height*2); + +$img_w = $width; +$img_h = $height+(2*$bandeau); + +// création d'une image plus haute pour inclure bandeaux haut et bas +$img = imagecreatetruecolor($img_w, $img_h); + +$type=2; +if (count($the_block->tx)==1) $type = 4; + +$paramHeader = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); + +$parametres = []; +$parametres['x'] = 0; +$parametres['y'] = $bandeau; +$parametres['width'] = $width; +$parametres['height'] = $height; +$parametres['methode'] = 5; +$parametres['type'] = $type; +$parametres['iterations'] = 200; +$parametres['transparent_color'] = $paramHeader[0]; +$parametres['background_color'] = $paramHeader[1]; +$parametres['font_color'] = $paramHeader[2]; +$parametres['fontname'] = $paramHeader[3]; +$parametres['font_RGB'] = $paramHeader[4]; +$parametres['background_RGB'] = $paramHeader[5]; + +topisto_line::DrawBlock($the_block, $img, $parametres); + +imagepng($img, DATA_PATH.'/last/'.$the_block->hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/line/robot.sh b/methode/line/robot.sh new file mode 100755 index 0000000..5b134aa --- /dev/null +++ b/methode/line/robot.sh @@ -0,0 +1,36 @@ +#!/bin/bash +METHODE=line +flag=$TMP_PATH/${METHODE}_bot.flag +date=`date +%Y%m%d0000` + +if [ -f $flag ]; +then + echo "$METHODE_bot is already running !" + exit 0 +fi + +touch $flag + +cd $APPS_PATH/methode/$METHODE +for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` +do + if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ] + then + php robot.php $BLOCK $(( RANDOM % 6)) + fi + + BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` + if [ "$BNAME" == "LAST" ] + then + touch $DATA_PATH/$METHODE/$BLOCK.png + else + touch -t $date $DATA_PATH/$METHODE/$BLOCK.png + fi + + rm -f $DATA_PATH/hasard/$BLOCK.png + ln $DATA_PATH/last/$BLOCK.png $DATA_PATH/$METHODE/$BLOCK.png + ln $DATA_PATH/last/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png + +done + +rm -f $flag diff --git a/methode/spline2/inc/draw.php b/methode/spline2/inc/draw.php new file mode 100644 index 0000000..61e3448 --- /dev/null +++ b/methode/spline2/inc/draw.php @@ -0,0 +1,409 @@ + $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;$ipct = ($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;$ipct = ($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); + } + } + +} + +?> diff --git a/methode/spline2/robot.php b/methode/spline2/robot.php new file mode 100644 index 0000000..b8e9d5e --- /dev/null +++ b/methode/spline2/robot.php @@ -0,0 +1,86 @@ +hash); +if ($the_name == $the_block->hash) $the_name =''; + +$bandeau = 50; +$marge = 25; +$text_border = 20; +$width = GRAPH_WIDTH; +$height = GRAPH_HEIGHT; + +// Pour que l'image simple ait les proportions que l'image full +$width = $marge + ($width*2) + (2*$text_border); +$height = $marge + ($height*2); + +$img_w = $width; +$img_h = $height+(2*$bandeau); + +// création d'une image plus haute pour inclure bandeaux haut et bas +$img = imagecreatetruecolor($img_w, $img_h); + +$type=2; +if (count($the_block->tx)==1) $type = 4; + +$paramHeader = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); + +$parametres = []; +$parametres['x'] = 0; +$parametres['y'] = $bandeau; +$parametres['width'] = $width; +$parametres['height'] = $height; +$parametres['methode'] = 5; +$parametres['type'] = $type; +$parametres['iterations'] = 200; +$parametres['transparent_color'] = $paramHeader[0]; +$parametres['background_color'] = $paramHeader[1]; +$parametres['font_color'] = $paramHeader[2]; +$parametres['fontname'] = $paramHeader[3]; +$parametres['font_RGB'] = $paramHeader[4]; +$parametres['background_RGB'] = $paramHeader[5]; + +topisto_spline2::DrawBlock($the_block, $img, $parametres); + +imagepng($img, DATA_PATH.'/last/'.$the_block->hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/spline2/robot.sh b/methode/spline2/robot.sh new file mode 100755 index 0000000..72996cd --- /dev/null +++ b/methode/spline2/robot.sh @@ -0,0 +1,36 @@ +#!/bin/bash +METHODE=spline2 +flag=$TMP_PATH/${METHODE}_bot.flag +date=`date +%Y%m%d0000` + +if [ -f $flag ]; +then + echo "$METHODE_bot is already running !" + exit 0 +fi + +touch $flag + +cd $APPS_PATH/methode/$METHODE +for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` +do + if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ] + then + php robot.php $BLOCK $(( RANDOM % 6)) + fi + + BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` + if [ "$BNAME" == "LAST" ] + then + touch $DATA_PATH/$METHODE/$BLOCK.png + else + touch -t $date $DATA_PATH/$METHODE/$BLOCK.png + fi + + rm -f $DATA_PATH/hasard/$BLOCK.png + ln $DATA_PATH/last/$BLOCK.png $DATA_PATH/$METHODE/$BLOCK.png + ln $DATA_PATH/last/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png + +done + +rm -f $flag