Compare commits

..

32 Commits

Author SHA1 Message Date
f154d9ab4d add WHALE20201026 to robot.sh 2020-10-29 19:51:19 +01:00
d403c2c90f WHALE20201026 2020-10-28 21:37:14 +01:00
2be9292816 Hal Finley 's blocks 2020-08-31 06:30:31 +02:00
ebbb33cb45 ajout de FIRST_USD_TX 2020-06-07 07:55:07 +02:00
c812e2f79d ajout de 2020JUMP10000 2020-06-02 12:05:39 +02:00
1fab7825da Adding some special blocks like HALVING_3 2020-05-26 08:48:23 +02:00
5e70658660 Ajout d'un block équilibré 2020-02-06 07:02:40 +01:00
4801821219 ajout de 613470 JUMP 9000 2020-01-19 07:26:46 +01:00
42123bbad6 correction date block DEMISSION 2020-01-12 20:27:24 +01:00
dddc112916 ajout du bloc DEMISSION 2020-01-12 20:12:13 +01:00
4455798ad8 ajout de la méthode spirale 2019-07-06 14:51:23 +02:00
1689bd6cd3 correction nonce_binary_str 2019-04-07 15:01:28 +02:00
514daaeaf1 nonce_binary_str 2019-04-07 10:16:41 +02:00
dd9e477e47 formatting text in emptybot 2019-03-10 08:52:17 +01:00
3f4bdf65e0 ajout de la méthode Tyler Hobbs 2019-03-10 08:48:30 +01:00
ccede092d0 splinelineblack is not only black ... 2019-03-09 13:55:23 +01:00
86576841f4 commentaire 2019-03-09 12:35:53 +01:00
43d87614ea special_blocks is now an array of objects , and add getSpecialBlocksJSON 2019-03-03 17:06:53 +01:00
e0cde58e4a tweeter les assemblages moins souvent 2019-02-02 17:56:47 +01:00
f597fc4995 ajout de emptybot 2019-01-27 07:28:31 +01:00
ab2d7de654 mieux gérer le hasard pour les couleurs de bloc header 2019-01-01 14:57:29 +01:00
642a655352 erreur sur final_hash et modif block2.sh 2018-12-30 18:31:18 +01:00
b3c60a5a76 rationaliser les hashes et hashes2hashes 2018-12-30 13:01:12 +01:00
37442a9506 rationaliser robot blockchain 2018-12-30 10:40:10 +01:00
b932e778c6 enlever le blockèlist.txt dans la synchro des blocks 2018-12-29 10:06:44 +01:00
dfe8528deb blockchain : cache.php se limite aux 6 derniers blocs 2018-12-29 10:01:06 +01:00
3c7acc8443 hashes tient compte du cache 2018-12-29 09:56:36 +01:00
b1ed2170f6 suppression d'un fichier inutile 2018-11-10 10:04:34 +01:00
09d51c6bba gestion des cercles et de leurs couleurs 2018-11-10 10:01:06 +01:00
c039cf8da9 Ajout de splinelinealpha dans methode2 2018-11-03 18:14:56 +01:00
6f9a20d1e1 Ajout de splinelineblack dans methode2 2018-11-03 17:57:07 +01:00
b3ad46d98a réorg 2018-10-31 10:06:43 +01:00
66 changed files with 3712 additions and 1408 deletions

View File

@@ -2,6 +2,8 @@
$url = 'http://x:m3lch1s3d3k@127.0.0.1:8332';
$url = 'http://bitcoinrpc:EF/iNKFWzQkpoTB+VFaSGk1+qZPckHsLfKu+3HZddpRr@77.159.16.114:8332';
$data = array("method" => "getbestblockhash");
$json_data = json_encode($data);

22
big.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
#
# VARIABLES
#
export APPS_PATH=`dirname "$(readlink -f "$0")"`
export TMP_PATH=$APPS_PATH/../tmp
export DATA_PATH=$APPS_PATH/../data
export FLAG_PATH=$APPS_PATH/../flags
MINUTE=`date +%M`
DATE=`date +%Y%m%d0000`
if [ -f methode/$1/robot.sh ];
then
source methode/$1/robot.sh
else
source methode2/robot.sh $1 4
fi
#source twitter/twitterbot/robot.sh

View File

@@ -1,50 +0,0 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// ---
// ---
// --- La config globale
// ---
require_once '../global/inc/config.php';
// ---
// --- Internal dependances
// ---
require_once 'inc/block.php';
// ---
// --- Par défaut on cherche le dernier block
// ---
$block_hash = 'LAST';
// ---
// --- On interroge la blockchain
// --- => Ce qui a pour effet de placer le block dans le cache
// ---
$the_block = blockchain::getSpecialBlock($block_hash);
if ($the_block === FALSE) die();
// ---
// --- On en recherche 3 sur approximativement 6 heures (36 blocks)
// ---
$max = 3;
$max2 = 36;
while(($max > 0)&&($max2 > 0))
{
$block_hash = $the_block->prev_block;
if (!file_exists(DATA_PATH.'/json/'.$block_hash.'.zip'))
{
$max--;
echo 'CACHE '.$block_hash.' '.($the_block->height-1)." ".$the_block->n_tx.PHP_EOL;
}
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
$max2--;
}
?>

View File

