Skip to content

Instantly share code, notes, and snippets.

@elzup
Created September 23, 2014 07:26
Show Gist options
  • Save elzup/4095e1af6b3e4ea7926a to your computer and use it in GitHub Desktop.
Save elzup/4095e1af6b3e4ea7926a to your computer and use it in GitHub Desktop.
<?php
define('CIRCLE_D', 36);
for ($k = 0; $k < 100; $k++):
list($px, $py) = get_rand_circle(CIRCLE_D / 2);
for ($i = 0; $i < CIRCLE_D;$i++) {
for ($j = 0; $j < CIRCLE_D;$j++) {
if ($i == $py && $j == $px) {
echo '=';
}
else {
echo is_circle(CIRCLE_D / 2 - $i, CIRCLE_D / 2 - $j, CIRCLE_D / 2) ? ' ' : '*';
}
}
echo PHP_EOL;
}
endfor;
function is_circle($x, $y, $r) {
return (pow($x, 2) + pow($y, 2) < ($r * $r));
}
function get_rand_circle($r)
{
$i = 0;
do {
$px = rand(0, $r * 2);
$py = rand(0, $r * 2);
if ($i++ > 100) return;
} while(!is_circle($r - $px, $r - $py, $r));
return array($px, $py);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment