Artykuły na każdy temat
<!DOCTYPE html>
<html lang="pl" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Drobny projekt inspiracji - CapaciousCore</title>
<style>
* { margin: 0; padding: 0; line-height: 0 }
body { margin: 0 auto; background-color: #D2D2D2; background-image: linear-gradient(-45deg, rgba(255, 255, 255, .2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, .2) 75%, transparent 75%, transparent); -webkit-background-size: 50px 50px; -moz-background-size: 50px 50px; background-size: 50px 50px }
table { border-collapse: collapse; border-spacing: 0; }
p { line-height: 1 }
ol { list-style-type: none }
li, p { margin: 10px; padding: 10px; height: 20px; line-height: 20px; text-align: center; background: #FFF; border-radius: 10px; box-shadow: 0 0 1px #000000 inset; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px }
a { color: #000; text-decoration: none }
li:hover { background: #4F7327 }
</style>
</head>
<body>
<?php
if(!isset($_GET['id']) || empty($_GET['id']))
{
echo '<ol>';
for($h = 1; $h < 15; ++$h)
{
echo '<li><a href="?id='.$h.'">Propozycja '.$h.'</a></li>';
}
echo '</ol>';
footer();
}
else
{
$id = (int)$_GET['id'];
if($id < 1 || $id > 14)
{
echo '<p>Wykryto manipulacje ID</p>';
footer();
}
}
// Circle
$objects[0] = $objects[34] = array_fill(13, 9, true);
$objects[1] = $objects[33] = array_fill(10, 3, true);
$objects[1] += $objects[33] += array_fill(22, 3, true);
$objects[2] = $objects[32] = array_fill(8, 3, true);
$objects[2] += $objects[32] += array_fill(24, 3, true);
$objects[3] = $objects[31] = array_fill(7, 2, true);
$objects[3] += $objects[31] += array_fill(26, 2, true);
$objects[4] = $objects[30] = array(6 => true, 28 => true);
$objects[5] = $objects[29] = array(5 => true, 29 => true);
$objects[6] = $objects[28] = array(4 => true, 30 => true);
$objects[7] = $objects[27] = array(3 => true, 31 => true);
$objects[8] = $objects[26] = array_fill(2, 2, true);
$objects[8] += $objects[26] += array_fill(31, 2, true);
$objects[9] = $objects[25] = array(2 => true, 32 => true);
$objects[10] = $objects[24] = array_fill(1, 2, true);
$objects[10] += $objects[24] += array_fill(32, 2, true);
$objects[11] = $objects[12] = $objects[23] = $objects[22] = array(1 => true, 33 => true);
for($y = 13; $y < 22; ++$y)
{
$objects[$y][0] = $objects[$y][34] = true;
}
// Eyes
$objects[7] += array(10 => true, 24 => true);
$objects[8] += array(9 => true, 11 => true, 23 => true, 25 => true);
$objects[9] += array(10 => true, 24 => true);
// Smile
$operator = ($id == 14 || $id & 1 ? 1 : -1);
$index = 27;
$objects[$index] += array(7 => true, 27 => true);
$objects[$index + 1 * $operator] += array(8 => true, 26 => true);
$objects[$index + 2 * $operator] += array_fill(24, 2, true);
$objects[$index + 2 * $operator] += array_fill(9, 2, true);
$objects[$index + 3 * $operator] += array_fill(22, 2, true);
$objects[$index + 3 * $operator] += array_fill(11, 2, true);
$objects[$index + 4 * $operator] += array_fill(13, 9, true);
if($id == 1 || $id == 2 || $id == 5 || $id == 6)
{
$elements = array(array('biggrin', 'Very Happy'), array('sad', 'Sad'));
}
else if($id == 3 || $id == 4 || $id == 7 || $id == 8)
{
$elements = array(array('sad', 'Sad'), array('biggrin', 'Very Happy'));
}
else if($id == 9 || $id == 10)
{
$elements = array(array('blank', 'Empty'), array('biggrin', 'Very Happy'));
}
else if($id == 11 || $id == 12)
{
$elements = array(array('blank', 'Empty'), array('sad', 'Sad'));
}
else if($id == 13)
{
$elements = array(array('blank', 'Empty'), array('mrgreen', 'Mr. Green'));
}
else
{
$elements = array(array('blank', 'Empty'), array('wink', 'Wink'));
}
// Fill the table
if($id > 4 && $id < 9)
{
// Watch the circle values
$fill[0] = $fill[34] = 13;
$fill[1] = $fill[33] = 10;
$fill[2] = $fill[32] = 8;
$fill[3] = $fill[31] = 7;
$fill[4] = $fill[30] = 6;
$fill[5] = $fill[29] = 5;
$fill[6] = $fill[28] = 4;
$fill[7] = $fill[27] = 3;
$fill[8] = $fill[9] = $fill[25] = $fill[26] = 2;
$fill[10] = $fill[11] = $fill[12] = $fill[22] = $fill[23] = $fill[24] = 1;
// Fill the rest?
}
// @todo: rotate 90, 180, 270 degrees
// @lól: Fatal error: Can't use function return value in write context -> array_fill(10, 3, true) = array_fill(22, 3, true)
echo smile($elements, $objects, $fill);
footer();
function smile($elements = array(), $objects = array(), $fill = array(), $size = 35)
{
if(is_int($size))
{
$size = array_fill(0, 2, $size);
}
$value = '<table>';
for($y = 0; $y < $size[0]; ++$y)
{
$value .= '<tr>';
for($x = 0; $x < $size[1]; ++$x)
{
if($x < $fill[$y] ^ $size[0] - $fill[$y] > $x)
{
$index = (isset($objects[$y][$x]) ? 1 : 0);
$src = $elements[$index][0];
$alt = $elements[$index][1];
$img = '<img src="http://www.capaciouscore.pl/smiles/icon_'.$src.'.gif" alt="'.$alt.'" />';
}
$value .= '<td>'.$img.'</td>';
unset($img);
}
$value .= '</tr>';
}
$value .= '</table>';
return $value;
}
function footer()
{
echo '</body></html>';
exit;
}
?>
Tworząc circle posiłkowałem się tym ponieważ nie chciało mi się pisać funkcji generującej takie cuda. Zamiast wywołania funkcji footer() można było zastosować proste goto. Ten prosty projekt/przykład można rozszerzyć o parę funkcjonalności. Wersje demo można zobaczyć tutaj.
Komentarze
Dodaj komentarz