| 
 | 
	
 
 
  PHP生成热点图,有两大要点: 
  1. 点需要有模糊效果。 
  2. 点越多,颜色需要越鲜艳。 
  借用http://www.labsmedia.com/clickheat/的算法,第一点比较好理解,第二点可以把RGB值和画图板里的颜色对比。 
  clickheat--version1: 
 
<?php 
define('CLICKHEAT_LOW_COLOR', 0);  
define('CLICKHEAT_HIGH_COLOR', 255); 
define('CLICKHEAT_GREY_COLOR', 240); 
define('CLICKHEAT_ALPHA', 60); 
for ($i = 0; $i < 110; $i++) 
{ 
/** Red */ 
if ($i < 10) 
{ 
$red = CLICKHEAT_GREY_COLOR + (CLICKHEAT_LOW_COLOR - CLICKHEAT_GREY_COLOR) * $i / 10; 
} 
elseif ($i < 60) 
{ 
$red = CLICKHEAT_LOW_COLOR; 
} 
elseif ($i < 85) 
{ 
$red = CLICKHEAT_LOW_COLOR + (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - 60) / 35; 
} 
else 
{ 
$red = CLICKHEAT_HIGH_COLOR; 
} 
/** Green */ 
if ($i < 10) 
{ 
$green = CLICKHEAT_GREY_COLOR + (CLICKHEAT_LOW_COLOR - CLICKHEAT_GREY_COLOR) * $i / 10; 
} 
elseif ($i < 35) 
{ 
$green = CLICKHEAT_LOW_COLOR + (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * $i / 35; 
} 
elseif ($i < 85) 
{ 
$green = CLICKHEAT_HIGH_COLOR; 
} 
else 
{ 
$green = CLICKHEAT_HIGH_COLOR - (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - 85) / 35; 
} 
/** Blue */ 
if ($i < 10) 
{ 
$blue = CLICKHEAT_GREY_COLOR + (CLICKHEAT_HIGH_COLOR - CLICKHEAT_GREY_COLOR) * $i / 10; 
} 
elseif ($i < 35) 
{ 
$blue = CLICKHEAT_HIGH_COLOR; 
} 
elseif ($i < 60) 
{ 
$blue = CLICKHEAT_HIGH_COLOR - (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - 35) / 35; 
} 
else 
{ 
$blue = CLICKHEAT_LOW_COLOR; 
} 
echo "R:".(int)$red.";    G:".(int)$green.";    B:".(int)$blue; 
echo "<br />"; 
} 
?> 
 
  clickheat--version18: 
 
<?php 
$colors = array(50, 70, 90, 110, 120); 
$low = 0; 
$high = 255; 
$grey = 240; 
for ($i = 0; $i < 128; $i++) 
{ 
/** Red */ 
if ($i < $colors[0]) 
{ 
$R = $grey + ($low - $grey) * $i / $colors[0]; 
} 
elseif ($i < $colors[2]) 
{ 
$R = $low; 
} 
elseif ($i < $colors[3]) 
{ 
$R = $low + ($high - $low) * ($i - $colors[2]) / ($colors[3] - $colors[2]); 
} 
else 
{ 
$R = $high; 
} 
/** Green */ 
if ($i < $colors[0]) 
{ 
$G = $grey + ($low - $grey) * $i / $colors[0]; 
} 
elseif ($i < $colors[1]) 
{ 
$G = $low + ($high - $low) * ($i - $colors[0]) / ($colors[1] - $colors[0]); 
} 
elseif ($i < $colors[3]) 
{ 
$G = $high; 
} 
else 
{ 
$G = $high - ($high - $low) * ($i - $colors[3]) / (127 - $colors[3]); 
} 
/** Blue */ 
if ($i < $colors[0]) 
{ 
$B = $grey + ($high - $grey) * $i / $colors[0]; 
} 
elseif ($i < $colors[1]) 
{ 
$B = $high; 
} 
elseif ($i < $colors[2]) 
{ 
$B = $high - ($high - $low) * ($i - $colors[1]) / ($colors[2] - $colors[1]); 
} 
else 
{ 
$B = $low; 
} 
echo "R:".(int)$R.";    G:".(int)$G.";    B:".(int)$B; 
echo "<br />"; 
} 
?> |   
 
 
 
 | 
  
 |