@@ -1,46 +0,0 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// ---
// ---
// --- La config globale
// ---
require_once '../global/inc/config.php';
// ---
// --- Internal dependances
// ---
require_once 'inc/block.php';
// ---
// --- On interroge la blockchain
// --- => Ce qui a pour effet de placer le block dans le cache
// ---
$block_hash = blockchain::getLastBlockHash();
if ($block_hash === FALSE) die();
echo 'LAST '.$block_hash.' ZIP OK PNG OK';
for($i=0;$i<36;$i++)
{
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
echo ' '.$the_block->height.PHP_EOL;
if ($i == 35) break;
$block_hash = $the_block->prev_block;
echo 'PREV '.$block_hash.' ';
echo 'ZIP ';
if (file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip')) echo 'OK ';
else echo 'KO ';
echo 'PNG ';
if (file_exists(DATA_PATH.'/hasard/'.$the_block->hash.'.png')) echo 'OK';
else echo 'KO';
}
?>
~

View File

@@ -1,5 +1,21 @@
<?php
class block
{
public $hash = null;
public $height = null;
public $name = null;
public $desc = null;
function __construct($ahash, $aheight, $aname = null, $adesc = null)
{
$this->hash = $ahash;
$this->height = $aheight;
$this->name = $aname;
$this->desc = $adesc;
}
}
class blockchain
{
private static $url_info = 'https://blockchain.info/fr';
@@ -9,8 +25,11 @@ class blockchain
*
* 'GENESIS' - Premier block de la blochain
* 'THE_ANSWER' - Block 42 (pour le fun)
* 'HAL_FINLEY' - Hal Finley has mined this block
* 'FIRST_TX' - First exchange between Satoshi and Hal Finley
* 'LUCIFER' - Block 666 (pour le fun)
* 'LEET' - Block 1337 (pour le fun)
* 'FISRT_USD_TX' - Martti Malmi change 5000 BTC for 5,02 $
* 'PIZZA' - Block 57035 : le block du pizza day, 22 05 2010
* 'HALVING_1' - First halving, block 2100000, 28 11 2012
* 'HALVING_2' - Second halving, block 420000, 09 07 2017
@@ -18,31 +37,269 @@ class blockchain
* 'BCC' - Block 478558 : Bitcoin Cash Fork 01/08/2017
* 'SEGWIT_LOCK' - Block 479808 SEGWIT est verrouillé 09 08 2017
* 'SEGWIT' - Block 481823 SEGWIT est activé 24 08 2017
* 'HALVING_3' - Third Hhalving, block 630000, 11 05 2020
* 'DORMEUR' - Block 631058 Une adresse datant de 2009 dépense ses 50 BTC de reward
* TX : cb1440c787d8a46977886405a34da89939e1b04907f567bf182ef27ce53a8d71
*
* ____JUMP______ : Lorsque le cours atteint certains palier (à la hausse ou à la baisse)
* WHALE____ : Lorsqu'une baleine remonte respirer (grosse TX)
* GOLGOTH____ : Lorsque le GOLGOTH pousse fort ... (grosse TX)
*/
private static $special_blocks = array (
'GENESIS' => '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
'THE_ANSWER' => '00000000314e90489514c787d615cea50003af2023796ccdd085b6bcc1fa28f5',
'LUCIFER' => '00000000fc5b3c76f27f810ee775e480ae7fd604fd196b2d8da4257fcd39f4f9',
'LEET' => '000000008bf44a528a09d203203a6a97c165cf53a92ecc27aed0b49b86a19564',
'TOPISTO' => '000000000a73e64735a2b75c97ea674950a9018da1420d01328a918c9ff9852c',
'PIZZA' => '00000000006de085dadb3ec413ef074022fe781121b467e98960280dd246bb00',
'HALVING_1' => '000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e',
'HALVING_2' => '000000000000000002cce816c0ab2c5c269cb081896b7dcb34b8422d6b74ffa1',
'BIP_91_LOCK' => '0000000000000000015411ca4b35f7b48ecab015b14de5627b647e262ba0ec40',
'BCC' => '00000000000000000019f112ec0a9982926f1258cdcc558dd7c3b7e5dc7fa148',
'SEGWIT_LOCK' => '0000000000000000012e6060980c6475a9a8e62a1bf44b76c5d51f707d54522c',
'SEGWIT' => '000000000000000000cbeff0b533f8e1189cf09dfbebf57a8ebe349362811b80',
'HURRICANE_1' => '0000000000000000000fe6d521a187a5523d5cef6f6c178923ff82ffe5a0f372'
private static $special_blocks = null;
// ----
// -- Des fonctions outils
// -- Parce que depuis PHP.7.0.33-10, file_get_contents ne focnitonne plus en HTTPS
// ----
private static function get_curl_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
private static function get_data($url, $with_curl = true)
{
if (!$with_curl)
return file_get_contents($url);
return self::get_curl_data($url);
}
//
// Init special blocks array ...
//
public static function init()
{
self::$special_blocks = array ();
self::$special_blocks[] = new block(
'000000000000000000070daa5861fe1e7064ef8007825431229c6c1cab2c766f',
654364,
'WHALE20201026'
);
self::$special_blocks[] = new block(
'00000000000000000005c0f74e8b00c3961d6dfbf32936edeaa300015949f3c4',
632676,
'2020JUMP10000'
);
self::$special_blocks[] = new block(
'00000000000000000000f811e171eee52157e9a95963140e62fa83610f23ea7e',
631058,
'DORMEUR'
);
self::$special_blocks[] = new block(
'000000000000000000024bead8df69990852c202db0e0097c1a12ea637d7e96d',
630000,
'HALVING_3'
);
self::$special_blocks[] = new block(
'0000000000000000001186079bbf9a5d945231236135af7a766bd34d814e7319',
628710,
'RIP_STEEVE'
);
self::$special_blocks[] = new block(
'000000000000000000099457d2aeb2b7fc8ad8adb1490814cb674dc5767ae9b9',
622453,
'COVID19'
);
self::$special_blocks[] = new block(
'00000000000000000001a3c68111789a6c2cc76f1209d1dae63b05460053eb2b',
619165,
'EQUILIBRE202002'
);
self::$special_blocks[] = new block(
'0000000000000000000f2306f08e8f34872a24dfaad3423801a91ee1626e9ea4',
618986,
'SOPHIA202002'
);
self::$special_blocks[] = new block(
'0000000000000000001085a869441fa2aa77f149a887af0ce59846ef51da6e4c',
616193,
'EQUILIBRE'
);
self::$special_blocks[] = new block(
'0000000000000000000b05f877e6e49b380f4f78b3cfb605b67439f825dba197',
613470,
'2020JUMP9000'
);
self::$special_blocks[] = new block(
'00000000000000000009e8fb4ac719a362c1c4e3df439740069ee58e2a713258',
612149,
'DEMISSION20200110'
);
self::$special_blocks[] = new block(
'000000000000000000051f84a7a1d0f5b2ddaf5682cbec5f7acb2bf5fa339725',
593879,
'GOLGOTH201909'
);
// 94 500 BTC, soit environ 1 milliards de dollars, 700 dollars de fees ...
self::$special_blocks[] = new block(
'00000000000000000014fcb29e6e3b0ead3bd2e307d7f619a935f1d5323e9013',
593468,
'WHALE201909'
);
self::$special_blocks[] = new block(
'0000000000000000000f9f2dadfb8f312572183272802cbfcc4ff95b4ee6777d',
545911,
'WHALE201810'
);
self::$special_blocks[] = new block(
'00000000000000000021e800c1e8df51b22c1588e5a624bea17e9faa34b2dc4a',
528249,
'BLOCK21E800'
);
self::$special_blocks[] = new block(
'0000000000000000000fe6d521a187a5523d5cef6f6c178923ff82ffe5a0f372',
506734,
'HURRICANE_1'
);
self::$special_blocks[] = new block(
'000000000000000000cbeff0b533f8e1189cf09dfbebf57a8ebe349362811b80',
481823,
'SEGWIT'
);
self::$special_blocks[] = new block(
'0000000000000000012e6060980c6475a9a8e62a1bf44b76c5d51f707d54522c',
479808,
'SEGWIT_LOCK'
);
self::$special_blocks[] = new block(
'00000000000000000019f112ec0a9982926f1258cdcc558dd7c3b7e5dc7fa148',
478559,
'BCC'
);
self::$special_blocks[] = new block(
'0000000000000000015411ca4b35f7b48ecab015b14de5627b647e262ba0ec40',
477120,
'BIP_91_LOCK'
);
self::$special_blocks[] = new block(
'000000000000000002cce816c0ab2c5c269cb081896b7dcb34b8422d6b74ffa1',
420000,
'HALVING_2'
);
self::$special_blocks[] = new block(
'0000000000000001bc7156dd1183c87859b326affa3a5cdd157e809537f0b284',
270953,
'WHALE201311'
);
self::$special_blocks[] = new block(
'000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e',
210000,
'HALVING_1'
);
self::$special_blocks[] = new block(
'000000000000041c718cd2fa4270ab80c917bb94caa79c84b417b7924a867a68',
196883,
'JOHN_CONWAY'
);
self::$special_blocks[] = new block(
'00000000006de085dadb3ec413ef074022fe781121b467e98960280dd246bb00',
57035,
'PIZZA'
);
self::$special_blocks[] = new block(
'00000000132fbe8314fc571c0be60b31ccd461c9ee85f42bde8c6d160a9dacc0',
24835,
'FIRST_USD_TX'
);
self::$special_blocks[] = new block(
'000000000a73e64735a2b75c97ea674950a9018da1420d01328a918c9ff9852c',
5637,
'TOPISTO'
);
self::$special_blocks[] = new block(
'00000000a70ba4a405c67310757606dd955cf1a3a8e5c042335d78394ea6cb67',
3654,
'DORMEUR_ORIGINE'
);
self::$special_blocks[] = new block(
'000000008bf44a528a09d203203a6a97c165cf53a92ecc27aed0b49b86a19564',
1337,
'LEET'
);
self::$special_blocks[] = new block(
'00000000fc5b3c76f27f810ee775e480ae7fd604fd196b2d8da4257fcd39f4f9',
666,
'LUCIFER'
);
self::$special_blocks[] = new block(
'00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee',
170,
'FIRST_TX'
);
self::$special_blocks[] = new block(
'00000000a2886c95400fd3b263b9920af80b118b28fee5d2a162a18e4d9d8b2f',
78,
'HAL_FINLEY'
);
self::$special_blocks[] = new block(
'00000000314e90489514c787d615cea50003af2023796ccdd085b6bcc1fa28f5',
42,
'THE_ANSWER'
);
self::$special_blocks[] = new block(
'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
0,
'GENESIS'
);
}
// ---
// --- Retourne le nom d'un block à partie de son hash
// --- Retourne le JSON du tableau des blocs speciaux
// ---
public static function getSpecialBlocksJSON()
{
return json_encode(self::$special_blocks);
}
// ---
// --- Retourne le nom d'un block à partir de son hash
// --- si ce n'est pas un block special, on renvoie le hash
// ---
public static function hash2SpecialName($block_hash)
{
foreach(self::$special_blocks as $key => $value)
if ($block_hash == $value) return $key;
foreach(self::$special_blocks as $value)
if ($block_hash == $value->hash) return $value->name;
return $block_hash;
}
@@ -56,7 +313,14 @@ class blockchain
{
$block_hash = '';
if (isset(self::$special_blocks[$nom_du_block])) $block_hash = self::$special_blocks[$nom_du_block];
foreach(self::$special_blocks as $value)
{
if ($nom_du_block == $value->name)
{
$block_hash = $value->hash;
break;
}
}
if (file_exists(self::$offline_block)) $block_hash = 'offline';
@@ -75,7 +339,7 @@ class blockchain
if (isset($myarray[0]))
{
usort( $myarray, function( $a, $b ) { return filemtime($b) - filemtime($a); } );
return substr(basename($myarray[0],'.png'),0,strlen(self::$special_blocks['GENESIS']));
return substr(basename($myarray[0],'.png'),0,strlen(self::$special_blocks[0]->hash));
}
// S'il n'y a rien dans le cache d'images
@@ -104,7 +368,7 @@ class blockchain
if (file_exists(self::$offline_block)) return 'offline';
$filename=self::$url_info.'/latestblock';
$message = file_get_contents($filename);
$message=self::get_data($filename);
if ($message === FALSE) return FALSE;
$the_block = json_decode($message);
return $the_block->hash;
@@ -121,7 +385,7 @@ class blockchain
if (!file_exists(DATA_PATH."/json/$block_hash.zip"))
{
$filename=self::$url_info.'/rawblock/'.$block_hash;
$message = file_get_contents($filename);
$message=self::get_data($filename);
if ( $message === FALSE ) return FALSE;
$the_block = json_decode($message);
return self::saveBlockInTmpDir($the_block);
@@ -138,6 +402,14 @@ class blockchain
{
if (file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip')) return $the_block;
// Blockchain.info renvoie des nonces négatifs
// Je repasse par la forme binaire pour retrouver
// une valeur positive
$the_block->nonce_binary_str = decbin($the_block->nonce);
if (strlen($the_block->nonce_binary_str) > 32) $the_block->nonce_binary_str = substr($the_block->nonce_binary_str,-32,32);
$the_block->topisto_nonce_blockchain_info = $the_block->nonce;
$the_block->nonce = bindec($the_block->nonce_binary_str);
if (!isset($the_block->topisto_inputs))
{
$the_block->topisto_inputs = 0;
@@ -211,7 +483,7 @@ class blockchain
return NULL;
}
public static function DrawBlockHeaderFooter($the_block, $vImage, $hauteur)
public static function DrawBlockHeaderFooter($the_block, $vImage, $hauteur, $couleur = -1)
{
$color_tab = [
[
@@ -238,6 +510,19 @@ class blockchain
[240,147,43],
[255,255,255]
],
// pour splinelineblack
[
[17,61,86],
[254,254,254]
],
[
[17,61,86],
[255,134,63]
],
[
[234,220,207],
[127,106,85]
],
[
[48,51,107],
[255,255,255]
@@ -250,13 +535,22 @@ class blockchain
[40, 40, 40],
[158,227,253]
],
[
[255, 255, 255],
[0, 0, 0]
],
[
[0, 0, 0],
[255, 255, 255]
],
[
[255, 255, 255],
[255, 0, 0]
]
];
$color = rand(0,count($color_tab)-1);
$color = $couleur;
if (($color == -1) || ($color > (count($color_tab)-1))) $color = rand(0,count($color_tab)-1);
// Rajout des HASHES
$white = imagecolorallocate($vImage, 254, 254, 254);
@@ -272,7 +566,7 @@ class blockchain
imagefilledrectangle($vImage, 0, 0, $w, $h, $white);
$len = strlen($the_block->hash);
$ratio_w = $w / $len;
$ratio_w = ($w - 10) / $len;
$ratio_h = $hauteur / 32; // car hexadécimal
// Récupérer les hashes dans 2 tableaux
@@ -295,7 +589,7 @@ class blockchain
$coin_x1 = $ratio_w * $i;
$coin_x2 = $ratio_w * ($i + 1);
$coin_y1 = $hauteur;
$coin_y2 = hexdec($tableau1[$i])*$ratio_h;
$coin_y2 = 5 + hexdec($tableau1[$i])*$ratio_h;
$points1[] = $coin_x1;
$points1[] = $coin_y2;
@@ -306,7 +600,7 @@ class blockchain
$coin_x1 = $ratio_w * $i;
$coin_x2 = $ratio_w * ($i + 1);
$coin_y1 = $hauteur;
$coin_y2 = 16 - (hexdec($tableau2[$i])*$ratio_h);
$coin_y2 = 25 - hexdec($tableau2[$i])*$ratio_h;
$points2[] = $coin_x1;
$points2[] = $coin_y2;
@@ -314,6 +608,28 @@ class blockchain
$points2[] = $coin_y2;
}
// Rajouter une barre au HASH
$coin_x1 = $ratio_w * $i;
$coin_x2 = $ratio_w * ($i + 1);
$coin_y1 = $hauteur;
$coin_y2 = 5;
$points1[] = $coin_x1;
$points1[] = $coin_y2;
$points1[] = $coin_x2;
$points1[] = $coin_y2;
// Rajouter une barre au PREV HASH
$coin_x1 = $ratio_w * $i;
$coin_x2 = $ratio_w * ($i + 1);
$coin_y1 = $hauteur;
$coin_y2 = 25;
$points2[] = $coin_x1;
$points2[] = $coin_y2;
$points2[] = $coin_x2;
$points2[] = $coin_y2;
// Rajouter un coin
$points1[] = $w;
$points1[] = $hauteur - 1;
@@ -324,7 +640,7 @@ class blockchain
// Inverser le PREV HASH
for($i=0;$i<count($points2);$i+=2)
{
$points2[$i+1] = ($h - 12) - $points2[$i+1];
$points2[$i+1] = $h - $points2[$i+1];
if ($points2[$i+1] >= $h) $points2[$i+1] = $h - 1;
}
@@ -332,12 +648,10 @@ class blockchain
imagefilledpolygon($vImage, $points1, (count($points1)/2), $fond);
imagepolygon($vImage, $points1, (count($points1)/2), $black);
// dessiner le PREV HASH
// Dessiner le PREV HASH
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);
@@ -411,4 +725,6 @@ class blockchain
}
}
blockchain::init();
?>

View File

@@ -1,5 +0,0 @@
<?php
foreach (glob("/opt/Twitterbot/inc/*.php") as $filename) require_once($filename);
?>

View File

@@ -1,47 +0,0 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// ---
// ---
// --- La config globale
// ---
require_once '../global/inc/config.php';
// ---
// --- Internal dependances
// ---
require_once 'inc/block.php';
// ---
// --- On interroge la blockchain
// --- => Ce qui a pour effet de placer le block dans le cache
// ---
block_hash = blockchain::getLastCacheBlockHash();
if ($block_hash === FALSE) die();
$the_block = blockchain::getBlockWithHash($block_hash);
echo 'LAST '.$block_hash.' '.$the_block->height.PHP_EOL;
$block_hash = blockchain::getLastBlockHash();
if ($block_hash === FALSE) die();
$the_block = blockchain::getBlockWithHash($block_hash);
echo 'LAST '.$block_hash.' '.$the_block->height.PHP_EOL;
$the_block = blockchain::getSpecialBlock('LAST');
if ($the_block === FALSE) die();
echo 'LAST '.$the_block->hash." ".$the_block->height.PHP_EOL;
$max = 0;
// On se met en retard d'au moins un bloc ...
while(!file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip'))
{
$block_hash = $the_block->prev_block;
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
// Mais pas plus de 5 blocs de retard ...
$max += 1;if ($max > 5) break;
}
echo 'LAST '.$the_block->hash." ".$the_block->height.PHP_EOL;
?>

View File

@@ -24,29 +24,24 @@ $block_hash = 'LAST';
// ---
if (isset($argv[1])) $block_hash = $argv[1];
echo $block_hash.' ';
// ---
// --- On interroge la blockchain
// --- => Ce qui a pour effet de placer le block dans le cache
// ---
$the_block = blockchain::getSpecialBlock($block_hash);
if ($the_block === FALSE) die();
echo $block_hash.' '.$the_block->hash." ".$the_block->height." ".$the_block->n_tx.PHP_EOL;
if ($block_hash == 'LAST')
{
$max = 0;
// On se met en retard d'au moins un bloc ...
while(!file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip'))
// On a demandé le dernier block
// On remonte sur les huits derniers pour accélerer les prochaines navigations
for($max=0;($max<8)&&(!file_exists(DATA_PATH.'/json/'.$the_block->prev_block.'.zip'));$max++)
{
$block_hash = $the_block->prev_block;
$the_block = blockchain::getSpecialBlock($block_hash);
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
// Mais pas plus de 5 blocs de retard ...
$max += 1;if ($max > 5) break;
echo 'CACHE '.$the_block->hash." ".$the_block->height." ".$the_block->n_tx.PHP_EOL;
}
}
echo $the_block->hash." ".$the_block->height." ".$the_block->n_tx.PHP_EOL;
?>

View File

@@ -11,13 +11,28 @@ touch $flag
cd $APPS_PATH/blockchain
rm -f $DATA_PATH/block_list.txt
rm -f $DATA_PATH/block_list.tmp
php cache.php >> $DATA_PATH/block_list.txt
LISTBLOCKS="GENESIS THE_ANSWER LUCIFER LEET \
TOPISTO PIZZA HALVING_1 WHALE201311 \
JOHN_CONWAY DORMEUR_ORIGINE \
HALVING_2 BIP_91_LOCK BCC SEGWIT_LOCK \
SEGWIT HURRICANE_1 WHALE201810 \
WHALE201909 WHALE20201026 \
BLOCK21E800 GOLGOTH201909 EQUILIBRE \
DEMISSION20200110 2020JUMP9000 \
SOPHIA202002 EQUILBIRE202002 COVID19 \
RIP_STEEVE HALVING_3 DORMEUR \
FIRST_USD_TX 2020JUMP10000 \
LAST"
for BLOCK in GENESIS THE_ANSWER LUCIFER LEET TOPISTO PIZZA HALVING_1 HALVING_2 BIP_91_LOCK BCC SEGWIT_LOCK SEGWIT LAST
for BLOCK in $LISTBLOCKS
do
php robot.php $BLOCK >> $DATA_PATH/block_list.txt
php robot.php $BLOCK >> $DATA_PATH/block_list.tmp
done
# Sort the block list by Height
sort -k3 -n $DATA_PATH/block_list.tmp > $DATA_PATH/block_list.txt
rm -f $DATA_PATH/block_list.tmp
rm -f $flag

View File

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

View File

@@ -11,6 +11,14 @@ export FLAG_PATH=$APPS_PATH/../flags
MINUTE=`date +%M`
DATE=`date +%Y%m%d0000`
source methode/$1/robot.sh
if [ -f methode/$1/robot.sh ];
then
source methode/$1/robot.sh
fi
if [ -d methode2/$1 ];
then
source methode2/robot.sh $1
fi
#source twitter/twitterbot/robot.sh

17
lancer2.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
#
# VARIABLES
#
export APPS_PATH=`dirname "$(readlink -f "$0")"`
export TMP_PATH=$APPS_PATH/../tmp
export DATA_PATH=$APPS_PATH/../data
export FLAG_PATH=$APPS_PATH/../flags
MINUTE=`date +%M`
DATE=`date +%Y%m%d0000`
if [ -f scripts/$1.sh ];
then
source scripts/$1.sh
fi

View File

@@ -1,72 +0,0 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// ---
// ---
// --- La config globale
// ---
require_once '../../global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
$width = 840;
$height = 104;
$final_hash = 'default';
$nb_max = 6;
$numprev = 0;
$img = imagecreatetruecolor($width, $height*$nb_max);
$gris = imagecolorallocate($img, 180, 180, 180);
$noir = imagecolorallocate($img, 0, 0, 0);
$tr = imagecolorallocate($img, 220, 220, 220);
imagecolortransparent($img, $tr);
imagefilledrectangle($img, 0, 0, $width, $height*$nb_max, $tr);
$handle = fopen(DATA_PATH.'/hashes2hashes/liste.txt', 'r');
if ($handle) {
while (($nb_max > 0)&&(($hash = fgets($handle, 4096)) !== false)) {
$hash = preg_replace('~[[:cntrl:]]~', '', $hash);
$split = explode(' ', $hash);
$numero = intval($split[0]);
$hash = $split[1];
if ($final_hash == 'default') $final_hash = $hash;
if (($numprev != 0) && ($numprev != ($numero - 1))) {
imagefilledrectangle($img, 0, $height*$nb_max, $width, $height*($nb_max-1), $gris);
imagerectangle($img, 0, $height*$nb_max, $width, $height*($nb_max-1), $noir);
echo $nb_max.' '.($numprev+1).' manquant !'.PHP_EOL;
$nb_max -= 1;
}
$numprev = $numero;
$nb_max -= 1;
echo $nb_max.' '.$numero.' '.$hash.PHP_EOL;
$hash = DATA_PATH.'/hashes/'.$hash.'.png';
if (file_exists($hash))
{
$src_img = imagecreatefrompng($hash);
if ($src_img)
{
if (FALSE === imagecopy($img, $src_img, 0, $height*$nb_max, 0, 0, $width, $height))
echo "Erreur : problème de copie image".PHP_EOL;
} else echo "Erreur: ".$hash." ne semble pas être une image PNG".PHP_EOL;
} else echo "Erreur: ".$hash." n'a pas été trouvé".PHP_EOL;
}
fclose($handle);
} else echo "Erreur: fopen('".DATA_PATH."/hashes2hashes/liste.txt') a échoué".PHP_EOL;
imagepng($img, DATA_PATH.'/hashes2hashes/'.$final_hash.'.png');
imagedestroy($img);
?>

View File

@@ -51,7 +51,12 @@ $img_h = $height+(2*$bandeau);
// création d'une image plus haute pour inclure bandeaux haut et bas
$img = imagecreatetruecolor($img_w, $img_h);
blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau);
$paramHeader = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau, $mode);
imagefilledrectangle($img, 0, $bandeau, $width, $bandeau + $height, $paramHeader[2]);
imagefilledrectangle($img, 0, 0, 0, $img_h, $paramHeader[2]);
imagefilledrectangle($img, $img_w-1, 0, $img_w-1, $img_h, $paramHeader[2]);
imagepng($img, DATA_PATH.'/hashes/'.$the_block->hash.'.png');

View File

@@ -1,42 +1,22 @@
#!/bin/bash
flag=$TMP_PATH/hashes_bot.flag
METHODE=hashes
flag=$TMP_PATH/${METHODE}_bot.flag
date=`date +%Y%m%d0000`
if [ -f $flag ];
then
echo "hashes_bot is already running !"
echo "${METHODE}_bot is already running !"
exit 0
fi
touch $flag
cd $APPS_PATH/methode/hashes
for BLOCK in `grep LAST $DATA_PATH/block_list.txt | awk '{print $2}'`
cd $APPS_PATH/methode/$METHODE
for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt`
do
if [ ! -f $DATA_PATH/hashes/$BLOCK.png ]
if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ]
then
BLOCK_HEIGHT=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $3}'`
php robot.php $BLOCK $((RANDOM % 6))
echo $BLOCK_HEIGHT $BLOCK >> $DATA_PATH/hashes2hashes/liste.txt
mv $DATA_PATH/hashes2hashes/liste.txt $DATA_PATH/hashes2hashes/liste.new
sort -k1 -n $DATA_PATH/hashes2hashes/liste.new > $DATA_PATH/hashes2hashes/liste.txt
rm -f $DATA_PATH/hashes2hashes/liste.new
COMPTEUR=`wc -l $DATA_PATH/hashes2hashes/liste.txt | awk '{print $1}' `
if [ $COMPTEUR -eq 6 ]
then
php assemble.php
rm -f $DATA_PATH/hashes2hashes/liste.old
mv $DATA_PATH/hashes2hashes/liste.txt $DATA_PATH/hashes2hashes/liste.old
php robot.php $BLOCK 99999
fi
fi
BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'`
if [ "$BNAME" == "LAST" ]
then
touch $DATA_PATH/hashes/$BLOCK.png
else
touch -t $date $DATA_PATH/hashes/$BLOCK.png
fi
done
rm -f $flag

View File

@@ -0,0 +1,73 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// ---
// ---
// --- La config globale
// ---
require_once '../../global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
// ---
// --- Internal dependances
// ---
require_once APP_PATH.'/blockchain/inc/block.php';
// ---
// --- Par défaut on cherche le dernier block
// ---
$block_hash = 'LAST';
// ---
// --- Le cas échéant, on cherche block passé en argument
// ---
if (isset($argv[1])) $block_hash = $argv[1];
$nb_max=6;
if (isset($argv[2])) $nb_max=intval($argv[2]);
$width = 840;
$height = 104;
$final_hash = 'default';
$img = imagecreatetruecolor($width, $height*$nb_max);
$gris = imagecolorallocate($img, 180, 180, 180);
$noir = imagecolorallocate($img, 0, 0, 0);
$tr = imagecolorallocate($img, 220, 220, 220);
imagecolortransparent($img, $tr);
imagefilledrectangle($img, 0, 0, $width, $height*$nb_max, $tr);
for($i=0; $i<$nb_max; $i++)
{
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
$block_hash = $the_block->prev_block;
$hash=DATA_PATH.'/hashes/'.$the_block->hash.'.png';
if ($final_hash == 'default') $final_hash = $the_block->hash;
if (file_exists($hash))
{
$src_img = imagecreatefrompng($hash);
if ($src_img)
{
if (FALSE === imagecopy($img, $src_img, 0, ($height*$i), 0, 0, $width, $height))
echo "Erreur : problème de copie image".PHP_EOL;
} else echo "Erreur: ".$hash." ne semble pas être une image PNG".PHP_EOL;
} else echo "Erreur: ".$hash." n'a pas été trouvé".PHP_EOL;
}
imagepng($img, DATA_PATH.'/hashes2hashes/'.$final_hash.'.png');
imagedestroy($img);
?>

26
methode/hashes2hashes/robot.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
METHODE=hashes2hashes
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
SIZE=6
BLOCK=`grep LAST $DATA_PATH/block_list.txt | awk '{print $2}'`
HEIGHT=`grep LAST $DATA_PATH/block_list.txt | awk '{print $3}'`
if [ $((HEIGHT % SIZE)) -eq 0 ]
then
if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ]
then
php robot.php $BLOCK $SIZE
fi
fi
rm -f $flag

View File

@@ -1,409 +0,0 @@
<?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);
}
}
}
?>

