How generate dynamic gradient effect in php

For generate dynamic gradient color in php just copy and paste below code into your file wherever you want to use..


<?php
function random() {
  return (float)rand()/(float)getrandmax();
}
function getRandomArbitrary() {
    $min = 0;
    $max =0.5;
    return random() * ($max - $min) + $min;
}
 $gradientSpeed = 0.002;
function updateGradient()
{
    $min = 0;
$max =0.5;
    $colors =  array(
  [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256),floor(getRandomArbitrary() * 256) ],
  [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) ],
  [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) ],
  [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256), floor(getRandomArbitrary() * 256) ],
  [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) ,floor(getRandomArbitrary() * 256) ],
  [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) ,floor(getRandomArbitrary() * 256) ],
  [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) ,floor(getRandomArbitrary() * 256) ],
  [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) ,floor(getRandomArbitrary() * 256) ],
  [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) ,floor(getRandomArbitrary() * 256) ],
  [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) ,floor(getRandomArbitrary() * 256) ]
  );
$cl_length = count($colors); 
 $color_00 = $colors[floor(random()*$cl_length)];
 $color_01 = $colors[floor(random()*$cl_length)];
 $color_10 = $colors[floor(random()*$cl_length)];
 $color_11 = $colors[floor(random()*$cl_length)];
 $r1 = round($color_00[0] +  $color_01[0]);
 $g1 = round($color_00[1] + $color_01[1]);
 $b1 = round($color_00[2] + $color_01[2]);
 $color1 = "rgb(".$r1.",".$g1.",".$b1.")";
 $r2 = round($color_10[0] + $color_11[0]);
 $g2 = round($color_10[1] + $color_11[1]);
 $b2 = round($color_10[2] + $color_11[2]);
 $color2 = "rgb(".$r2.",".$g2.",".$b2.")";
  return 'background: -webkit-gradient(linear, left top, right top, from('.$color1.'), to('.$color2.'));background: -moz-linear-gradient(left, '.$color1.' 0%, '.$color2.' 100%)';

?>
<!DOCTYPE html>
<html >
  <head>
    <meta charset="UTF-8">
    <title>Php Generate dynamic Gradient</title>
        <style>
        #gradient_box
        {
          width: 100%;
          height: 800px;
          padding: 0px;
          margin: 0px;
        }
        </style>
  </head>
  <body>
    <html>
  <head>
  </head>
  <body>
    <div id="gradient_box"  style="<?php echo updateGradient(); ?>">
 </body>
</html>
  </body>
</html>

Comments

Popular posts from this blog

How to add image option in nav menu in wordpress

How to add a custom email functionality in woocommerce,wordpress for example new email template for shipping order

How to change user id on checkout page for assign order to different user in woocommerce wordpress