Instantly share code, notes, and snippets.

# pieman72/esheep.php

Created Jul 2, 2014
E-Sheep! They're what computers dream about.
 >5) + 1]; \$shape = (\$data>>3)%4; \$thick = (\$data>>1)%4 + 2; \$fill = (bool)(\$data%2); \$x = round((((\$data*\$index)%256)%16)*\$WIDTH / 15.0); \$y = round((((\$data*\$index)%256)>>4)*\$HEIGHT / 15.0); \$angle = ((\$data*\$index)%256)*2.0*M_PI/255.0; \$size = ((\$data*\$index)%256)*30.0/255.0 + 20; // Depending on the shape, do different drawing things imagesetthickness(\$IMG, \$thick); switch(\$shape){ case 0: // Line \$rise = sin(\$angle)*(\$WIDTH+\$HEIGHT); \$run = cos(\$angle)*(\$WIDTH+\$HEIGHT); imageline(\$IMG, \$x-\$run, \$y-\$rise, \$x+\$run, \$y+\$rise, \$color); break; case 1: // Square \$rise = sin(\$angle)*\$size; \$run = cos(\$angle)*\$size; \$points = array( \$x-\$run, \$y-\$rise ,\$x+\$rise, \$y-\$run ,\$x+\$run, \$y+\$rise ,\$x-\$rise, \$y+\$run ); if(\$fill){ imagefilledpolygon(\$IMG, \$points, 4, \$color); }else{ imagepolygon(\$IMG, \$points, 4, \$color); } break; case 2: // Circle if(\$fill){ imagefilledellipse(\$IMG, \$x, \$y, \$size, \$size, \$color); }else{ imageellipse(\$IMG, \$x, \$y, \$size, \$size, \$color); } break; case 3: // Triangle \$points = array(); for(\$a=0; \$a<3; ++\$a){ \$angle += 2.0*M_PI/3; \$rise = sin(\$angle)*\$size; \$run = cos(\$angle)*\$size; \$points[] = \$x-\$run; \$points[] = \$y-\$rise; } if(\$fill){ imagefilledpolygon(\$IMG, \$points, 3, \$color); }else{ imagepolygon(\$IMG, \$points, 3, \$color); } break; } } // Pick colors based on triad scheme \$h = hexdec(substr(\$key, 0, 2)); \$s = hexdec(substr(\$key, 2, 2)); \$l = hexdec(substr(\$key, 4, 2)); for(\$a=0; \$a<3; ++\$a){ for(\$b=0; \$b<3; ++\$b){ generateHSL(\$h, \$s, (\$l+70*((\$b+1)%3-1))%256); } \$h = (\$h+85)%256; } // Fill with background color imagefilledrectangle(\$IMG, 0, 0, \$WIDTH, \$HEIGHT, \$COLORS[0]); // Draw 17 shapes for(\$a=0; \$a<17; ++\$a){ drawShape(hexdec(substr(\$key, \$a*2+6, 2)), \$a); } // Output the image contents header('Last-Modified: '.date('r', strtotime('-100 years'))); header('Cache-Control: max-age=315360000'); header('Expires: '.date('r', strtotime('+10 years'))); header('Content-Type: image/png'); imagepng(\$IMG, null, 9); imagedestroy(\$IMG);