View File

@@ -1,98 +0,0 @@
<?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);
}
}
}
?>

View File

@@ -1,86 +0,0 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// ---
// ---
// --- La config globale
// ---
require_once '../../global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
require_once '../../global/inc/colors.php';
require_once '../../global/inc/cubic.php';
// ---
// --- Internal dependances
// ---
require_once APP_PATH.'/blockchain/inc/block.php';
require_once 'inc/draw.php';
// ---
// --- Par défaut on cherche le dernier block
// ---
$block_hash = 'LAST';
// ---
// --- Le cas échéant, on cherche block passé en argument
// ---
if (isset($argv[1])) $block_hash = $argv[1];
$mode=8;
if (isset($argv[2])) $mode=intval($argv[2]);
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
$the_name = blockchain::hash2SpecialName($the_block->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);
?>

View File

@@ -1,36 +0,0 @@
#!/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

View File

@@ -265,8 +265,6 @@ class CubicSplines
}
}
define('TX_HASH_LEN',64);
class topisto_spline
{
public static function DefaultDrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, $type=1)

View File

@@ -21,9 +21,6 @@ class topisto_spline2
//
public static function DrawBlock($the_block, $vImage, $parametres)
{
return topisto_spline2::DrawLine($the_block, $vImage, $parametres);
$somme = 0;
$min =-1;
$max = 0;

View File

@@ -1,118 +0,0 @@
<?php
use codeagent\treemap\Treemap;
use codeagent\treemap\presenter\ImagePresenter;
use codeagent\treemap\presenter\NodeInfo;
use codeagent\treemap\Gradient;
// ---
// --- Local fonctions
// ---
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 (#)
}
function hex2rgb($color){
$color = str_replace('#', '', $color);
if (strlen($color) != 6){ return array(0,0,0); }
$rgb = array();
for ($x=0;$x<3;$x++){
$rgb[$x] = hexdec(substr($color,(2*$x),2));
}
return $rgb;
}
class topisto_treemap
{
private static function getRGB($methode, $gradient, $factor)
{
switch($methode)
{
case 0:
$rgb = [rand(0,255),rand(0,255),rand(0,255)];
break;
case 1:
$rgb = [80,80,80];
break;
case 2:
$factor=rand(0,100);
$rgb = [255,255,255];
if ($factor < 50 ) $rgb = [255,0,0];
if ($factor < 25 ) $rgb = [0,0,255];
if ($factor < 10 ) $rgb = [255,255,0];
break;
case 3:
$rgb = hex2rgb($gradient[1]->color($factor));
break;
case 4:
$rgb = hex2rgb($gradient[2]->color($factor));
break;
case 999:
$rgb = hex2rgb($gradient[3]->color($factor));
break;
default:
$rgb = hex2rgb($gradient[0]->color($factor));
}
return $rgb;
}
public static function DrawBlock($the_block, $vImage, $parametres)
{
$type = 1;
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['font_color'])) $vBgColor = $parametres['font_color'];
if (isset($parametres['background_color'])) $vFgColor = $parametres['background_color'];
imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vFgColor);
$full_area = $width * $height;
if ($full_area == 0) $full_area = 1;
$data = blockchain::getTransactionData($the_block, $type);
$treemap = new Treemap($data, $width, $height);
$map = $treemap->getMap();
$m = count($map);
$flag_contour = true;
for($mm = 0; $mm < $m; $mm++)
{
$tx = $map[$mm];
$factor = (($tx['_rectangle']->width * $tx['_rectangle']->height) / $full_area)*100.0;
$x1 = $x + $tx['_rectangle']->left;
$y1 = $y + $tx['_rectangle']->top;
$x2 = $x1 + $tx['_rectangle']->width;
$y2 = $y1 + $tx['_rectangle']->height;
if ($x1 > ($x+$width)) $x1 = ($x+$width);
if ($y1 > ($y+$height)) $y1 = ($y+$height);
if ($x2 > ($x+$width)) $x2 = ($x+$width);
if ($y2 > ($y+$height)) $y2 = ($y+$height);
imagerectangle($vImage, $x1, $y1, $x2, $y2, $vBgColor);
}
imagerectangle($vImage, $x, $y, $x+$width-1, $y+$height, $vBgColor);
}
}
?>

