按标签的点击率来设置标签字体的大小和 颜色
本程序没有考虑程序性能和函数封装。。。只想表达这个算法
具体代码如下:
php
function showTag($cur=47,$tag="美女和野兽"){
$maxSize=300;$minSize=30;//maxSize为标签字体最大大小,minSize为标签最小大小 按百分比
$max=100;$min=8;//max为最多标签点击数 min为最少点击数 cur为当前标签当前点击数
$tagColor=$tagSize=$minSize;#tagColor为标签最终颜色,tagsize为标签最终字体大小
$tagSize=@(float)($cur-$min)/($max-$min)*($maxSize-$minSize);
$colors=array("0.2"=>"#333333","0.4"=>"#0033CC","0.6"=>"#660099","0.8"=>"#00FFFF","1"=>"#FF0000");
//color为存放颜色的数组,按百分百存放,例如在0-0.2之间的color1
$colorkeys=array_keys($colors);
$select=(float)($cur-$min)/($max-$min);
$len=count($colorkeys);
$i=0;$j=$len-1;
while($i$j){//二分查找
$index=($i+$j)/2;
if($select>=(float)$colorkeys[$index] && $select(float)$colorkeys[$index+1]) break;
elseif($select(float)$colorkeys[$index]) $j--;
elseif($select>(float)$colorkeys[$index]) $i++;
elseif($select==(float)$colorkeys[$index+1]) break;
else break;
}
$tagColor=$colors[$colorkeys{($i+$j)/2}];
echo "$tag ";
}
showTag(90);showTag(66,"股民");showTag(50,"我的爱情");showTag(100,"MM");
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
