-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
# Changelog | ||
|
||
|
||
### v0.2 - 29/06/2019 | ||
|
||
Add class `Color` for to control light | ||
|
||
|
||
### v0.1 - 08/05/2019 | ||
|
||
Initial release (version beta) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<phpunit bootstrap="test/bootstrap.php" colors="true" verbose="true"> | ||
<testsuites> | ||
<testsuite name="all"> | ||
<directory>test</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Librairie des transformations des couleurs en surcharge de la classe Color | ||
* | ||
* @author Olivier <[email protected]> | ||
* | ||
* @package TuyaCloudApi | ||
* @link https://github.com/mexitek/phpColors | ||
*/ | ||
|
||
namespace Sabinus\TuyaCloudApi\Tools; | ||
|
||
use Mexitek\PHPColors\Color as MexitekColor; | ||
|
||
|
||
class Color extends MexitekColor | ||
{ | ||
|
||
/** | ||
* Corrections pour retourner les valeurs en pourcentage sur la saturation et la luminosité | ||
* | ||
* @see Mexitek\PHPColors\Color::hexToHsl | ||
*/ | ||
public static function hexToHsl($color) | ||
{ | ||
$HSL = parent::hexToHsl($color); | ||
|
||
// Correction en pourcentage | ||
$HSL['H'] = (int) $HSL['H']; | ||
$HSL['S'] = (int) round($HSL['S']*100); | ||
$HSL['L'] = (int) round($HSL['L']*100); | ||
|
||
return $HSL; | ||
} | ||
|
||
|
||
/** | ||
* Couvertion des valeurs de la saturation et la luminosité de pourcentage en décimale | ||
* | ||
* @see Mexitek\PHPColors\Color::hslToHex | ||
*/ | ||
public static function hslToHex($hsl = array()) | ||
{ | ||
// Correction en decimal | ||
if (isset($hsl['S'])) $hsl['S'] = $hsl['S'] / 100; | ||
if (isset($hsl['L'])) $hsl['L'] = $hsl['L'] / 100; | ||
|
||
return parent::hslToHex($hsl); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Test de la class Color | ||
* | ||
* @author Olivier <[email protected]> | ||
* | ||
* @package TuyaCloudApi | ||
*/ | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sabinus\TuyaCloudApi\Tools\Color; | ||
|
||
|
||
class ColorTest extends TestCase | ||
{ | ||
|
||
public function testRGB2HEX() | ||
{ | ||
$this->assertSame('007fff', Color::rgbToHex(array('R' => 0, 'G' => 127, 'B' => 255))); | ||
$this->assertSame('cf2080', Color::rgbToHex(array('R' => 207, 'G' => 32, 'B' => 128))); | ||
} | ||
|
||
|
||
public function testHEX2RGB() | ||
{ | ||
$this->assertSame(array('R' => 0, 'G' => 127, 'B' => 255), Color::hexToRgb('007fff')); | ||
$this->assertSame(array('R' => 207, 'G' => 32, 'B' => 128), Color::hexToRgb('cf2080')); | ||
} | ||
|
||
|
||
public function testHEX2HSL() | ||
{ | ||
$this->assertSame(array('H' => 210, 'S' => 100, 'L' => 50), Color::hexToHsl('007fff')); | ||
$this->assertSame(array('H' => 327, 'S' => 73, 'L' => 47), Color::hexToHsl('cf2080')); | ||
} | ||
|
||
|
||
public function testHSL2HEX() | ||
{ | ||
$this->assertSame('0080ff', Color::hslToHex(array('H' => 210, 'S' => 100, 'L' => 50))); | ||
$this->assertSame('cf2081', Color::hslToHex(array('H' => 327, 'S' => 73, 'L' => 47))); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
require __DIR__.'/../vendor/autoload.php'; | ||
includeAll(__DIR__.'/../src'); | ||
|
||
|
||
function includeAll($dir) { | ||
$f = scandir($dir); | ||
foreach ($f as $f2) { | ||
if ($f2 == "." || $f2 == "..") continue; | ||
if (is_dir($dir . DIRECTORY_SEPARATOR . $f2)) { | ||
includeAll($dir . DIRECTORY_SEPARATOR . $f2); | ||
} else { | ||
if (substr($f2, -4) == ".php") { | ||
include_once($dir . DIRECTORY_SEPARATOR . $f2); | ||
} | ||
} | ||
} | ||
} |