<script>ec(2);</script>
按标签的点击率来设置标签字体的大小和 颜色
本程序没有考虑程序性能和函数封装。。。只想表达这个算法
具体代码如下:
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");
?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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
How to fix KB5055523 fails to install in Windows 11?
4 weeks agoByDDD
How to fix KB5055518 fails to install in Windows 10?
4 weeks agoByDDD
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks agoByDDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
How to fix KB5055612 fails to install in Windows 10?
3 weeks agoByDDD

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
