mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-09 20:57:11 +00:00
98_DOIFtools: add getter hsvColorGradient, returns a table of value, colornumber, RGB values and color bar using Color::hsv2rgb
git-svn-id: https://svn.fhem.de/fhem/trunk@15281 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
759a2383b2
commit
badb001273
@ -1,5 +1,7 @@
|
||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||
# Do not insert empty lines here, update check depends on it.
|
||||
- feature: 98_DOIFtools: add getter hsvColorGradient, returns a table of
|
||||
value, colornumber, RGB values and color bar using Color::hsv2rgb
|
||||
- new: 46_TeslaPowerwall2AC: retrieves data from a Tesla Powerwall 2AC
|
||||
- bugfix: 21_HEOSMaster: fix typo in define Fn
|
||||
- feature: 93_DbRep: V5.8.0, can set table as flexible argument for command
|
||||
|
@ -706,6 +706,29 @@ sub DOIFtoolsLinColorGrad {
|
||||
return $prefix.join("",@rgb);
|
||||
}
|
||||
|
||||
sub DOIFtoolsHsvColorGrad {
|
||||
my ($cur,$min,$max,$min_s,$max_s,$s,$v)=@_;
|
||||
|
||||
my $m=($max_s-$min_s)/($max-$min);
|
||||
my $n=$min_s-$min*$m;
|
||||
if ($cur>$max) {
|
||||
$cur=$max;
|
||||
} elsif ($cur<$min) {
|
||||
$cur=$min;
|
||||
}
|
||||
|
||||
my $h=$cur*$m+$n;
|
||||
$h /=360;
|
||||
$s /=100;
|
||||
$v /=100;
|
||||
|
||||
my($r,$g,$b)=Color::hsv2rgb ($h,$s,$v);
|
||||
$r *= 255;
|
||||
$g *= 255;
|
||||
$b *= 255;
|
||||
return sprintf("#%02X%02X%02X", $r+0.5, $g+0.5, $b+0.5);
|
||||
}
|
||||
|
||||
sub DOIFtoolsRg
|
||||
{
|
||||
my ($hash,$arg) = @_;
|
||||
@ -1535,6 +1558,56 @@ Syntax: <code><start color number>,<end color number>,<minimal va
|
||||
<li><code><step width></code>, for each step a color number will be generated, example: 1.</li>
|
||||
</ul>
|
||||
Example specification: <code>#0000FF,#FF0000,7,30,1</code>
|
||||
<pre>";
|
||||
return $ret
|
||||
}
|
||||
} elsif ($arg eq "hsvColorGradient") {
|
||||
my ($min_s,$max_s,$min,$max,$step,$s,$v)=split(",",$value);
|
||||
if ($value && $s >= 0 && $s <= 100 && $v >= 0 && $v <= 100 && $min_s >= 0 && $min_s <= 360 && $max_s >= 0 && $max_s <= 360) {
|
||||
$ret .= "<br></pre><table>";
|
||||
$ret .= "<tr><td colspan=4 style='font-weight:bold;'>Color Table</td></tr>";
|
||||
$ret .= "<tr><td colspan=4><div>";
|
||||
for (my $i=0;$i<=127;$i++) {
|
||||
my $col = DOIFtoolsHsvColorGrad($i,0,127,$min_s,$max_s,$s,$v);
|
||||
$ret .= "<span style='background-color:$col;'> </span>";
|
||||
}
|
||||
$ret .= "</div></td></tr>";
|
||||
$ret .= "<tr style='text-align:center;'><td> Value </td><td> Color Number </td><td> RGB values </td><td> Color</td> </tr>";
|
||||
for (my $i=$min;$i<=$max;$i+=$step) {
|
||||
my $col = DOIFtoolsHsvColorGrad($i,$min,$max,$min_s,$max_s,$s,$v);
|
||||
$col =~ /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/;
|
||||
$ret .= "<tr style='text-align:center;'><td>".sprintf("%.1f",$i)."</td><td>$col</td><td> ".hex($1).",".hex($2).",".hex($3)." </td><td style='background-color:$col;'>      </td></tr>";
|
||||
}
|
||||
$ret .= "</table><pre>";
|
||||
|
||||
return $ret;
|
||||
} else {
|
||||
$ret = $DE ? "<br></pre>
|
||||
Falsche Eingabe: <code>$value</code><br>
|
||||
Syntax: <code><HUE-Startwert>,<HUE-Endwert>,<Minimalwert>,<Maximalwert>,<Schrittweite>,<Sättigung>,<Hellwert></code><br>
|
||||
<ul>
|
||||
<li><code><HUE-Startwert></code>, ist ein HUE-Wert <code>0-360</code>, Beispiel: 240 für Blau.</li>
|
||||
<li><code><HUE-Endwert></code>, ist ein HUE-Wert <code>0-360</code>, Beispiel: 360 für Rot.</li>
|
||||
<li><code><Minimalwert></code>, der Minimalwert auf den der HUE-Startwert skaliert wird, Beispiel: 7.</li>
|
||||
<li><code><Maximalwert></code>, der Maximalwert auf den der HUE-Endwert skaliert wird, Beispiel: 30.</li>
|
||||
<li><code><Schrittweite></code>, für jeden Schritt wird ein Farbwert erzeugt, Beispiel: 1.</li>
|
||||
<li><code><Sättigung></code>, die verwendete Farbsätigung <code>0-100</code>, Beispiel: 80.</li>
|
||||
<li><code><Hellwert></code>, Angabe der Helligkeit <code>0-100</code>, Beispiel: 80.</li>
|
||||
</ul>
|
||||
Beispielangabe: <code>240,360,7,30,1,80,80</code>
|
||||
<pre>":"<br></pre>
|
||||
Wrong input: <code>$value</code><br>
|
||||
Syntax: <code><HUE start value>,<HUE end value>,<minimal value>,<maximal value>,<step width>,<saturation>,<lightness></code><br>
|
||||
<ul>
|
||||
<li><code><HUE start value></code>, a HUE value <code>0-360</code>, example: 240 for blue.</li>
|
||||
<li><code><HUE end value></code>, a HUE value <code>0-360</code>, example: 360 for red.</li>
|
||||
<li><code><minimal value></code>, the HUE start value will be scaled to it, example: 7.</li>
|
||||
<li><code><maximal value></code>, the HUE end value will be scaled to it, example: 30.</li>
|
||||
<li><code><step width></code>, for each step a color number will be generated, example: 1.</li>
|
||||
<li><code><saturation></code>, a value of saturation <code>0-100</code>, example: 80.</li>
|
||||
<li><code><lightness></code>, a value of lightness <code>0-100</code>, example: 80.</li>
|
||||
</ul>
|
||||
Example specification: <code>240,360,7,30,1,80,80</code>
|
||||
<pre>";
|
||||
return $ret
|
||||
}
|
||||
@ -1623,7 +1696,7 @@ Example specifications:<br>
|
||||
return $ret;
|
||||
} else {
|
||||
my $hardcoded = "checkDOIF:noArg statisticsReport:noArg runningTimerInDOIF:noArg";
|
||||
return "unknown argument $arg for $pn, choose one of readingsGroup_for:multiple-strict,$dL DOIF_to_Log:multiple-strict,$dL SetAttrIconForDOIF:multiple-strict,$dL userReading_nextTimer_for:multiple-strict,$ntL ".(AttrVal($pn,"DOIFtoolsHideGetSet",0) ? $hardcoded :"")." linearColorGradient:textField modelColorGradient:textField";
|
||||
return "unknown argument $arg for $pn, choose one of readingsGroup_for:multiple-strict,$dL DOIF_to_Log:multiple-strict,$dL SetAttrIconForDOIF:multiple-strict,$dL userReading_nextTimer_for:multiple-strict,$ntL ".(AttrVal($pn,"DOIFtoolsHideGetSet",0) ? $hardcoded :"")." linearColorGradient:textField modelColorGradient:textField hsvColorGradient:textField";
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user