Outils pour utilisateurs

Outils du site


php:machins_qui_tournent

Ceci est une ancienne révision du document !


Machins Qui Tournent

Code PHP qui génère un ficher SVG minimaliste, de taille 1920×1080, avec de petits rectangles qui tournent. Avec une résolution d'écran de 1920×1080 et en entrant en mode plein écran du navigateur (touche F11), ça fait un sympathique écran de veille :D

exemple

generateur.php
<?php
header( "Content-type: image/svg+xml" );
echo '<?xml version="1.0" encoding="UTF-8" standalone="no"?>';
?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="1900"
   height="1060"
	style="background: black">
  <g>
<?php
echo '<rect style="fill:#000000;fill-opacity:1" width="100%" height="100%" x="0" y="0" />';
function posx(){$rand=rand(0, 1920);return $rand;} // position horizontale
function posy(){$rand=rand(0, 1080);return $rand;} // position verticale
function long(){$rand=rand(1, 2);return $rand;} // longeur des rectangles
function col(){$color=substr(md5(rand()), 0, 6);return $color;} // couleur aléatoire
function opa(){$color=rand(1, 9);return $color;} // opacité 0.1 à 0.9
function hei(){$color=rand(1, 5);return $color;} // largeur des rectangles
function speed(){$color=rand(5, 120);return $color;} // temps de rotation en secondes
$iter=0;
while($iter!=300) // nombre d'itérations (évitez d'aller au delà de 500 si vous avez un petit CPU)
	{
	echo '<rect style="fill:#'.col().';fill-opacity:0.'.opa().'" width="'.long().'" height="'.hei().'" x="'.posx().'" y="'.posy().'"><animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 960 540" to="-360 960 540" dur="'.speed().'s" repeatCount="indefinite"/> </rect>';
	echo '<rect style="fill:#'.col().';fill-opacity:0.'.opa().'" width="'.long().'" height="'.hei().'" x="'.posx().'" y="'.posy().'"><animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 960 540" to="360 960 540" dur="'.speed().'s" repeatCount="indefinite"/> </rect>';
	//  300 rectangles par sens de rotation :D
	$iter++;
	}
?>
  </g>
</svg>
php/machins_qui_tournent.1361302973.txt.gz · Dernière modification : 2013-02-19 20:42 (modification externe)