1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00
Tims-Chat/file/lib/util/ChatUtil.class.php

40 lines
1.2 KiB
PHP
Raw Normal View History

2011-12-05 15:53:12 +00:00
<?php
2011-12-05 17:00:03 +00:00
namespace wcf\util;
2011-12-05 15:53:12 +00:00
/**
* Chat utilities
*
* @author Tim Düsterhus
* @copyright 2010-2011 Tim Düsterhus
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @package timwolla.wcf.chat
* @subpackage util
*/
class ChatUtil {
/**
* Creates a gradient out of two colors represented by an integer.
* The first byte is red, the second byte is green, the third one is blue.
* The numbers can be easily expressed in hexadecimal notation: 0xFF0000 being red.
*
* @param string $string
* @param integer $start
* @param integer $end
* @returen string
*/
public static function gradient($string, $start, $end) {
$string = str_split($string);
2011-12-10 13:25:36 +00:00
$r = (int) ((($start & 0xFF0000) - ($end & 0xFF0000)) / (count($string) - 1));
$g = (int) ((($start & 0x00FF00) - ($end & 0x00FF00)) / (count($string) - 1));
$b = (int) ((($start & 0x0000FF) - ($end & 0x0000FF)) / (count($string) - 1));
2011-12-05 15:53:12 +00:00
$result = '';
for ($i = 0, $max = count($string); $i < $max; $i++) {
2011-12-10 13:25:36 +00:00
$result .= '<span style="color:rgb('.(($start & 0xFF0000) - $i * $r).','.(($start & 0x00FF00) - $i * $g).','.(($start & 0x0000FF) - $i * $b).')">'.$string[$i].'</span>';
2011-12-05 15:53:12 +00:00
}
return $result;
}
2011-12-10 13:25:36 +00:00
2011-12-05 15:53:12 +00:00
}