View File

@@ -1,81 +0,0 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// ---
// ---
// --- La config globale
// ---
require_once '../../global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
// ---
// --- Internal dependances
// ---
require_once APP_PATH.'/blockchain/inc/block.php';
require_once 'inc/treemap.php';
// ---
// --- Par défaut on cherche le dernier block
// ---
$block_hash = 'LAST';
// ---
// --- Le cas échéant, on cherche block passé en argument
// ---
if (isset($argv[1])) $block_hash = $argv[1];
$mode=rand(0, 5);
if (isset($argv[2])) $mode=intval($argv[2]);
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
$the_name = blockchain::hash2SpecialName($the_block->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;
$param0 = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau);
$parametres = [];
$parametres['x'] = 0;
$parametres['y'] = $bandeau;
$parametres['width'] = $width;
$parametres['height'] = $height;
$parametres['methode'] = $mode;
$parametres['type'] = $type;
$parametres['transparent_color'] = $param0[0];
$parametres['background_color'] = $param0[1];
$parametres['font_color'] = $param0[2];
$parametres['fontname'] = $param0[3];
topisto_treemap::DrawBlock($the_block, $img, $parametres);
imagepng($img, DATA_PATH.'/treemapV2/'.$the_block->hash.'.png');
imagedestroy($img);
?>

View File

@@ -1,32 +0,0 @@
#!/bin/bash
flag=$TMP_PATH/treemapV2_bot.flag
date=`date +%Y%m%d0000`
if [ -f $flag ];
then
echo "treemap_bot is already running !"
exit 0
fi
touch $flag
cd $APPS_PATH/methode/treemapV2
for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt`
do
if [ ! -f $DATA_PATH/treemapV2/$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/treemapV2/$BLOCK.png
else
touch -t $date $DATA_PATH/treemapV2/$BLOCK.png
fi
rm -f $DATA_PATH/hasard/$BLOCK.png
ln $DATA_PATH/treemapV2/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png
done
rm -f $flag

View File

@@ -1,103 +0,0 @@
<?php
use codeagent\treemap\Treemap;
use codeagent\treemap\presenter\ImagePresenter;
use codeagent\treemap\presenter\NodeInfo;
use codeagent\treemap\Gradient;
function rgb2hex($rgb)
{
return "#0203FF";
}
class topisto_veraMolnar
{
public static function DrawBlock($the_block, $vImage, $parametres)
{
$type = 1;
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['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'];
$min =-1;
$max = 0;
$data = blockchain::getTransactionData($the_block, $type);
// Inverser foreground et Background
imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vFgColor);
$vFgColor = imagecolorallocatealpha($vImage, $vBgRGB[0], $vBgRGB[1], $vBgRGB[2], 125);
//$vBgColor = imagecolorallocate($vImage, 10, 10, 10);
//imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vBgColor);
// Calcul des min max
foreach($data as $v)
{
if ($v['value'] > $max) $max = $v['value'];
if (($v['value'] < $min)||($min == -1)) $min = $v['value'];
}
if ($min == $max) $max = $min + 1;
$treemap = new Treemap($data, $width, $height);
$map = $treemap->getMap();
$mm = count($map);
$mmax = $mm - 30;
foreach($map as $tx)
{
$x1 = $x + $tx['_rectangle']->left;
$y1 = $y + $tx['_rectangle']->top;
if (($tx['_rectangle']->height < 2)&&($tx['_rectangle']->width < 2))
{
imagesetpixel($vImage, $x1, $y1, $vFgColor);
} else {
$x2 = $x1;
$y2 = $y1 + $tx['_rectangle']->height;
// if ($y2 >= ($height-$bandeau)) $y2 = ($height - $bandeau) - 1;
$x3 = $x1 + $tx['_rectangle']->width;
$y3 = $y2;
$x4 = $x3;
$y4 = $y1;
// ----
$w = floor($tx['_rectangle']->width / 4);
$h = floor($tx['_rectangle']->height / 4);
$ww = floor(200*($mm/$mmax));
$ww = floor(($h * $w)*0.8);
if ($ww < 1) $ww = 1;
for($i=0;$i<$ww;$i++)
{
$x1_1 = $x1 + floor($w*( rand(0, 100) / 100));
$y1_1 = $y1 + floor($h*( rand(0, 100) / 100));
$x2_1 = $x2 + floor($w*( rand(0, 100) / 100));
$y2_1 = $y2 - floor($h*( rand(0, 100) / 100));
$x3_1 = $x3 - floor($w*( rand(0, 100) / 100));
$y3_1 = $y3 - floor($h*( rand(0, 100) / 100));
$x4_1 = $x4 - floor($w*( rand(0, 100) / 100));
$y4_1 = $y4 + floor($h*( rand(0, 100) / 100));
imageline($vImage, $x1_1, $y1_1, $x2_1, $y2_1, $vFgColor);
imageline($vImage, $x2_1, $y2_1, $x3_1, $y3_1, $vFgColor);
imageline($vImage, $x3_1, $y3_1, $x4_1, $y4_1, $vFgColor);
imageline($vImage, $x4_1, $y4_1, $x1_1, $y1_1, $vFgColor);
}
}
$mm -= 1;
}
}
}
?>

View File

@@ -1,83 +0,0 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// ---
// ---
// --- La config globale
// ---
require_once '../../global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
// ---
// --- Internal dependances
// ---
require_once APP_PATH.'/blockchain/inc/block.php';
require_once 'inc/treemap.php';
// ---
// --- Par défaut on cherche le dernier block
// ---
$block_hash = 'LAST';
// ---
// --- Le cas échéant, on cherche block passé en argument
// ---
if (isset($argv[1])) $block_hash = $argv[1];
$mode=8;
if (isset($argv[2])) $mode=intval($argv[2]);
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
$the_name = blockchain::hash2SpecialName($the_block->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;
$param0 = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau);
$parametres = [];
$parametres['x'] = 0;
$parametres['y'] = $bandeau;
$parametres['width'] = $width;
$parametres['height'] = $height;
$parametres['methode'] = $mode;
$parametres['type'] = $type;
$parametres['transparent_color'] = $param0[0];
$parametres['background_color'] = $param0[1];
$parametres['font_color'] = $param0[2];
$parametres['fontname'] = $param0[3];
$parametres['font_RGB'] = $param0[4];
$parametres['background_RGB'] = $param0[5];
topisto_veraMolnar::DrawBlock($the_block, $img, $parametres);
imagepng($img, DATA_PATH.'/veraMolnar/'.$the_block->hash.'.png');
imagedestroy($img);
?>

View File

@@ -1,33 +0,0 @@
#!/bin/bash
flag=$TMP_PATH/veraMolnar_bot.flag
date=`date +%Y%m%d0000`
if [ -f $flag ];
then
echo "veraMolnar_bot is already running !"
exit 0
fi
touch $flag
cd $APPS_PATH/methode/veraMolnar
for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt`
do
if [ ! -f $DATA_PATH/veraMolnar/$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/veraMolnar/$BLOCK.png
else
touch -t $date $DATA_PATH/veraMolnar/$BLOCK.png
fi
rm -f $DATA_PATH/hasard/$BLOCK.png
ln $DATA_PATH/veraMolnar/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png
done
rm -f $flag

74
methode2/circle/draw.php Normal file
View File

@@ -0,0 +1,74 @@
<?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;
$alpha = 0;
// 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);
}
}
}
?>

View File

@@ -0,0 +1,82 @@
<?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;
$alpha = 0;
// 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);
}
}
?>

View File

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

84
methode2/circles/draw.php Normal file
View File

@@ -0,0 +1,84 @@
<?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;
$alpha = 0;
// 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);
}
}
}
?>

View File

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

86
methode2/line/draw.php Normal file
View File

@@ -0,0 +1,86 @@
<?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;
// 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'];
// Remplir le fond
imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-($marge_x/2), $y+$height-($marge_y/2), $vBgColor);
// 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, $vFgColor);
}
}
?>

View File

@@ -0,0 +1,106 @@
<?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;
// 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'];
// Remplir le fond
imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-($marge_x/2), $y+$height-($marge_y/2), $vBgColor);
// 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($vFgRGB),
ColorGradient::rgb2hex($vBgRGB)
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
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 = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]);
}
// 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;
$limite_x = $x + ($width - (2*$marge_x));
$dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN));
$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 trace
//
$x0 = $x + $marge_x;
while($x0 < $limite_x)
{
$pct = (($x0 - $x)*1.0) / ($limite_x - $x);
$index = floor($pct*$nb_colors);
imageline($vImage, $x0, $h0, $x0+$dx, $h0, $vColor[$index]->color);
$x0 += $dx;
}
}
}
?>

View File

@@ -0,0 +1,119 @@
<?php
function DrawBlock($the_block, $vImage, $parametres)
{
// valeurs par défaut
$type = 1;
$facteur_max = 2.5;
// 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'];
if (isset($parametres['font_RGB'])) $vFgRGB = $parametres['font_RGB'];
if (isset($parametres['background_RGB'])) $vBgRGB = $parametres['background_RGB'];
// Remplir le fond
imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-($marge_x/2), $y+$height-($marge_y/2), $vBgColor);
// 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($vFgRGB),
ColorGradient::rgb2hex($vBgRGB)
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
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 = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]);
}
// 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;
$limite_x = $x + ($width - (2*$marge_x));
$dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN));
$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);
$facteur = 0.1;
//
// On trace
//
$x0 = $x + $marge_x;
for ($i = 0; $i < TX_HASH_LEN; $i++)
{
$y0 = $h0;
$valeur = hexdec($the_block->hash[$i]);
if ($valeur != 0) $y0 += floor(($valeur - 8) * $facteur);
if ($y0 < $y+$marge_y) $y0 = $y+$marge_y;
if ($y0 > ($y+$height-$marge_y)) $y0 = $y+$height-$marge_y;
$pct = (($x0 - $x)*1.0) / ($limite_x - $x);
$index = floor($pct*$nb_colors);
imageline($vImage, $x0, $y0, $x0+$dx, $y0, $vColor[$index]->color);
$x0 += $dx;
if ($y0 == $h0) continue;
$facteur = 0.1 + (($facteur_max*$i) / TX_HASH_LEN);
if ($facteur > $facteur_max) $facteur = $facteur_max;
}
}
}
?>

View File

