api.emotionhero.com/www/faces3.php
2016-09-20 10:33:01 +01:00

392 lines
No EOL
8.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require __DIR__ . '/../bootstrap.php';
error_reporting(E_ALL);ini_set('display_errors', true);
$em = \EmotionHero\Application::getInstance()->getEm();
/* @var $hitRepo EmotionHero\Models\HitRepository */
$hitRepo = $em->getRepository(\EmotionHero\Models\Hit::class);
/* @var $currentHit \EmotionHero\Models\Hit */
$currentHit = $hitRepo->findOneBy(['hasImage'=>true], ['id'=>'DESC']);
$betterHit = $hitRepo->getBetterHit($currentHit);
$printEmoBlocks = function($emotion, $feature, $steps = 6) use($em) {
foreach(range(0, 100, 100/($steps-1)) as $i) {
/* @var $hitRepo EmotionHero\Models\HitRepository */
$hitRepo = $em->getRepository(EmotionHero\Models\Hit::class);
// if($feature == 'nose'){
// $items = [992, 1035, 701, 888, 671, 906, 693, 725, 762, 666, 751,992,728];
// $hit = $hitRepo->find($items[array_rand($items)]);
// } elseif($feature == 'mouth_left') {
// $items = [992, 1035, 1034, 888];
// $hit = $hitRepo->find($items[array_rand($items)]);
// } else{
$hit = $hitRepo->getClosestHitWithImage($emotion, $i);
// }
$img = $hit->getFeatureImgAsString($feature);
$score = $hit->getEmotions()->getEmotionScore($emotion);
$percentage = sprintf("%.0f %%",$score);
echo <<< EOSNIPPET
<div class="block">
<img src="data:image/x-icon;base64,$img" title="{$hit->getId()}">
<span class="perc">$percentage</span>
</div>
EOSNIPPET;
}
};
?>
<html>
<head>
<title>Emotion Hero</title>
</head>
<style type="text/css">
html{
height:100%;
overflow:hidden;
}
body{
background:blue;
font-family:"Unifont";
font-weight:bold;
font-size:1vw;
margin:0.5em;
}
body.presentation{
background:black;
}
h3{
margin:0.5%;
text-align:center;
}
h3 span{
background:black;
color:white;
padding:0.2%;
}
.block{
width:100%;
font-size:80%;
}
.mouth .emo-block{
width:50%;
float:left;
height:5em;
}
.mouth .emotitle{
display:block;
width:14%;
margin-right:0.14%;
margin-left:0.14%;
float:left;
font-size:80%;
padding-top:2.5%
}
.mouth .block {
width:14%;
margin-right:0.14%;
margin-left:0.14%;
float:left;
}
/*.emotitle span:before{content:"";}
.emotitle span:after{content:"";}*/
.emotitle{font-style:italic;}
.emotitle:before{content:"«";}
.emotitle:after{content:"»";}
img{
width:100%;
filter:saturate(0%);
mix-blend-mode: multiply;
/*mix-blend-mode: exclusion;*/
}
.perc{
display:block;
width:100%;
text-align:center;
}
.emo-block{
float:left;
text-align:center;
}
.brows .emo-block {
width:23%;
margin-left:1%;
margin-right:1%;
}
.nose .emo-block {
width:12%;
margin-left:1.14%;
margin-right:1.14%;
}
.nose .emotitle{
font-size:80%;
}
.emo-block-emos{
position:relative;
}
.emo{
text-align:center;
float:left;
background:#fff;
}
.brows{
width:40%;
margin-right:1%;
}
.nose{
width:40%;
margin-right:1%;
}
.mouth{
width:81%;
margin-top:1%;
}
img.curImg{
position:absolute;
left:0;
mix-blend-mode:difference;
}
.currentHit svg{
border-top: 1em solid blue;
margin: 0px -0.5em;
width: 100%;
padding: 0.5em;
width:100%;
}
.presentation .currentHit svg {
border-top: solid 0.1em white;
}
.nose .block{position:relative;margin-bottom:2%;}
.nose .block span{position:absolute;top:0;right:0;color:white;text-align:right;padding:0.5%;}
.brows .emo-block.brow_explainer {
margin-top:3%;font-size:85%;
border-left: 0.3em solid blue;
width: 22%;
padding-left: 0.4em;
margin-left: -0.1em;
}
.presentation .brows .emo-block.brow_explainer{
border-left-color: black;
}
.brow_explainer img{filter:unset;margin-bottom:5%;}
.brow_explainer ol{
margin:0;padding:0;
counter-reset:li 4;
}
.brow_explainer li{
text-align:left;
margin-bottom:5%;
list-style:none;
}
.brow_explainer li:before{
content:counter(li) ". "; /* Use the counter as content */
counter-increment:li; /* Increment the counter by 1 */
color:red;
}
.currentHit{
width:17%;
position:absolute;
right:0.5em;
top:0.5em;
background:yellow;
padding:0.5%;
}
.presentation .currentHit {
background:none;
color:white;
}
.presentation .currentHit h3 span{
color:white;
background: none;
}
.currentHit h3 span{
color:yellow;
}
.presentation .currentHit h3 span{
color:white;
}
.currentHit h3 .last{color:red;}
.currentHit h3 .vs{background:none;color:black;padding-left:0.5em;padding-right:0.5em;}
.currentHit h3 .perfect{}
ul{
font-size:80%;
list-style:none;
margin:0;
padding:0;
}
.presentation ul{
font-size:1.1em;
}
.currentHit li{
clear:both;
}
.currentHit li .value{
float:right;
}
.currentHit li .diff{
float:right;
clear:both;
font-size:72%;
color:gray;
}
.currentHit li .diff.negative{
color:red;
}
.currentHit li .diff.positive{
color:green;
}
.presentation .currentHit li .diff.positive{
color:yellow;
}
.currentHit p {
margin: 0 -0.5em 1% -0.5em;
border-bottom: solid 1em blue;
padding: 0.5em;
text-align: center;
}
.presentation .currentHit p {
border-bottom: solid 0.1em white;
}
</style>
<body <?php if(isSet($_GET['presentation'])){echo "class='presentation'";}?>>
<?php
echo "<div class='brows emo'><h3><span>eye brows</span></h3>";
foreach(EmotionHero\Models\Emotions::$EMOTIONS as $emotion) {
echo "<div class='emo-block'><span class='emotitle'>$emotion</span><div class='emo-block-emos'>";
$printEmoBlocks($emotion, 'brows');
//echo "<img class='curImg' src=\"data:image/x-icon;base64,{$currentHit->getFeatureImgAsString("brows")}\" title=\"{$currentHit->getId()}\" style=\"top:{$currentHit->getEmotions()->getEmotionScore($emotion)}%\">";
echo "</div></div>";
}
?>
<div class="emo-block brow_explainer">
<img src="brow_explain.png">
<ol start="5">
<li>Outer Right Brow Corner</li>
<li>Right Brow Center</li>
<li>Inner Right Brow Corner</li>
<li>Inner Left Brow Corner</li>
<li>Left Brow Center</li>
<li>Outer Left Brow Corner</li>
</ol>
</div>
<?php
echo "</div>"; // .brows
echo "<div class='nose emo'><h3><span>nose</span></h3>";
foreach(EmotionHero\Models\Emotions::$EMOTIONS as $emotion) {
echo "<div class='emo-block'><span class='emotitle'>$emotion</span><div class='emo-block-emos'>";
$printEmoBlocks($emotion, 'nose');
//echo "<img class='curImg' src=\"data:image/x-icon;base64,{$currentHit->getFeatureImgAsString("nose")}\" title=\"{$currentHit->getId()}\" style=\"top:{$currentHit->getEmotions()->getEmotionScore($emotion)}%\">";
echo "</div></div>";
}
echo "</div>"; // .nose
echo "<div class='mouth emo'><h3><span>mouth</span></h3>";
foreach(EmotionHero\Models\Emotions::$EMOTIONS as $emotion) {
echo "<div class='emo-block'><span class='emotitle'>$emotion</span><div class='emo-block-emos'>";
$printEmoBlocks($emotion, 'mouth_left');
echo "</div></div>";
}
echo "</div>"; // .mouth
echo "<div class='currentHit'>";
echo "<h3><span class='last'>last</span><span class='vs'>vs</span><span class='perfect'>perfect</span></h3>";
// echo "<p>".\PrettyDateTime\PrettyDateTime::parse($currentHit->getGame()->getOriginalGameAt())."</p>";
echo "<p>aim: {$currentHit->getTarget()->getScore()}% ".$currentHit->getTarget()->getEmotion()->getName()."</p>";
echo "<ul>";
$expressions = array_keys($currentHit->getExpressions()::$EXPRESSIONS_2ND_PERSON);
sort($expressions);
foreach($expressions as $expression) {
$currentScore = $currentHit->getExpressions()->getExpressionScore($expression);
$betterScore = $betterHit->getExpressions()->getExpressionScore($expression);
$diff = $betterScore - $currentScore;
if($diff > 0) {
$diffclass = "positive";
}elseif($diff < 0) {
$diffclass = "negative";
}
echo "<li>";
echo "<span class='name'>$expression</span>";
echo "<span class='value'>". sprintf("%.5f", $currentScore)." %</span>";
echo "<span class='diff $diffclass'>". sprintf("%+.5f", $diff)." %</span>";
echo "</li>";
}
echo "</ul>";
$circles = "";
foreach($betterHit->getPoints()->getNormalisedPoints() as $i => $point) {
/* $circles .= '<circle
style="fill:gray;"
id="point'.$i.'"
cx="'.$point->getX().'"
cy="'.$point->getY().'"
r="0.7" />';*/
$circles .= '<text
style="fill:green;font-size:4"
id="point'.$i.'"
x="'.$point->getX().'"
y="'.$point->getY().'"
r="0.7">'.$i.'</text>';
}
foreach($currentHit->getPoints()->getNormalisedPoints() as $i => $point) {
$circles .= '<text
style="fill:red;font-size:4"
id="point'.$i.'"
x="'.$point->getX().'"
y="'.$point->getY().'"
r="0.7">'.$i.'</text>';
}
echo <<< EOSVG
<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="-4 -4 108 108"
id="svg2"
version="1.1">
<g id="layer1">
$circles
</g>
</svg>
EOSVG;
echo "</div>"; // .currentHit
?>
</body>
</html>