Zend - The PHP Company




HTML

Add Code


MDC_ColorChange  

Type: class
Added by: wolframschlich
Entered: 19/02/2001
Last modified: 02/12/2000
Rating: - (fewer than 3 votes)
Views: 4028
rotatory returns one of a set of previously defined colors. it's a class, so you can have as many differently colored (e.g.) tables as you like on a page.


<?php

    
/*
    
        -------------------------------
        Copyleft by
        
        Wolfram Schlich
        work@schlich.org
        
        Michel Development & Consulting
        Adenauerallee 113
        D-56626 Bonn, Germany
        -------------------------------
        
        VERSION:
        --------
        <current> :P
        --------
        
        DESCRIPTION:
        ------------
        rotatory returns one of a set of colors
        ------------
        
        USAGE (EXAMPLE):
        ----------------
        $mycolor = new MDC_ColorChange;
        
        $mycolor->add ('#ff0000');
        $mycolor->add ('#ffcc00');
        $mycolor->add ('#ffff00');
        $mycolor->add ('#ccff00');
        $mycolor->add ('#00ff00');
        $mycolor->add ('#00ffcc');
        $mycolor->add ('#00ffff');
        $mycolor->add ('#00ccff');
        $mycolor->add ('#0000ff');
        $mycolor->add ('#cc00ff');
        $mycolor->add ('#ff00ff');
        $mycolor->add ('#ff00cc');
        $mycolor->add ('black');
        
        for ($i = 0; $i < $mycolor->get_colorcount(); $i++) {
            echo ('<font color="'.$mycolor->get_color().'">###</font> - '.$i.'<br>'."n");
        }
        ----------------

    */
    
    
class MDC_ColorChange {

        var 
$color;
        var 
$last_index = -1/* start-value */

        /* add a color to the array*/
        
function add ($color_code) {
            
$this->color[] = $color_code;
        }
        
        
/* get next color from the array */
        
function get_color () {
            
$index_count count ($this->color);
            if (
$this->last_index $index_count 2) {
                
$index 0;
            }
            else {
                
$index $this->last_index 1;
            }
            
$this->last_index $index;
            return 
$this->color[$index];
        }

        
/* count the colors in the array */
        
function get_colorcount () {
            return 
count ($this->color);
        }
    }

?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories