Skip to content

Instantly share code, notes, and snippets.

@AntoineAugusti
Created April 7, 2012 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntoineAugusti/2327331 to your computer and use it in GitHub Desktop.
Save AntoineAugusti/2327331 to your computer and use it in GitHub Desktop.
<?php
/*
* Test des fonctions random
* Copyleft 2012 - Antoine AUGUSTI - INSA de Rouen
* www.antoine-augusti.fr - antoine@augusti.fr
*
*/
header("Content-type: image/png");
// Notre taille d'image finale
$sizex = 800;
$sizey = 400;
// On crée une image noire
$img = imagecreatetruecolor($sizex,$sizey);
// Permet de colorer un pixel en blanc
$ink = imagecolorallocate($img,255,255,255);
// Création de l'image de gauche, test avec la fonction rand
// On se déplace horizontalement
for($i=0;$i<$sizex/2;$i++) {
// On est sur un point x, on balaie tout l'axe y en coloriant de manière aléatoire des pixels blancs
for($j=0;$j<$sizey;$j++) {
// Colorie en blanc aléatoirement un pixel sur la partie gauche de l'image avec une coordonnée (x,y) générée aléatoirement par rand
imagesetpixel($img, rand(1,$sizex/2), rand(1,$sizey), $ink);
}
}
// Création de l'image de droite, test avec la fonction mt_rand
// On se déplace horizontalement
for($i=$sizex/2;$i<$sizex;$i++) {
// On est sur un point x, on balaie tout l'axe y en coloriant de manière aléatoire des pixels blancs
for($j=0;$j<$sizey;$j++) {
// Colorie en blanc aléatoirement un pixel sur la partie droite de l'image avec une coordonnée (x,y) générée aléatoirement par mt_rand
imagesetpixel($img, mt_rand($sizex/2,$sizex), mt_rand(1,$sizey), $ink);
}
}
// Affiche l'image
imagepng($img);
// Libère la mémoire associée à l'image
imagedestroy($img);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment