Created
March 7, 2012 11:11
-
-
Save nerevar/1992561 to your computer and use it in GitHub Desktop.
Draws Yin-Yang in ASCII-mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Draws Yin-Yang in ASCII-mode | |
Usage: "php yin.php <size>" | |
Size must be greater then 10 | |
Author Roman Rybalchenko mail@nerevar.ru | |
http://dumpz.org/84832/ | |
13.09.2011 | |
*/ | |
define('EMPTY_CELL', '.'); | |
define('BLACK_CELL', '*'); | |
define('WHITE_CELL', 'x'); | |
if (empty($argv[1]) || intval($argv[1]) < 11) { | |
die ("\nUsage: 'php ascii.php <size>' \nSize > 10\n"); | |
} | |
$size = intval($argv[1]); | |
// generate map | |
$map = array(); | |
for ($i=0; $i<=$size; $i++) { | |
$map[$i] = array(); | |
for ($j=0; $j<=$size; $j++) { | |
$map[$i][$j] = EMPTY_CELL; | |
} | |
} | |
// radius | |
$r = $size / 2; | |
$r2 = $size / 4; | |
$r4 = $size / 8; | |
// center | |
$c_x = $size / 2; | |
$c_y = $size / 2; | |
// fill left part with white cells | |
for ($i=1; $i<=$size; $i++) { | |
for ($j=1; $j<=$size / 2; $j++) { | |
if (sqrt( ($i-$c_y)*($i-$c_y) + ($j-$c_x)*($j-$c_x) ) <= $r) { | |
$map[$i][$j] = WHITE_CELL; | |
} | |
} | |
} | |
// fill right part with black cells | |
for ($i=1; $i<=$size; $i++) { | |
for ($j=$size / 2 + 1; $j<=$size; $j++) { | |
if (sqrt( ($i-$c_y)*($i-$c_y) + ($j-$c_x)*($j-$c_x) ) <= $r) { | |
$map[$i][$j] = BLACK_CELL; | |
} | |
} | |
} | |
// fill small top circle with black cells | |
$c_y = $size / 4; | |
for ($i=1; $i<=$size; $i++) { | |
for ($j=1; $j<=$size; $j++) { | |
if (sqrt( ($i-$c_y)*($i-$c_y) + ($j-$c_x)*($j-$c_x) ) <= $r2) { | |
$map[$i][$j] = BLACK_CELL; | |
} | |
} | |
} | |
// fill small bottom circle with white cells | |
$c_y = $size / 4 * 3; | |
for ($i=1; $i<=$size; $i++) { | |
for ($j=1; $j<=$size; $j++) { | |
if (sqrt( ($i-$c_y)*($i-$c_y) + ($j-$c_x)*($j-$c_x) ) <= $r2) { | |
$map[$i][$j] = WHITE_CELL; | |
} | |
} | |
} | |
// fill the smallest top circle with white cells | |
$c_y = $size / 4; | |
for ($i=1; $i<=$size; $i++) { | |
for ($j=1; $j<=$size; $j++) { | |
if (sqrt( ($i-$c_y)*($i-$c_y) + ($j-$c_x)*($j-$c_x) ) <= $r4) { | |
$map[$i][$j] = WHITE_CELL; | |
} | |
} | |
} | |
// fill the smallest bottom circle with black cells | |
$c_y = $size / 4 * 3; | |
for ($i=1; $i<=$size; $i++) { | |
for ($j=1; $j<=$size; $j++) { | |
if (sqrt( ($i-$c_y)*($i-$c_y) + ($j-$c_x)*($j-$c_x) ) <= $r4) { | |
$map[$i][$j] = BLACK_CELL; | |
} | |
} | |
} | |
// print map | |
for ($i=1; $i<=$size; $i++) { | |
for ($j=1; $j<=$size; $j++) { | |
print $map[$i][$j]; | |
} | |
print "\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment