$b)$u=$b; return $u; } function gauss() { // N(0,1) // returns random number with normal distribution: // mean=0 // std dev=1 // auxilary vars $x=random_0_1(); $y=random_0_1(); // two independent variables with normal distribution N(0,1) $u=sqrt(-2*log($x))*cos(2*pi()*$y); $v=sqrt(-2*log($x))*sin(2*pi()*$y); // i will return only one, couse only one needed return $u; } function gauss_ms($m=0.0,$s=1.0) { // N(m,s) // returns random number with normal distribution: // mean=m // std dev=s return gauss()*$s+$m; } function random_0_1() { // auxiliary function // returns random number with flat distribution from 0 to 1 return (float)rand()/(float)getrandmax(); } function get_tag_data() { $db= mysql_connect("xxx", "xxx", "xxx"); mysql_select_db("xxx",$db); $result = mysql_query("SELECT * FROM tags WHERE type='text' GROUP BY tag ORDER BY count DESC"); while($row = mysql_fetch_array($result)) { $arr[$row['tag']] = $row['count']; //creiamo il nostro array } mysql_close(); return $arr; } function get_tag_cloud() { //definiamo le dimensioni minime e massime del font $width=50; $height=100; $x_offset=0; $y_offset=10; $min_font_size = 8; $max_font_size = 20; //Recuperiamo l'array ordinato $tags = get_tag_data(); //calcoliamo la minima e la massima occorrenza dei tag $minimum_count = min(array_values($tags)); $maximum_count = max(array_values($tags)); //ne calcolo la differenza $spread = $maximum_count - $minimum_count; if($spread == 0) { $spread = 1; //controllo inserito per evitare errori del tipo divisione per zero } $cloud_html = ''; $cloud_tags = array(); //entriamo nel cuore della rappresentazione del tag cloud foreach ($tags as $tag => $count) { $level=$count/$spread*100; $x=randGauss($width/2 ,$width); $y=randGauss($height/2 ,$height); $x2=randGauss($width/4 ,$width/2); $y2=randGauss($height/4 ,$height/2); $size = $min_font_size + ($count - $minimum_count) * ($max_font_size - $min_font_size) / $spread; $alpha = 0.2 + ($count - 1)/ $spread; //in questo modo si calcola la dimensione del font in modo porporzionale all'occorrenza del tag if($level<70){ $x=$x_offset+$x; if($y>$width+floor($size)*strlen($tag)) $y=$y_offset+$y-floor($size)*strlen($tag); else $y=$y_offset+$y; }else{ $x2=$x_offset+$x2; if($y2>$width+floor($size)*strlen($tag)) $y=$y_offset+$y2-floor($size)*strlen($tag); else $y=$y_offset+$y2; } $cloud_tags[] = '
' . htmlspecialchars(stripslashes($tag)) . '
'; } $cloud_html = join("\n", $cloud_tags) . "\n"; return $cloud_html; } ?>