@@ -0,0 +1,119 @@
<?php
function DrawBlock($the_block, $vImage, $parametres)
{
// valeurs par défaut
$type = 1;
$facteur_max = 2.5;
// 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'];
if (isset($parametres['font_RGB'])) $vFgRGB = $parametres['font_RGB'];
if (isset($parametres['background_RGB'])) $vBgRGB = $parametres['background_RGB'];
// Remplir le fond
imagefilledrectangle($vImage, $x+($marge_x/2), $y+($marge_y/2), $x+$width-($marge_x/2), $y+$height-($marge_y/2), $vBgColor);
// 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($vFgRGB),
ColorGradient::rgb2hex($vBgRGB)
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
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 = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]);
}
// 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;
$limite_x = $x + ($width - (2*$marge_x));
$dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN));
$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);
$facteur = 0.1;
//
// On trace
//
$x0 = $x + $marge_x;
for ($i = 0; $i < TX_HASH_LEN; $i++)
{
$y0 = $h0;
$valeur = hexdec($transaction['hash'][$i]);
if ($valeur != 0) $y0 += floor(($valeur - 8) * $facteur);
if ($y0 < $y+$marge_y) $y0 = $y+$marge_y;
if ($y0 > ($y+$height-$marge_y)) $y0 = $y+$height-$marge_y;
$pct = (($x0 - $x)*1.0) / ($limite_x - $x);
$index = floor($pct*$nb_colors);
imageline($vImage, $x0, $y0, $x0+$dx, $y0, $vColor[$index]->color);
$x0 += $dx;
if ($y0 == $h0) continue;
$facteur = 0.1 + (($facteur_max*$i) / TX_HASH_LEN);
if ($facteur > $facteur_max) $facteur = $facteur_max;
}
}
}
?>

View File

@@ -0,0 +1,89 @@
<?php
use codeagent\treemap\Treemap;
use codeagent\treemap\presenter\ImagePresenter;
use codeagent\treemap\presenter\NodeInfo;
function DrawBlock($the_block, $vImage, $parametres)
{
$type = 1;
if (isset($parametres['x'])) $x = $parametres['x']+2;
if (isset($parametres['y'])) $y = $parametres['y']+2;
if (isset($parametres['width'])) $width = $parametres['width']-4;
if (isset($parametres['height'])) $height = $parametres['height']-4;
if (isset($parametres['methode'])) $mode = $parametres['methode'];
if (isset($parametres['type'])) $type = $parametres['type'];
if (isset($parametres['font_color'])) $vBgColor = $parametres['font_color'];
if (isset($parametres['background_color'])) $vFgColor = $parametres['background_color'];
imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vFgColor);
$couleurs = array();
$couleurs[0] = imagecolorallocate($vImage, 255, 255, 255);
$couleurs[1] = imagecolorallocate($vImage, 255, 0, 0);
$couleurs[2] = imagecolorallocate($vImage, 0, 0, 255);
$couleurs[3] = imagecolorallocate($vImage, 255, 255, 0);
$full_area = $width * $height;
if ($full_area == 0) $full_area = 1;
$data = blockchain::getTransactionData($the_block, $type);
$treemap = new Treemap($data, $width, $height);
$map = $treemap->getMap();
$m = count($map);
$flag_contour = true;
for($mm = 0; $mm < $m; $mm++)
{
$tx = $map[$mm];
$factor = (($tx['_rectangle']->width * $tx['_rectangle']->height) / $full_area)*100.0;
$x1 = $x + $tx['_rectangle']->left;
$y1 = $y + $tx['_rectangle']->top;
$x2 = $x1 + $tx['_rectangle']->width;
$y2 = $y1 + $tx['_rectangle']->height;
if ($x1 > ($x+$width)) $x1 = ($x+$width);
if ($y1 > ($y+$height)) $y1 = ($y+$height);
if ($x2 > ($x+$width)) $x2 = ($x+$width);
if ($y2 > ($y+$height)) $y2 = ($y+$height);
//if (($x2 - $x1) < ($width*0.015)) break;
//if (($y2 - $y1) < ($height*0.015)) break;
$factor=rand(0,100);
// Je triche: les petits rectangle sont blancs
if (($x2 - $x1) < 6) $factor=90;
if (($y2 - $y1) < 6) $factor=90;
$couleur = 0;
if ($factor < 50) $couleur += 1;
if ($factor < 25) $couleur += 1;
if ($factor < 10) $couleur += 1;
// Pourtour noir
imagefilledrectangle($vImage, $x1, $y1, $x2, $y2, $vBgColor);
// Intérieur de couleur
$dx = 1 + floor(0.0025 * $width);
$dy = 1 + floor(0.0025 * $height);
// Je triche: les petits rectangle ont un tour de 1 pixel
if (($x2 - $x1) < 6) $dy=1;
if (($y2 - $y1) < 6) $dy=1;
$x1 = $x1 + $dx;$x2 = $x2 - $dx;
$y1 = $y1 + $dy;$y2 = $y2 - $dy;
if ($x1 > ($x+$width)) $x1 = ($x+$width);
if ($y1 > ($y+$height)) $y1 = ($y+$height);
if ($x2 > ($x+$width)) $x2 = ($x+$width);
if ($y2 > ($y+$height)) $y2 = ($y+$height);
imagefilledrectangle($vImage, $x1, $y1, $x2, $y2, $couleurs[$couleur]);
}
if ($mm < $m) imagerectangle($vImage, $x1, $y1, $x+$width, $y+$height, $vBgColor);
}
?>

156
methode2/peigne/draw.php Normal file
View File

@@ -0,0 +1,156 @@
<?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 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)
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
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 = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]);
}
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
// Un calculateur de Spline
$oCurve = new CubicSplines();
// 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 prend une plus grosse marge en hauteur
$coef = ($height - (4*$marge_y)) / $somme;
$limite_x = $x + ($width - (2*$marge_x));
$dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN+10));
$h0 = 0;
$hauteur = $y + (2*$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);
$x0 = $x + $marge_x;
//
// On découpe la ligne en fonction du nombre de DIGIT
// dans le hash des transactions
//
$facteur = 0.1;
$aCoords = array();
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
for ($i = 0; $i < TX_HASH_LEN; $i++)
{
$y0 = $h0;
$valeur = hexdec($the_block->hash[$i]);
if ($valeur != 0) $y0 += floor(($valeur - 8) * $facteur);
if ($y0 < $y+$marge_y) $y0 = $y+$marge_y;
if ($y0 > ($y+$height-$marge_y)) $y0 = $y+$height-$marge_y;
$x0 += $dx;
$aCoords[$x0] = $y0;
if ($y0 == $h0) continue;
$facteur = 0.1 + (($facteur_max*$i) / TX_HASH_LEN);
if ($facteur > $facteur_max) $facteur = $facteur_max;
}
if ($oCurve)
{
$oCurve->setInitCoords($aCoords);
$r = $oCurve->processCoords();
if ($r)
{
$curveGraph = new Plot($r);
$curveGraph->drawLine($vImage, $vColor, $x0, $limite_x);
}
}
}
}
?>

View File

@@ -0,0 +1,181 @@
<?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;
$local_iterations = 100;
// 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'];
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);
// 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)
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
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);
}
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
// ---
// --- On se limite à 40 000 traits
// --- Pour des questions de performance
// ---
while(($n_data * $local_iterations)>40000) $local_iterations--;
// Un calculateur de Spline
$oCurve = new CubicSplines();
// 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 prend une plus grosse marge en hauteur
$coef = ($height - (4*$marge_y)) / $somme;
$limite_x = $x + ($width - (2*$marge_x));
$dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN+10));
$special_draw = (count($data) == 1);
while($local_iterations-- > 0)
{
$h0 = 0;
$hauteur = $y + (2*$marge_y);
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);
$x0 = $x + $marge_x;
//
// On découpe la ligne en fonction du nombre de DIGIT
// dans le hash des transactions
//
$facteur = 0.1;
$aCoords = array();
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
for ($i = 0; $i < TX_HASH_LEN; $i++)
{
$y0 = $h0;
$valeur = hexdec($the_block->hash[$i]);
if ($valeur != 0)
{
$decal = 15.0 * ($i / TX_HASH_LEN);
$valeur += rand(0, floor($decal));
$valeur /= 2;
$valeur -= 8;
$y0 = $h0 + ($valeur * $facteur);
}
if ($y0 < $y+$marge_y) $y0 = $y+$marge_y;
if ($y0 > ($y+$height-$marge_y)) $y0 = $y+$height-$marge_y;
$x0 += $dx;
$aCoords[$x0] = $y0;
if ($y0 == $h0) continue;
$facteur = 0.1 + (($facteur_max*$i) / TX_HASH_LEN);
if ($facteur > $facteur_max) $facteur = $facteur_max;
}
if ($oCurve)
{
$oCurve->setInitCoords($aCoords);
$r = $oCurve->processCoords();
if ($r)
{
$curveGraph = new Plot($r);
$curveGraph->drawLine($vImage, $vColor, $x0, $limite_x);
}
}
}
}
}
?>

118
methode2/robot.php Normal file
View File

@@ -0,0 +1,118 @@
<?php
// ---
// --- Par défaut, on trace de lignes
// ---
$methode='line';
if (isset($argv[1])) $methode = $argv[1];
// ---
// --- La config globale
// ---
require_once '../global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
require_once '../global/inc/colors.php';
require_once '../global/inc/cubic.php';
// ---
// --- Internal dependances
// ---
require_once APP_PATH.'/blockchain/inc/block.php';
require_once $methode.'/draw.php';
// ---
// --- Par défaut on cherche le dernier block
// --- Le cas échéant, on cherche block passé en argument
// ---
$block_hash = 'LAST';
if (isset($argv[2])) $block_hash = $argv[2];
// ---
// --- Par défaut mode 8
// ---
$mode=8;
if (isset($argv[3])) $mode=intval($argv[3]);
// ---
// --- Par défaut mode 8
// ---
$taille=1;
if (isset($argv[4])) $taille=intval($argv[4]);
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
$the_name = blockchain::hash2SpecialName($the_block->hash);
if ($the_name == $the_block->hash) $the_name ='';
$bandeau = 50;
$marge = 25;
$text_border = 20;
$width = GRAPH_WIDTH * $taille;
$height = GRAPH_HEIGHT * $taille;
$couleur = -1; // Au hasard
// Exception : pour hashes2 on dessine un petit bloc
if ($methode == 'hashes2') $height = 2;
// Exception : pour mondrian on prend unbloc en noir et blanc
if ($methode == 'mondrian') $couleur = 9;
// 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);
// ---
// --- On dessine les inputs, sauf pour les blocks ne contenanty que la récompense
// ---
$type=2;
if (count($the_block->tx)==1) $type = 4;
$paramHeader = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau, $couleur);
imagefilledrectangle($img, 0, $bandeau, $width, $bandeau + $height, $paramHeader[1]);
imageline($img, 0, 5, 0, $img_h-25, $paramHeader[2]);
imageline($img, $width-1, 5, $width-1, $img_h-25, $paramHeader[2]);
$parametres = [];
$parametres['x'] = 0;
$parametres['y'] = $bandeau;
$parametres['width'] = $width;
$parametres['height'] = $height;
$parametres['methode'] = 5;
$parametres['type'] = $type;
$parametres['iterations'] = 10;
$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];
// Une chance sur deux d'inverser entre fg et bg
if (rand(0,100) < 50) {
$parametres['background_color'] = $paramHeader[2];
$parametres['background_RGB'] = $paramHeader[4];
$parametres['font_color'] = $paramHeader[1];
$parametres['font_RGB'] = $paramHeader[5];
}
DrawBlock($the_block, $img, $parametres);
$imagepath = 'big';
if ($taille == 1) $imagepath = 'last';
imagepng($img, DATA_PATH.'/'.$imagepath.'/'.$the_block->hash.'.png');
imagedestroy($img);
?>

