<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Slider - Colorpicker</title>
<link rel="stylesheet" href="jquery/jquery-ui.css">
<script src="jquery/jquery-1.10.2.js"></script>
<script src="jquery/jquery-ui.js"></script>
<style>
#red, #green, #blue, #brightness {
float: left;
clear: left;
width: 300px;
margin: 15px;
}
#ValueRed, #ValueGreen, #ValueBlue, #ValueBrightness{
float: left;
clear: left;
margin-left: 150px;
}
#lred, #lgreen, #lblue {
float: left;
clear: left;
width: 300px;
margin: 15px;
}
#lValueRed, #lValueGreen, #lValueBlue {
float: left;
clear: left;
margin-left: 150px;
}
#swatch {
width: 120px;
height: 250px;
margin-top: 18px;
margin-left: 350px;
margin-bottom: 35px;
background-image: none;
}
#lswatch {
width: 120px;
height: 200px;
margin-top: 18px;
margin-left: 350px;
background-image: none;
}
#red .ui-slider-range { background: #ef2929; }
#red .ui-slider-handle { border-color: #ef2929; }
#green .ui-slider-range { background: #8ae234; }
#green .ui-slider-handle { border-color: #8ae234; }
#blue .ui-slider-range { background: #729fcf; }
#blue .ui-slider-handle { border-color: #729fcf; }
#lred .ui-slider-range { background: #ef2929; }
#lred .ui-slider-handle { border-color: #ef2929; }
#lgreen .ui-slider-range { background: #8ae234; }
#lgreen .ui-slider-handle { border-color: #8ae234; }
#lblue .ui-slider-range { background: #729fcf; }
#lblue .ui-slider-handle { border-color: #729fcf; }
</style>
<script>
function hexFromRGB(r, g, b) {
var hex = [
r.toString( 16 ),
g.toString( 16 ),
b.toString( 16 )
];
$.each( hex, function( nr, val ) {
if ( val.length === 1 ) {
hex[ nr ] = "0" + val;
}
});
return hex.join( "" ).toUpperCase();
}
function refreshSwatch() {
var red = $( "#red" ).slider( "value" ),
green = $( "#green" ).slider( "value" ),
blue = $( "#blue" ).slider( "value" ),
brightness = $( "#brightness" ).slider( "value" ),
brightness = (brightness/255),
hex = hexFromRGB( red, green, blue ),
lred = $( "#lred" ).slider( "value" ),
lgreen = $( "#lgreen" ).slider( "value" ),
lblue = $( "#lblue" ).slider( "value" ),
laverage = Math.round((lred + lgreen + lblue)/3),
lhex = hexFromRGB( laverage, laverage, laverage );
$( "#lswatch" ).css( "background-color", "#" + lhex );
$( "#swatch" ).css( "background-color", "rgb(" + Math.round(red * brightness) + "," + Math.round(green * brightness) + "," + Math.round(blue * brightness) + ")");
$( "#lred" ).css( "background", "rgb(" + lred + "," + lred + "," + lred + ")" );
$( "#lgreen" ).css( "background", "rgb(" + lgreen + "," + lgreen + "," + lgreen + ")" );
$( "#lblue" ).css( "background", "rgb(" + lblue + "," + lblue + "," + lblue + ")" );
document.getElementById('ValueRed').innerHTML = Math.round(red * brightness);
document.getElementById('ValueGreen').innerHTML = Math.round(green * brightness);
document.getElementById('ValueBlue').innerHTML = Math.round(blue * brightness);
document.getElementById('ValueBrightness').innerHTML = Math.round(brightness * 100) + " %";
document.getElementById('lValueRed').innerHTML = lred;
document.getElementById('lValueGreen').innerHTML = lgreen;
document.getElementById('lValueBlue').innerHTML = lblue;
UpdateLED();
}
$(function() {
$( "#red, #green, #blue, #brightness, #lred, #lgreen, #lblue" ).slider({
orientation: "horizontal",
range: "min",
max: 255,
value: 127,
slide: refreshSwatch,
change: refreshSwatch
});
$( "#red" ).slider( "value", 255 );
$( "#green" ).slider( "value", 140 );
$( "#blue" ).slider( "value", 60 );
$( "#brightness" ).slider( "value", 255 );
$( "#lred" ).slider( "value", 255 );
$( "#lgreen" ).slider( "value", 255 );
$( "#lblue" ).slider( "value", 255 );
});
</script>
<script type="text/javascript">
function UpdateLED() {
JSrouge = $( "#red" ).slider( "value" );
JSvert = $( "#green" ).slider( "value" );
JSbleu = $( "#blue" ).slider( "value" );
$.ajax({
url: 'LEDcolor.php',
type: 'POST',
dataType: 'text',
data: {ROUGE: $( "#red" ).slider( "value" ), VERT: $( "#green" ).slider( "value" ), BLEU: $( "#blue" ).slider( "value" ), LUMINOSITE: $( "#brightness" ).slider( "value" ),LROUGE: $( "#lred" ).slider( "value" ), LVERT: $( "#lgreen" ).slider( "value" ), LBLEU: $( "#lblue" ).slider( "value" )}
})};
</script>
</head>
<body class="ui-widget-content" style="border:0;">
<p class="ui-state-default ui-corner-all ui-helper-clearfix" style="padding:4px;">
<span class="ui-icon ui-icon-pencil" style="float:left; margin:-2px 5px 0 0;"></span>
RGB Selector
</p>
<div id="ValueRed"></div>
<div id="red"></div>
<div id="ValueGreen"></div>
<div id="green"></div>
<div id="ValueBlue"></div>
<div id="blue"></div>
<div id="ValueBrightness"></div>
<div id="brightness"></div>
<div id="swatch" class="ui-widget-content ui-corner-all"></div>
<p class="ui-state-default ui-corner-all ui-helper-clearfix" style="padding:4px;">
<span class="ui-icon ui-icon-pencil" style="float:left; margin:-2px 5px 0 0;"></span>
RGB Balancing
</p>
<div id="lValueRed"></div>
<div id="lred"></div>
<div id="lValueGreen"></div>
<div id="lgreen"></div>
<div id="lValueBlue"></div>
<div id="lblue"></div>
<div id="lswatch" class="ui-widget-content ui-corner-all"></div>
</body>
</html>