diff --git a/blockchain/inc/block.php b/blockchain/inc/block.php index a3026ac..f24e9e2 100644 --- a/blockchain/inc/block.php +++ b/blockchain/inc/block.php @@ -586,7 +586,7 @@ class blockchain ]; $color = $couleur; - if (($color == -1) || ($color > (count($color_tab)-1))) $color = rand(0,count($color_tab)-1); + if (($color == -1) || ($color > (count($color_tab)-1))) $color = $the_block->nonce % count($color_tab); // Rajout des HASHES $white = imagecolorallocate($vImage, 254, 254, 254); diff --git a/methode2.tgz b/methode2.tgz new file mode 100644 index 0000000..38bb681 Binary files /dev/null and b/methode2.tgz differ diff --git a/methode2/circle/draw.php b/methode2/circle/draw.php index 9fd205b..ea6f3de 100644 --- a/methode2/circle/draw.php +++ b/methode2/circle/draw.php @@ -29,35 +29,22 @@ function DrawBlock($the_block, $vImage, $parametres) 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); + imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $vFgColor); // Dégradé de 360 couleurs entre la couleur de dessin et le blanc - $vColor = getGDcolorGradientArray($vImage, 360, $couleurRGB, $fondRGB, $alpha); + $nbColor = 360; + $vColor = getGDcolorGradientArray($vImage, $nbColor, $vBgRGB, $vFgRGB, $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++) + for($i=0;$i<$nbColor;$i++) { $valeur = hexdec($transaction['hash'][$i%TX_HASH_LEN]); if ($valeur != 0) $valeur += $valeur - 8; diff --git a/methode2/circle_line/draw.php b/methode2/circle_line/draw.php index b165e19..0917dba 100644 --- a/methode2/circle_line/draw.php +++ b/methode2/circle_line/draw.php @@ -29,24 +29,11 @@ function DrawBlock($the_block, $vImage, $parametres) 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); + imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $vFgColor); // Dégradé de 360 couleurs entre la couleur de dessin et le blanc - $vColor = getGDcolorGradientArray($vImage, 360, $couleurRGB, $fondRGB, $alpha); + $vColor = getGDcolorGradientArray($vImage, 360, $vBgRGB, $vBgRGB, $alpha); // Récup des données $data = blockchain::getTransactionData($the_block, $type); @@ -63,7 +50,8 @@ function DrawBlock($the_block, $vImage, $parametres) for($i=0;$i 5) $coef = 0.3; if ($c > 7) $coef = 0.8; if ($c > 9) $coef = 1.2; diff --git a/methode2/circles/draw.php b/methode2/circles/draw.php index b21e90a..bacb50f 100644 --- a/methode2/circles/draw.php +++ b/methode2/circles/draw.php @@ -29,24 +29,11 @@ function DrawBlock($the_block, $vImage, $parametres) 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); + imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $vFgColor); // Dégradé de 360 couleurs entre la couleur de dessin et le blanc - $vColor = getGDcolorGradientArray($vImage, 360, $couleurRGB, $fondRGB, $alpha); + $vColor = getGDcolorGradientArray($vImage, 360, $vBgRGB, $vFgRGB, $alpha); // Récup des données $data = blockchain::getTransactionData($the_block, $type); diff --git a/methode2/circles_spline/draw.php b/methode2/circles_spline/draw.php index f31ced6..613056b 100644 --- a/methode2/circles_spline/draw.php +++ b/methode2/circles_spline/draw.php @@ -28,21 +28,8 @@ function DrawBlock($the_block, $vImage, $parametres) 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); + imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $vFgColor); // Récup des données $data = blockchain::getTransactionData($the_block, $type); @@ -66,7 +53,7 @@ function DrawBlock($the_block, $vImage, $parametres) 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); + $vColor = getGDcolorGradientArray($vImage, 360, $vBgRGB, $vFgRGB, $alpha); // Le rayon du cercle dépend du montant de la transaction //$r0 = $width / 3; @@ -97,7 +84,7 @@ function DrawBlock($the_block, $vImage, $parametres) // Un coef aléatoire $coef = 0.1; - $c = rand(0,10); + $c = $transaction['value']%10; if ($c > 5) $coef = 0.3; if ($c > 7) $coef = 0.8; if ($c > 9) $coef = 1.2; diff --git a/methode2/mondrian/draw.php b/methode2/mondrian/draw.php index 4aac6d4..e902206 100644 --- a/methode2/mondrian/draw.php +++ b/methode2/mondrian/draw.php @@ -53,7 +53,7 @@ function DrawBlock($the_block, $vImage, $parametres) //if (($x2 - $x1) < ($width*0.015)) break; //if (($y2 - $y1) < ($height*0.015)) break; - $factor=rand(0,100); + $factor=$the_block->nonce % 100; // Je triche: les petits rectangle sont blancs if (($x2 - $x1) < 6) $factor=90; if (($y2 - $y1) < 6) $factor=90; diff --git a/methode2/peigne/draw.php b/methode2/peigne/draw.php index c9d16c2..b086c1c 100644 --- a/methode2/peigne/draw.php +++ b/methode2/peigne/draw.php @@ -28,28 +28,15 @@ function DrawBlock($the_block, $vImage, $parametres) 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); + imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $vFgColor); // Dégradé de 256 couleurs entre la couleur de fond et la couleur de dessin $nb_colors = 256; $vColor = array(); $hex_val = array( - ColorGradient::rgb2hex($couleurRGB), - ColorGradient::rgb2hex($fondRGB) + ColorGradient::rgb2hex($vBgRGB), + ColorGradient::rgb2hex($vFgRGB) ); $gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors); for($i=0;$i<$nb_colors;$i++) diff --git a/methode2/peignealpha/draw.php b/methode2/peignealpha/draw.php index a722674..bd3c337 100644 --- a/methode2/peignealpha/draw.php +++ b/methode2/peignealpha/draw.php @@ -33,30 +33,17 @@ function DrawBlock($the_block, $vImage, $parametres) if (isset($parametres['iterations'])) $local_iterations = $parametres['iterations']; $facteur_max = 2.5 * ($height / GRAPH_HEIGHT); - - // 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); + imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $vFgColor); // Dégradé de 256 couleurs entre la couleur de fond et la couleur de dessin $alpha = 100; $nb_colors = 256; $vColor = array(); $hex_val = array( - ColorGradient::rgb2hex($couleurRGB), - ColorGradient::rgb2hex($fondRGB) + ColorGradient::rgb2hex($vBgRGB), + ColorGradient::rgb2hex($vFgRGB) ); $gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors); for($i=0;$i<$nb_colors;$i++) @@ -148,7 +135,7 @@ function DrawBlock($the_block, $vImage, $parametres) if ($valeur != 0) { $decal = 15.0 * ($i / TX_HASH_LEN); - $valeur += rand(0, floor($decal)); + $valeur += floor($decal); $valeur /= 2; $valeur -= 8; $y0 = $h0 + ($valeur * $facteur); diff --git a/methode2/robot.php b/methode2/robot.php index b0a78b7..1c2254b 100644 --- a/methode2/robot.php +++ b/methode2/robot.php @@ -99,11 +99,11 @@ $parametres['font_RGB'] = $paramHeader[4]; $parametres['background_RGB'] = $paramHeader[5]; // Une chance sur deux d'inverser entre fg et bg -if (rand(0,100) < 50) { +if (($the_block->nonce%2)==1) { $parametres['background_color'] = $paramHeader[2]; - $parametres['background_RGB'] = $paramHeader[4]; - $parametres['font_color'] = $paramHeader[1]; - $parametres['font_RGB'] = $paramHeader[5]; + $parametres['background_RGB'] = $paramHeader[4]; + $parametres['font_color'] = $paramHeader[1]; + $parametres['font_RGB'] = $paramHeader[5]; } DrawBlock($the_block, $img, $parametres); diff --git a/methode2/splinelineblack/draw.php b/methode2/splinelineblack/draw.php index a18daaf..758288d 100644 --- a/methode2/splinelineblack/draw.php +++ b/methode2/splinelineblack/draw.php @@ -29,7 +29,7 @@ function DrawBlock($the_block, $vImage, $parametres) if (isset($parametres['background_RGB'])) $vBgRGB = $parametres['background_RGB']; // Forcer les couleurs - $hasard = rand(0,10); + $hasard = $the_block->nonce % 10; $couleur=3;$val=0; if ($hasard > $val++) $couleur = 5; if ($hasard > $val++) $couleur = 6; diff --git a/methode2/splinelineblackalpha/draw.php b/methode2/splinelineblackalpha/draw.php index 4abaccf..395c640 100644 --- a/methode2/splinelineblackalpha/draw.php +++ b/methode2/splinelineblackalpha/draw.php @@ -34,23 +34,9 @@ function DrawBlock($the_block, $vImage, $parametres) $facteur_max = 2.5 * ($height / GRAPH_HEIGHT); - // 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]; - $couleur=imagecolorallocate($vImage,$couleurRGB[0],$couleurRGB[1],$couleurRGB[2]); // Remplir le fond imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $fond); @@ -168,7 +154,7 @@ function DrawBlock($the_block, $vImage, $parametres) if ($valeur != 0) { $decal = 15.0 * ($i / TX_HASH_LEN); - $valeur += rand(0, floor($decal)); + $valeur += floor($decal); $valeur /= 2; $valeur -= 8; $y0 = $h0 + ($valeur * $facteur); diff --git a/methode2/splinelinegradient/draw.php b/methode2/splinelinegradient/draw.php index a2096a0..d432455 100644 --- a/methode2/splinelinegradient/draw.php +++ b/methode2/splinelinegradient/draw.php @@ -28,28 +28,15 @@ function DrawBlock($the_block, $vImage, $parametres) 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); + imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $vFgColor); // Dégradé de 256 couleurs entre la couleur de fond et la couleur de dessin $nb_colors = 256; $vColor = array(); $hex_val = array( - ColorGradient::rgb2hex($couleurRGB), - ColorGradient::rgb2hex($fondRGB) + ColorGradient::rgb2hex($vBgRGB), + ColorGradient::rgb2hex($vFgRGB) ); $gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors); for($i=0;$i<$nb_colors;$i++) diff --git a/methode2/splinelinegradientalpha/draw.php b/methode2/splinelinegradientalpha/draw.php index 4b4af99..a7cfa35 100644 --- a/methode2/splinelinegradientalpha/draw.php +++ b/methode2/splinelinegradientalpha/draw.php @@ -34,29 +34,16 @@ function DrawBlock($the_block, $vImage, $parametres) $facteur_max = 2.5 * ($height / GRAPH_HEIGHT); - // 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); + imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-+($marge_x/2), $y+$height-+($marge_y/2), $vFgColor); // Dégradé de 256 couleurs entre la couleur de fond et la couleur de dessin $alpha = 100; $nb_colors = 256; $vColor = array(); $hex_val = array( - ColorGradient::rgb2hex($couleurRGB), - ColorGradient::rgb2hex($fondRGB) + ColorGradient::rgb2hex($vBgRGB), + ColorGradient::rgb2hex($vFgRGB) ); $gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors); for($i=0;$i<$nb_colors;$i++) @@ -148,7 +135,7 @@ function DrawBlock($the_block, $vImage, $parametres) if ($valeur != 0) { $decal = 15.0 * ($i / TX_HASH_LEN); - $valeur += rand(0, floor($decal)); + $valeur += floor($decal); $valeur /= 2; $valeur -= 8; $y0 = $h0 + ($valeur * $facteur); diff --git a/scripts/blocks2.sh b/scripts/blocks2.sh index b73cbc1..cbe54c1 100755 --- a/scripts/blocks2.sh +++ b/scripts/blocks2.sh @@ -91,15 +91,11 @@ while IFS='' read -r line || [[ -n "$line" ]]; do then php robot.php $METHODE $BLOCK $((RANDOM % 6)) $2 cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/$METHODE/$BLOCK.png + cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png fi done cd - >> /dev/null - if [ ! -f $DATA_PATH/hasard/$BLOCK.png ] - then - cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png - fi - if [ ! -f $DATA_PATH/nonce/$BLOCK.png ] then cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/nonce/$BLOCK.png diff --git a/scripts/blocks3.sh b/scripts/blocks3.sh new file mode 100755 index 0000000..1624292 --- /dev/null +++ b/scripts/blocks3.sh @@ -0,0 +1,121 @@ +#!/bin/bash +lescript=`basename $0 .sh` +flag=$TMP_PATH/bot_$lescript.flag + +# +# TOOLS +# +function debug +{ + if [ -f $FLAG_PATH/debug ] + then + echo $1 + fi +} + +function sortie +{ + exit $1 +} + +function succes +{ + debug "SUCCES" + sortie 0 +} + +function echec +{ + debug "ECHEC" + exit 1 +} + +# +# PARAMETRES PAR FICHIER FLAGS +# +if [ -f $FLAG_PATH/no_blocks ] +then + debug "No blocks" + echec +fi + +while IFS='' read -r line || [[ -n "$line" ]]; do + + NAME=`echo $line | awk '{print $1}'` + BLOCK=`echo $line | awk '{print $2}'` + HEIGHT=`echo $line | awk '{print $3}'` + NBTX=`echo $line | awk '{print $4}'` + + # + # TEST DU FLAG + # + flag=$FLAG_PATH/bot_${lescript}_${BLOCK}.flag + if [ -f $flag ] + then + debug "${lescript}_${BLOCK} already done" + continue + fi + touch $flag + + if [ ! -f $DATA_PATH/nonce/$BLOCK.png ] + then + # + # Si c'est la première fois que l'on dessine le block + # On choisit la méthode qui découle du nonce + # + cd $APPS_PATH/nonce + nbmethodes=`cat $DATA_PATH/nonce_methods_list.txt | wc -l` + lenonce=`php robot.php $BLOCK` + lamethode=$((lenonce % nbmethodes)) + if [ $lamethode -eq 0 ] + then + lamethode=$nbmethodes + fi + LISTE_METHODE=`cat $DATA_PATH/nonce_methods_list.txt | head -n $lamethode | tail -1` + else + # + # CHOISIR UNE METHODE2 AU HASARD + # + LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v robot | shuf` + if [ $NBTX -lt 10 ] + then + LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v robot | grep -v treemap | grep -v mondrian | shuf` + fi + fi + + cd $APPS_PATH/methode2 + for METHODE in $LISTE_METHODE + do + if [ ! -d $DATA_PATH/$METHODE ] + then + mkdir -p $DATA_PATH/$METHODE + fi + echo $BLOCK $NAME $METHODE + if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ] + then + php robot.php $METHODE $BLOCK $((RANDOM % 6)) $2 + cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/$METHODE/$BLOCK.png + cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png + fi + done + cd - >> /dev/null + + if [ ! -f $DATA_PATH/nonce/$BLOCK.png ] + then + cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/nonce/$BLOCK.png + fi + + rm -f $flag + +done < $DATA_PATH/block_list.txt + +# +# List of finished blocks +# +rm -f $DATA_PATH/finished_block_list.txt +grep -v CACHE $DATA_PATH/block_list.txt >> $DATA_PATH/finished_block_list.txt + +# +# SORTIE AVEC SUCCES +# +succes