52
methode2/robot.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/bash
METHODE=$1
flag=$TMP_PATH/${METHODE}_bot.flag
date=`date +%Y%m%d0000`
if [ ! -d $APPS_PATH/methode2/$METHODE ];
then
echo $APPS_PATH/methode2/$METHODE introuvable ...
exit 1
fi
if [ -f $flag ];
then
echo "${METHODE}_bot is already running ! [$flag]"
exit 0
fi
touch $flag
if [ ! -d $DATA_PATH/$METHODE ];
then
mkdir -p $DATA_PATH/$METHODE
fi
cd $APPS_PATH/methode2
for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt`
do
if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ]
then
php robot.php $1 $BLOCK $((RANDOM % 6)) $2
if [ "$2" == "" ];
then
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
fi
fi
if [ -f $DATA_PATH/$METHODE/$BLOCK.png ]
then
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
fi
done
rm -f $flag

135
methode2/spirale/draw.php Normal file
View File

@@ -0,0 +1,135 @@
<?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;
$alpha = 0;
// 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'];
// Je reprends les couleurs de Tyler Hobbs
$couleursRGB=[
[234,220,207],
[197,46,39],
[183,230,214],
[248,200,40],
[51,41,32],
[250,142,41],
[5,37,32],
[233,201,58],
[183,230,214]
];
$couleurs = [];
$nb_couleurs = count($couleursRGB);
for($i=0;$i<$nb_couleurs;$i++)
$couleurs[$i] = imagecolorallocate($vImage,$couleursRGB[$i][0],$couleursRGB[$i][1],$couleursRGB[$i][2]);
// Prendre une des couleurs au hasard comme couleur de fond
shuffle($couleurs);
$fond = $couleurs[0];
shuffle($couleurs);
// 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;
// On commence au centre de l'image
$xc = $x + ($width / 2);
$yc = $y + ($height / 2);
$r = $width / 3;
$cur = 0;
$n = 0;
$x1 = $xc;
$y1 = $yc;
$x2 = $xc;
$y2 = $yc;
// Trouver le max
$max=0;
while(true){
$r1 = 0.05 * $max;
$x2 = $xc + $r1*cos($r1);
$y2 = $yc + $r1*sin($r1);
if (($x2 > $width) || ($x2 < 0)) break;
if (($y2 > $height) || ($y2 < 0)) break;
imageline($vImage, $x1, $y1, $x2, $y2, $couleurs[0]);
$x1 = $x2;
$y1 = $y2;
$max++;
}
$coef = floatval($max) / floatval($somme);
$cur = 0;
$n = 0;
$x1 = $xc;
$y1 = $yc;
$x2 = $xc;
$y2 = $yc;
foreach($data as $transaction)
{
// chaque fois que toutes les couleurs ont été utilisées
// on mélange leur ordre
if (!($n%$nb_couleurs)) shuffle($couleurs);
// S'il n'y a qu'une transaction
// Ou Si la transaction courante représente plus du 5eme de la somme des tx
// On s'interdit la couleur de fond
if (($n_data == 1)||($transaction['value'] > ($somme/5)))
while ($couleurs[$n%$nb_couleurs] == $fond) $n++;
$couleur = $couleurs[$n%$nb_couleurs];
// le segment de couleur est de longueur proportionnelle
// à la valeur de sa transaction
$next = $cur + ($coef*$transaction['value']);
if ($next > $max) $next = $max;
while($cur<$next)
{
$r1 = 0.05 * $cur;
$x2 = $xc + $r1*cos($r1);
$y2 = $yc + $r1*sin($r1);
imageline($vImage, $x1, $y1, $x2, $y2, $couleur);
$x1 = $x2;
$y1 = $y2;
$cur++;
}
$n++;
}
}
?>

View File

@@ -0,0 +1,207 @@
<?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'];
// Forcer les couleurs
$hasard = rand(0,10);
$couleur=3;$val=0;
if ($hasard > $val++) $couleur = 5;
if ($hasard > $val++) $couleur = 6;
if ($hasard > $val++) $couleur = 7;
if ($hasard > $val++) $couleur = 8;
$couleur = 8;
switch($couleur) {
case 3:
case 5:
$fondRGB=[0,0,0];
$couleurRGB=[240,147,43];
break;
case 7:
$fondRGB=[17,61,86];
$couleurRGB=[255,134,63];
break;
case 8:
$fondRGB=[234,220,207];
$couleurRGB=[252,196,37];
break;
default:
$fondRGB=[17,61,86];
$couleurRGB=[73,20,26];
}
$img_w = $width;
$img_h = $height+(2*$y);
// Redessiner entête et pied de page
$p2 = blockchain::DrawBlockHeaderFooter($the_block, $vImage, $y, $couleur);
$fond=imagecolorallocate($vImage,$fondRGB[0],$fondRGB[1],$fondRGB[2]);
//$couleur=imagecolorallocate($vImage,$couleurRGB[0],$couleurRGB[1],$couleurRGB[2]);
// Remplir le fond
imagefilledrectangle($vImage, 0, $y, $width, $y + $height, $fond);
imageline($vImage, 0, 5, 0, $img_h-25, $p2[2]);
imageline($vImage, $width-1, 5, $width-1, $img_h-25, $p2[2]);
$vColor = array();
// Dégradé de 192 couleurs entre la couleur de dessin et le blanc
$nb_colors = 192;
$hex_val = array(
ColorGradient::rgb2hex($couleurRGB),
ColorGradient::rgb2hex([255,255,255])
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
for($i=0;$i<$nb_colors;$i++)
{
$rgbval = ColorGradient::hex2rgb($gradient[$i]);
$vColor[$i] = new ColorGradient();
$vColor[$i]->pct = ($i*1.0) / 256;
$vColor[$i]->color = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]);
}
// On ajoute un dégradé de 64 couleurs entre le blanc et la couleur de fond
$nb_colors = 64;
$hex_val = array(
ColorGradient::rgb2hex([255,255,255]),
ColorGradient::rgb2hex($fondRGB)
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
for($i=0;$i<$nb_colors;$i++)
{
$rgbval = ColorGradient::hex2rgb($gradient[$i]);
// Pas de blanc <=> c'est la transparence ...
if (($rgbval[0] == $rgbval[1])&&($rgbval[1] == $rgbval[2])&&($rgbval[0] == 254))
{
$rgbval[0] = 255;
$rgbval[1] = 255;
$rgbval[2] = 255;
}
$vColor[192+$i] = new ColorGradient();
$vColor[192+$i]->pct = ((192+$i)*1.0) / 256;
$vColor[192+$i]->color = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]);
}
$nb_colors = 256;
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
// Un calculateur de Spline
$oCurve = new CubicSplines();
// 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 prend une plus grosse marge en hauteur
$coef = ($height - (4*$marge_y)) / $somme;
$limite_x = $x + ($width - (2*$marge_x));
$dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN+10));
$h0 = 0;
$hauteur = $y + (2*$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);
$x0 = $x + $marge_x;
//
// On découpe la ligne en fonction du nombre de DIGIT
// dans le hash des transactions
//
$facteur = 0.1;
$aCoords = array();
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
for ($i = 0; $i < TX_HASH_LEN; $i++)
{
$y0 = $h0;
$valeur = hexdec($transaction['hash'][$i]);
if ($valeur != 0) $y0 += floor(($valeur - 8) * $facteur);
if ($y0 < $y+$marge_y) $y0 = $y+$marge_y;
if ($y0 > ($y+$height-$marge_y)) $y0 = $y+$height-$marge_y;
$x0 += $dx;
$aCoords[$x0] = $y0;
if ($y0 == $h0) continue;
$facteur = 0.1 + (($facteur_max*$i) / TX_HASH_LEN);
if ($facteur > $facteur_max) $facteur = $facteur_max;
}
if ($oCurve)
{
$oCurve->setInitCoords($aCoords);
$r = $oCurve->processCoords();
if ($r)
{
$curveGraph = new Plot($r);
$curveGraph->drawLine($vImage, $vColor, $x0, $limite_x);
}
}
}
}
?>

View File

@@ -0,0 +1,201 @@
<?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;
$local_iterations = 100;
// 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'];
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;
}
$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);
// Dégradé de 192 couleurs entre la couleur de dessin et le blanc
$alpha = 100;
$vColor = array();
$nb_colors = 192;
$hex_val = array(
ColorGradient::rgb2hex($couleurRGB),
ColorGradient::rgb2hex([255,255,255])
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
for($i=0;$i<$nb_colors;$i++)
{
$rgbval = ColorGradient::hex2rgb($gradient[$i]);
$vColor[$i] = new ColorGradient();
$vColor[$i]->pct = ($i*1.0) / 256;
$vColor[$i]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha);
}
// On ajoute un dégradé de 64 couleurs entre le blanc et la couleur de fond
$nb_colors = 64;
$hex_val = array(
ColorGradient::rgb2hex([255,255,255]),
ColorGradient::rgb2hex($fondRGB)
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
for($i=0;$i<$nb_colors;$i++)
{
$rgbval = ColorGradient::hex2rgb($gradient[$i]);
$vColor[192+$i] = new ColorGradient();
$vColor[192+$i]->pct = ((192+$i)*1.0) / 256;
$vColor[192+$i]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha);
}
$nb_colors = 256;
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
// ---
// --- On se limite à 40 000 traits
// --- Pour des questions de performance
// ---
while(($n_data * $local_iterations)>40000) $local_iterations--;
// Un calculateur de Spline
$oCurve = new CubicSplines();
// 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 prend une plus grosse marge en hauteur
$coef = ($height - (4*$marge_y)) / $somme;
$limite_x = $x + ($width - (2*$marge_x));
$dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN+10));
$special_draw = (count($data) == 1);
while($local_iterations-- > 0)
{
$h0 = 0;
$hauteur = $y + (2*$marge_y);
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);
$x0 = $x + $marge_x;
//
// On découpe la ligne en fonction du nombre de DIGIT
// dans le hash des transactions
//
$facteur = 0.1;
$aCoords = array();
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
for ($i = 0; $i < TX_HASH_LEN; $i++)
{
$y0 = $h0;
$valeur = hexdec($transaction['hash'][$i]);
if ($valeur != 0)
{
$decal = 15.0 * ($i / TX_HASH_LEN);
$valeur += rand(0, floor($decal));
$valeur /= 2;
$valeur -= 8;
$y0 = $h0 + ($valeur * $facteur);
}
if ($y0 < $y+$marge_y) $y0 = $y+$marge_y;
if ($y0 > ($y+$height-$marge_y)) $y0 = $y+$height-$marge_y;
$x0 += $dx;
$aCoords[$x0] = $y0;
if ($y0 == $h0) continue;
$facteur = 0.1 + (($facteur_max*$i) / TX_HASH_LEN);
if ($facteur > $facteur_max) $facteur = $facteur_max;
}
if ($oCurve)
{
$oCurve->setInitCoords($aCoords);
$r = $oCurve->processCoords();
if ($r)
{
$curveGraph = new Plot($r);
$curveGraph->drawLine($vImage, $vColor, $x0, $limite_x);
}
}
}
}
}
?>

View File

@@ -0,0 +1,156 @@
<?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 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)
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
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 = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]);
}
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
// Un calculateur de Spline
$oCurve = new CubicSplines();
// 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 prend une plus grosse marge en hauteur
$coef = ($height - (4*$marge_y)) / $somme;
$limite_x = $x + ($width - (2*$marge_x));
$dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN+10));
$h0 = 0;
$hauteur = $y + (2*$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);
$x0 = $x + $marge_x;
//
// On découpe la ligne en fonction du nombre de DIGIT
// dans le hash des transactions
//
$facteur = 0.1;
$aCoords = array();
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
for ($i = 0; $i < TX_HASH_LEN; $i++)
{
$y0 = $h0;
$valeur = hexdec($transaction['hash'][$i]);
if ($valeur != 0) $y0 += floor(($valeur - 8) * $facteur);
if ($y0 < $y+$marge_y) $y0 = $y+$marge_y;
if ($y0 > ($y+$height-$marge_y)) $y0 = $y+$height-$marge_y;
$x0 += $dx;
$aCoords[$x0] = $y0;
if ($y0 == $h0) continue;
$facteur = 0.1 + (($facteur_max*$i) / TX_HASH_LEN);
if ($facteur > $facteur_max) $facteur = $facteur_max;
}
if ($oCurve)
{
$oCurve->setInitCoords($aCoords);
$r = $oCurve->processCoords();
if ($r)
{
$curveGraph = new Plot($r);
$curveGraph->drawLine($vImage, $vColor, $x0, $limite_x);
}
}
}
}
?>

View File

@@ -0,0 +1,181 @@
<?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;
$local_iterations = 100;
// 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'];
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);
// 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)
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
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);
}
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
// ---
// --- On se limite à 40 000 traits
// --- Pour des questions de performance
// ---
while(($n_data * $local_iterations)>40000) $local_iterations--;
// Un calculateur de Spline
$oCurve = new CubicSplines();
// 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 prend une plus grosse marge en hauteur
$coef = ($height - (4*$marge_y)) / $somme;
$limite_x = $x + ($width - (2*$marge_x));
$dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN+10));
$special_draw = (count($data) == 1);
while($local_iterations-- > 0)
{
$h0 = 0;
$hauteur = $y + (2*$marge_y);
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);
$x0 = $x + $marge_x;
//
// On découpe la ligne en fonction du nombre de DIGIT
// dans le hash des transactions
//
$facteur = 0.1;
$aCoords = array();
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
for ($i = 0; $i < TX_HASH_LEN; $i++)
{
$y0 = $h0;
$valeur = hexdec($transaction['hash'][$i]);
if ($valeur != 0)
{
$decal = 15.0 * ($i / TX_HASH_LEN);
$valeur += rand(0, floor($decal));
$valeur /= 2;
$valeur -= 8;
$y0 = $h0 + ($valeur * $facteur);
}
if ($y0 < $y+$marge_y) $y0 = $y+$marge_y;
if ($y0 > ($y+$height-$marge_y)) $y0 = $y+$height-$marge_y;
$x0 += $dx;
$aCoords[$x0] = $y0;
if ($y0 == $h0) continue;
$facteur = 0.1 + (($facteur_max*$i) / TX_HASH_LEN);
if ($facteur > $facteur_max) $facteur = $facteur_max;
}
if ($oCurve)
{
$oCurve->setInitCoords($aCoords);
$r = $oCurve->processCoords();
if ($r)
{
$curveGraph = new Plot($r);
$curveGraph->drawLine($vImage, $vColor, $x0, $limite_x);
}
}
}
}
}
?>

View File

@@ -0,0 +1,55 @@
<?php
use codeagent\treemap\Treemap;
use codeagent\treemap\presenter\ImagePresenter;
use codeagent\treemap\presenter\NodeInfo;
function DrawBlock($the_block, $vImage, $parametres)
{
$type = 1;
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['font_color'])) $vBgColor = $parametres['font_color'];
if (isset($parametres['background_color'])) $vFgColor = $parametres['background_color'];
imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vFgColor);
$full_area = $width * $height;
if ($full_area == 0) $full_area = 1;
$data = blockchain::getTransactionData($the_block, $type);
$treemap = new Treemap($data, $width, $height);
$map = $treemap->getMap();
$m = count($map);
$flag_contour = true;
for($mm = 0; $mm < $m; $mm++)
{
$tx = $map[$mm];
$factor = (($tx['_rectangle']->width * $tx['_rectangle']->height) / $full_area)*100.0;
$x1 = $x + $tx['_rectangle']->left;
$y1 = $y + $tx['_rectangle']->top;
$x2 = $x1 + $tx['_rectangle']->width;
$y2 = $y1 + $tx['_rectangle']->height;
if ($x1 > ($x+$width)) $x1 = ($x+$width);
if ($y1 > ($y+$height)) $y1 = ($y+$height);
if ($x2 > ($x+$width)) $x2 = ($x+$width);
if ($y2 > ($y+$height)) $y2 = ($y+$height);
if (($x2 - $x1) < 3) break;
if (($y2 - $y1) < 3) break;
imagerectangle($vImage, $x1, $y1, $x2, $y2, $vBgColor);
}
if ($mm < $m) imagerectangle($vImage, $x1, $y1, $x+$width, $y+$height, $vBgColor);
}
?>

View File

@@ -0,0 +1,216 @@
<?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'];
$fondRGB=[234,220,207];
$couleursRGB=[
[197,46,39],
[183,230,214],
[248,200,40],
[51,41,32],
[250,142,41],
[5,37,32],
[233,201,58],
[183,230,214]
];
shuffle($couleursRGB);
$pas = $height / (count($couleursRGB)-1);
$img_w = $width;
$img_h = $height+(2*$y);
// Redessiner entête et pied de page
$p2 = blockchain::DrawBlockHeaderFooter($the_block, $vImage, $y, 8);
$fond=imagecolorallocate($vImage,$fondRGB[0],$fondRGB[1],$fondRGB[2]);
// Remplir le fond
imagefilledrectangle($vImage, 0, $y, $width, $y + $height, $fond);
// Tracer des bords à droite et à gauche
imageline($vImage, 0, 5, 0, $img_h-25, $p2[2]);
imageline($vImage, $width-1, 5, $width-1, $img_h-25, $p2[2]);
// Récup des données
$data = blockchain::getTransactionData($the_block, $type);
$n_data = count($data);
// Un calculateur de Spline
$oCurve = new CubicSplines();
// 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 prend une plus grosse marge en hauteur
$coef = ($height - (4*$marge_y)) / $somme;
$limite_x = $x + ($width - (2*$marge_x));
$dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN+10));
$h0 = 0;
$hauteur = $y + (2*$marge_y);
$special_draw = (count($data) == 1);
$etage = -1;
// [ TODO ] L'épaisseur du trait dépend du nombre de transactions
$epaisseur = 5;
foreach($data as $transaction)
{
//
// La nouvelle hauteur : cumule des montants de transaction
//
$hauteur += $coef * $transaction['value'];
//
// Gestion de la couleur
//
if ($etage != floor($hauteur/$pas))
{
$etage = floor($hauteur/$pas);
$vColor = array();
// Dégradé de 192 couleurs entre la couleur de dessin et le blanc
$nb_colors = 192;
$hex_val = array(
ColorGradient::rgb2hex($couleursRGB[$etage]),
ColorGradient::rgb2hex([255,255,255])
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
for($i=0;$i<$nb_colors;$i++)
{
$rgbval = ColorGradient::hex2rgb($gradient[$i]);
// Pas de blanc <=> c'est la transparence ...
if (($rgbval[0] == $rgbval[1])&&($rgbval[1] == $rgbval[2])&&($rgbval[0] > 252))
{
$rgbval[0] = 255;
$rgbval[1] = 255;
$rgbval[2] = 255;
}
$vColor[$i] = new ColorGradient();
$vColor[$i]->pct = ($i*1.0) / 256;
$vColor[$i]->color = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]);
}
// On ajoute un dégradé de 64 couleurs entre le blanc et la couleur de fond
$nb_colors = 64;
$hex_val = array(
ColorGradient::rgb2hex([255,255,255]),
ColorGradient::rgb2hex($fondRGB)
);
$gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors);
for($i=0;$i<$nb_colors;$i++)
{
$rgbval = ColorGradient::hex2rgb($gradient[$i]);
// Pas de blanc <=> c'est la transparence ...
if (($rgbval[0] == $rgbval[1])&&($rgbval[1] == $rgbval[2])&&($rgbval[0] > 252))
{
$rgbval[0] = 255;
$rgbval[1] = 255;
$rgbval[2] = 255;
}
$vColor[192+$i] = new ColorGradient();
$vColor[192+$i]->pct = ((192+$i)*1.0) / 256;
$vColor[192+$i]->color = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]);
}
$nb_colors = 256;
}
//
// 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);
$x0 = $x + $marge_x;
//
// On découpe la ligne en fonction du nombre de DIGIT
// dans le hash des transactions
//
$facteur = 0.1;
$aCoords = array();
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
$aCoords[$x0] = $h0; $x0 += $dx;
for ($i = 0; $i < TX_HASH_LEN; $i++)
{
$y0 = $h0;
$valeur = hexdec($transaction['hash'][$i]);
if ($valeur != 0) $y0 += floor(($valeur - 8) * $facteur);
$x0 += $dx;
$aCoords[$x0] = $y0;
if ($y0 == $h0) continue;
$facteur = 0.1 + (($facteur_max*$i) / TX_HASH_LEN);
if ($facteur > $facteur_max) $facteur = $facteur_max;
}
for($i=0;$i<$epaisseur;$i++)
{
foreach($aCoords as &$aCoord)
{
$aCoord += 1;
if ($aCoord < $y+$marge_y) $aCoord = $y+$marge_y;
if ($aCoord > ($y+$height-$marge_y)) $aCoord = $y+$height-$marge_y;
}
$oCurve->setInitCoords($aCoords);
$r = $oCurve->processCoords();
if ($r)
{
$curveGraph = new Plot($r);
$curveGraph->drawLine($vImage, $vColor, $x0, $limite_x);
}
}
}
}
?>

View File

@@ -0,0 +1,95 @@
<?php
use codeagent\treemap\Treemap;
use codeagent\treemap\presenter\ImagePresenter;
use codeagent\treemap\presenter\NodeInfo;
use codeagent\treemap\Gradient;
function DrawBlock($the_block, $vImage, $parametres)
{
$type = 1;
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['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'];
$min =-1;
$max = 0;
$data = blockchain::getTransactionData($the_block, $type);
// Inverser foreground et Background
imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vFgColor);
$vFgColor = imagecolorallocatealpha($vImage, $vBgRGB[0], $vBgRGB[1], $vBgRGB[2], 125);
//$vBgColor = imagecolorallocate($vImage, 10, 10, 10);
//imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vBgColor);
// Calcul des min max
foreach($data as $v)
{
if ($v['value'] > $max) $max = $v['value'];
if (($v['value'] < $min)||($min == -1)) $min = $v['value'];
}
if ($min == $max) $max = $min + 1;
$treemap = new Treemap($data, $width, $height);
$map = $treemap->getMap();
$mm = count($map);
$mmax = $mm - 30;
foreach($map as $tx)
{
$x1 = $x + $tx['_rectangle']->left;
$y1 = $y + $tx['_rectangle']->top;
if (($tx['_rectangle']->height < 2)&&($tx['_rectangle']->width < 2))
{
imagesetpixel($vImage, $x1, $y1, $vFgColor);
} else {
$x2 = $x1;
$y2 = $y1 + $tx['_rectangle']->height;
// if ($y2 >= ($height-$bandeau)) $y2 = ($height - $bandeau) - 1;
$x3 = $x1 + $tx['_rectangle']->width;
$y3 = $y2;
$x4 = $x3;
$y4 = $y1;
// ----
$w = floor($tx['_rectangle']->width / 4);
$h = floor($tx['_rectangle']->height / 4);
$ww = floor(200*($mm/$mmax));
$ww = floor(($h * $w)*0.8);
if ($ww < 1) $ww = 1;
for($i=0;$i<$ww;$i++)
{
$x1_1 = $x1 + floor($w*( rand(0, 100) / 100));
$y1_1 = $y1 + floor($h*( rand(0, 100) / 100));
$x2_1 = $x2 + floor($w*( rand(0, 100) / 100));
$y2_1 = $y2 - floor($h*( rand(0, 100) / 100));
$x3_1 = $x3 - floor($w*( rand(0, 100) / 100));
$y3_1 = $y3 - floor($h*( rand(0, 100) / 100));
$x4_1 = $x4 - floor($w*( rand(0, 100) / 100));
$y4_1 = $y4 + floor($h*( rand(0, 100) / 100));
imageline($vImage, $x1_1, $y1_1, $x2_1, $y2_1, $vFgColor);
imageline($vImage, $x2_1, $y2_1, $x3_1, $y3_1, $vFgColor);
imageline($vImage, $x3_1, $y3_1, $x4_1, $y4_1, $vFgColor);
imageline($vImage, $x4_1, $y4_1, $x1_1, $y1_1, $vFgColor);
}
}
$mm -= 1;
}
}
?>

View File

@@ -8,8 +8,10 @@ export TMP_PATH=$APPS_PATH/../tmp
export DATA_PATH=$APPS_PATH/../data
export FLAG_PATH=$APPS_PATH/../flags
export TS=`date +%s`
export MINUTE=`date +%M | sed 's/^0*//'`
export DATE=`date +%Y%m%d0000`
export DATEHOUR=`date +%Y%m%d%H`
#
# Synchronize the Blockchain
@@ -24,7 +26,7 @@ $APPS_PATH/scripts/hashes.sh
#
# Draw the BLOCKS
#
$APPS_PATH/scripts/blocks.sh
$APPS_PATH/scripts/blocks2.sh
#
# Send a TWEET

View File

@@ -53,6 +53,16 @@ then
echec
fi
#
# CHOISIR UNE METHODE2 AU HASARD
#
ROBOT=`ls $APPS_PATH/methode2 | shuf | tail -n 1`
debug $ROBOT
$APPS_PATH/methode2/robot.sh $ROBOT
succes
#
# CHOISIR UNE METHODE AU HASARD
#

105
scripts/blocks2.sh Executable file
View File

@@ -0,0 +1,105 @@
#!/bin/bash
lescript=blocks2
#
# 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
#
# CHOISIR UNE METHODE2 AU HASARD
#
# LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v robot | shuf`
# LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v robot | shuf | head -n 1`
# en rajoutant le head, on ne fait qu'un seul dessin
LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v robot | shuf | head -n 1`
if [ $HEIGHT -eq 1 ]
then
LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v treemap | grep -v robot | shuf | head -n 1`
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
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
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

