api.emotionhero.com/www/faces3.php
2016-09-19 00:50:50 +01:00

342 lines
No EOL
7.4 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">
body{
background:#999;
font-family:"Unifont";
font-weight:bold;
font-size:1vw;
margin:0.5em;
}
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;
}
.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;
}
svg{
margin-top:1%;
width:100%;
}
.nose .block{position:relative;margin-bottom:2%;}
.nose .block span{position:absolute;top:0;right:0;color:white;text-align:right;padding:0.5%;}
.brow_explainer{
}
.brow_explainer {
margin-top:3%;font-size:85%;
}
.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%;
}
.currentHit h3 span{
color:yellow;
}
ul{
font-size:80%;
list-style:none;
margin:0;
padding:0;
}
.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;
}
</style>
<body>
<?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>last</span><span>vs</span><span>perfect</span></h3>";
echo "<p>{$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>