View File

@@ -1,11 +1,22 @@
#!/bin/bash
# Antidater les données des blocks connus
date=`date +%Y%m%d0000`
touch -t $date $DATA_PATH/emptybot/*
for BLOCK in `grep -v LAST $DATA_PATH/block_list.txt | grep -v CACHE | awk '{print $2}'`
do
touch -t $date $DATA_PATH/*/$BLOCK.*
done
# Effacer ce qui trop vieux
if [ "$#" -eq "0" ]
then
if [ -d $DATA_PATH ]
then
find $DATA_PATH -mtime +1 -type f -name *.png -exec rm -f {} \;
find $DATA_PATH -mtime +1 -type f -name *.zip -exec rm -f {} \;
find $TMP_PATH -mtime +3 -type f -name *.flag -exec rm -f {} \;
fi
else
if [ "$1" -eq "FULL" ]

View File

@@ -53,12 +53,14 @@ then
echec
fi
#
# Toujours placer la version HASHES
#
debug "Compute HASHES ..."
$APPS_PATH/methode/hashes/robot.sh
#
debug "Compute HASHES2HASHES ..."
$APPS_PATH/methode/hashes2hashes/robot.sh
#
# SORTIE AVEC SUCCES
#

View File

@@ -53,11 +53,28 @@ then
echec
fi
if [ ! -d $DATA_PATH/twitterbot ]
then
mkdir -p $DATA_PATH/twitterbot
fi
if [ ! -d $DATA_PATH/emptybot ]
then
mkdir -p $DATA_PATH/emptybot
fi
#
# TWEET
#
TWEET=30
if [ $((MINUTE % $TWEET)) -eq 0 ]
# tweet Topisto : empty blocks
$APPS_PATH/twitter/emptybot/robot.sh 2>&1
# tweet frequency : 2 Hours
#TWEETFREQ=7200
#if [ $((TS % $TWEETFREQ)) -eq 0 ]
# Tweet freq : One per Hour
if [ ! -f $DATA_PATH/twitterbot/$DATEHOUR ]
then
debug "send a TWEET"
@@ -66,8 +83,10 @@ then
# "auto likes" from Topisto
$APPS_PATH/twitter/likebot/robot.sh 2>&1
touch $DATA_PATH/twitterbot/$DATEHOUR
else
debug "no TWEET"
debug "skip TWEET"
fi
#

4
test.sh Normal file
View File

@@ -0,0 +1,4 @@
while IFS='' read -r line || [[ -n "$line" ]]; do
ROW="$line"
echo "Text read from file: $ROW"
done < ../data/block_list.txt

View File

@@ -0,0 +1 @@
["topisto42","UnnaxPayments","aureliusdrusus","solacedotcom","omgbtc","ohiobitcoin","LogicScience","redunisproject","Cryptocracy2020","fullstache","callblockapp","marketranger","TheCryptodamus","crypt0co","CryptoassetsUSA","Nadeem_nadi797","cryptomoneyz","BaseCyberSec","Tweetsintoabyss","anthkell98","grattonboy","mac_a_dam","devnullius","123wolfArmy","03018333860","JeffinkoGuru","BitJob_Team","rugigana","Crypto_info321","cointopic_","Chef_JeanPierre","Cienencom","btcltcdigger","AdzCoin_Gift","treyptrsn","n2yolo","SHL0M0ABADD0N","EdwardCulligan","promote_crypto","TheFutureShift","ErickCoval","RIMCorpPK","arhiezvanhoute1","ttoff85","actu_fintech","BeautyBubble","PDX_Trader","Yasirperdesi","cre8hyperledger","Thurse8","cre8capital","icobountyprogs","rob67803423","AphexTwin4ever"]

View File

@@ -0,0 +1,88 @@
<?php
use Abraham\TwitterOAuth\TwitterOAuth;
// Twitter OAuth Settings:
/* TOPISTO */
define('CONSUMER_KEY', 'HBInbm93bM80z86XVJ34rtjxO');
define('CONSUMER_SECRET', 'zpdSp8yv9R2VODgPRA0RZbiO7VE8vSPNLVNg9zI0HjWnJKADO8');
define('ACCESS_TOKEN', '315679287-EjINhav5VbJPscb4h9pw3WwveeeX0ShpnIjcawDe');
define('ACCESS_TOKEN_SECRET', 'SIFKfPYEoIdlAyeQKVS3y067uNFuLpy013wRycJ8VxNcd');
/* R. Topisto
define('CONSUMER_KEY', '9Ie6CjwM5eZSQu5Xnbel4PBqm');
define('CONSUMER_SECRET', 'pI4ha5gW7Lft6Lg5xP7nH49Yqbm8PwLn1EP8D1qKg1q0SYd5t2');
define('ACCESS_TOKEN', '840479603143630849-c3xFLJFvo77ubP1njoXHpFu9LQqKLR8');
define('ACCESS_TOKEN_SECRET', 'EW4Zi10cQnNfoOunnEF1svJ3omz223U57G6KuYo5ZZ2Ls');
*/
define('TWITTER_WIDTH', 880);
define('TWITTER_HEIGHT', 440);
class twitter
{
public static function tweet($message, $media='')
{
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$content = $twitter->get('account/verify_credentials');
if ($twitter->getLastHttpCode() !== 200) return FALSE;
$parameters = array("status" => $message);
if (($media != NULL)&&($media != ''))
{
$imageMedia = $twitter->upload('media/upload', array('media' => $media));
if ($twitter->getLastHttpCode() !== 200) return FALSE;
$parameters = array(
"status" => $message,
"media_ids" => $imageMedia->media_id_string);
}
$statuses = $twitter->post("statuses/update", $parameters);
if ($twitter->getLastHttpCode() !== 200) return FALSE;
return TRUE;
}
public static function thanksRetweet()
{
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$content = $twitter->get('account/verify_credentials');
if ($twitter->getLastHttpCode() !== 200) return FALSE;
$results = $twitter->get('statuses/retweets_of_me');
if ($twitter->getLastHttpCode() !== 200) return FALSE;
/* TO DO */
return TRUE;
}
public static function thanksFollowers()
{
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$content = $twitter->get('account/verify_credentials');
if ($twitter->getLastHttpCode() !== 200) return FALSE;
$results = $twitter->get('followers/list');
if ($twitter->getLastHttpCode() !== 200) return FALSE;
$followers = json_decode(file_get_contents('followers.json'));
foreach($results->users as $user)
if (!in_array($user->screen_name, $followers))
{
$parameters = array("status" => '@'.$user->screen_name.' thanks following me !');
$followers[] = $user->screen_name;
$statuses = $twitter->post("statuses/update", $parameters);
if ($twitter->getLastHttpCode() !== 200) return FALSE;
break; // Un à la fois ...
}
file_put_contents('followers.json', json_encode($followers));
return TRUE;
}
}
?>

View File

@@ -0,0 +1,82 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// --- Drawing the block as a Treemap
// --- Tweet it
// ---
// ---
// --- La config globale
// ---
require_once '../../global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
// ---
// --- Internal dependances
// ---
require_once APP_PATH.'/blockchain/inc/block.php';
require 'inc/twitter.php';
$midnight = strtotime('today midnight');
$methode='spline';
if (isset($argv[3])) $methode=$argv[3];
$block_hash = $argv[1];
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
// ---
// --- Remercier les followers ?
// ---
// twitter::thanksFollowers();
$image_file=DATA_PATH."/$methode/".$argv[1].'.png';
if (file_exists($image_file))
{
$image_origine = imagecreatefrompng($image_file);
$image_twitter = imagecreatetruecolor(TWITTER_WIDTH, TWITTER_HEIGHT);
$fond = imagecolorallocate($image_twitter, 255, 255, 255);
//imagecolortransparent($image_twitter, $fond);
imagefilledrectangle($image_twitter, 0, 0, TWITTER_WIDTH, TWITTER_HEIGHT, $fond);
$ratio = TWITTER_HEIGHT / imagesy($image_origine);
$new_width = $ratio * imagesx($image_origine);
$xpos = floor((TWITTER_WIDTH - $new_width) / 2);
$ypos = 0;
imagecopyresized($image_twitter, $image_origine, $xpos, $ypos, 0, 0, $new_width, TWITTER_HEIGHT, imagesx($image_origine), imagesy($image_origine));
$image_file = DATA_PATH."/emptybot/".$argv[1].'.png';
imagepng($image_twitter,$image_file);
// ---
// --- Un petit peu de stéganographie ...
// ---
/* Ca fait des fichiers trop gros !
$processor = new KzykHys\Steganography\Processor();
$image = $processor->encode($image_file, 'TOPISTO is making art with block '.$the_block->height);
$image->write($image_file);
*/
// ---
// --- Tweet
// ---
$tweet = "Lucky One on #bitcoin #blockchain 's".PHP_EOL;
$tweet .= "Someone put an empty block ...".PHP_EOL;
$tweet .= "And get the reward for it !".PHP_EOL;
$tweet .= "Block height : ".$the_block->height.PHP_EOL;
$tweet .= "[ See more on www.topisto.net ]";
$success = twitter::tweet($tweet, $image_file);
}
?>

38
twitter/emptybot/robot.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
flag=$TMP_PATH/emptybot_bot.flag
if [ -f $flag ];
then
echo "empty_bot is already running !"
exit 0
fi
touch $flag
cd $APPS_PATH/twitter/emptybot
#
# Se lancer pour un tweet sur un block unique
#
BLOCK_LINE=`grep LAST $DATA_PATH/block_list.txt`
BLOCK_HASH=`echo ${BLOCK_LINE} | awk '{print $2}'`
BLOCK_NAME=`echo ${BLOCK_LINE} | awk '{print $1}'`
BLOCK_HEIGHT=`echo ${BLOCK_LINE} | awk '{print $3}'`
BLOCK_SIZE=`echo ${BLOCK_LINE} | awk '{print $4}'`
if [ $BLOCK_SIZE -eq 1 ]
then
if [ -f $DATA_PATH/hasard/$BLOCK_HASH.png ]
then
if [ ! -f $DATA_PATH/emptybot/$BLOCK_HASH.png ]
then
echo Tweet EmptyBlock for $BLOCK_HASH
echo $BLOCK_LINE >> $DATA_PATH/emptybot/list.txt
php robot.php $BLOCK_HASH $BLOCK_NAME hasard $BLOCK_HEIGHT
# Don't TWEET it again ...
touch $DATA_PATH/twitterbot/$BLOCK_HASH
fi
fi
fi
rm -f $flag

View File

@@ -0,0 +1 @@
["CryptoPressNews","ryushi_w","JoelPlatoon"]

View File

@@ -69,7 +69,7 @@ if (file_exists($image_file))
// ---
// --- Tweet
// ---
$tweet = "#bitcoin #blockchain 's".PHP_EOL;
$tweet = "#computerart :".PHP_EOL."#bitcoin #blockchain 's".PHP_EOL;
$tweet .= $argv[2]." Block, Height : ".$the_block->height.PHP_EOL;
$tweet .= "[ See more on www.topisto.net ]";
$success = twitter::tweet($tweet, $image_file);

View File

@@ -14,18 +14,17 @@ cd $APPS_PATH/twitter/twitterbot
#
# Tweet pour un assemblage de hash
#
for fichier in `ls $DATA_PATH/hashes2hashes/*.png`
for fichier in `ls -tr $DATA_PATH/hashes2hashes/*.png`
do
BLOCK=`basename $fichier .png`
if [ ! -f $DATA_PATH/twitterbot/assemblage_$BLOCK ]
then
php robot.php $BLOCK CONFIRMED hashes2hashes
touch $DATA_PATH/twitterbot/assemblage_$BLOCK
rm -f $flag
exit 0
fi
BLOCK_HASH=`basename $fichier .png`
done
if [ 5 -gt $((RANDOM % 100)) ]
then
php robot.php $BLOCK_HASH CONFIRMED hashes2hashes
touch $DATA_PATH/twitterbot/$BLOCK_HASH
fi
#
# Se lancer pour un tweet sur un block unique
#