Template:Team:UC Davis/MutantWidget

From 2011.igem.org

(Difference between revisions)
Line 2: Line 2:
<script src='https://2011.igem.org/Template:Team:UC_Davis/jquery.flot.min.js?action=raw'></script>
<script src='https://2011.igem.org/Template:Team:UC_Davis/jquery.flot.min.js?action=raw'></script>
<script>
<script>
 +
// RGB <-> HSL conversions based on equations from wikipedia.
 +
// If they're wrong, don't blame me!
 +
function RGB2HSL(r,g,b)
 +
{
 +
var alpha = 1/2*(2*r-g-b);
 +
var beta = Math.sqrt(3)/2*(g-b);
 +
var C = Math.sqrt(alpha^2 + beta^2);
 +
var h = Math.atan2(beta, alpha);
 +
if(h < 0)
 +
{
 +
h += 2*Math.PI;
 +
}
 +
var l = 0.3*r + 0.59*g + 0.11*b;
 +
if(C > 0)
 +
{
 +
s = C/(1 - Math.abs(2*l-1));
 +
} else
 +
{
 +
s = 0;
 +
}
 +
 +
return {h:h,s:s,l:l};
 +
}
 +
function HSL2RGB(h,s,l)
 +
{
 +
 +
var C = (1-Math.abs(2*l-1))*s;
 +
var Hprime = h / Math.PI*3;
 +
var X = C*(1 - Math.abs(Hprime%2-1));
 +
if(h < 0) {
 +
var r = g = b = 0;
 +
} else if(h < 1) {
 +
var r = C, g = X, b = 0;
 +
} else if(h < 2) {
 +
var r = X, g = C, b = 0;
 +
} else if(h < 3) {
 +
var r = 0, g = C, b = X;
 +
} else if(h < 4) {
 +
var r = 0, g = X, b = C;
 +
} else if(h < 5) {
 +
var r = X, g = 0, b = C;
 +
} else if(h < 6) {
 +
var r = C, g = 0, b = X;
 +
}
 +
m = l - C/2;
 +
r = r + m;
 +
g = g + m;
 +
b = b + m;
 +
return {r:r, g:g, b:b}
 +
}
 +
 +
//Bilinear interpolation
 +
// y1-*z0    -    *z1
 +
//          fr1
 +
//          +x,y
 +
//          fr2
 +
// y2-*z2    -    *z3
 +
//    |            |
 +
//    x1          x2
 +
function interp2(x1, y1, x2, y2, z0, z1, z2, z3, x, y)
 +
{
 +
fr1 = (x-x1)/(x2-x1)*z1 + (x2-x)/(x2-x1)*z0;
 +
fr2 = (x-x1)/(x2-x1)*z3 + (x2-x)/(x2-x1)*z2;
 +
return ((y-y1)/(y2-y1)*fr2 + (y2-y)/(y2-y1)*fr1);
 +
}
 +
 +
function colorRamp(value, colormap)
 +
{
 +
if(value > 1)
 +
{
 +
value = 1;
 +
}
 +
if(value < 0)
 +
{
 +
value = 0;
 +
}
 +
var maxval = colormap.length-1;
 +
var newval = value*maxval;
 +
var highval = Math.ceil(newval);
 +
var lowval = highval - 1;
 +
if(highval == 0)
 +
{
 +
lowval = 0;
 +
highval = 1;
 +
}
 +
lowcolor = RGB2HSL(colormap[lowval][0], colormap[lowval][1], colormap[lowval][2]);
 +
highcolor = RGB2HSL(colormap[highval][0], colormap[highval][1], colormap[highval][2]);
 +
var h = lowcolor.h*(highval - newval) + highcolor.h*(newval - lowval);
 +
var s = lowcolor.s*(highval - newval) + highcolor.s*(newval - lowval);
 +
var v = lowcolor.l*(highval - newval) + highcolor.l*(newval - lowval);
 +
newcolor = HSL2RGB(h,s,v);
 +
/*
 +
var r = colormap[lowval][0]*(highval - newval) + colormap[highval][0]*(newval - lowval);
 +
var g = colormap[lowval][1]*(highval - newval) + colormap[highval][1]*(newval - lowval);
 +
var b = colormap[lowval][2]*(highval - newval) + colormap[highval][2]*(newval - lowval);
 +
*/
 +
return [newcolor.r, newcolor.g, newcolor.b];
 +
}
 +
 +
cool_color_ramp = [[1,0,0], [0,0,1]];
 +
 +
var WIDTH = 650;
 +
var HEIGHT = 350;
 +
var VIEW_ANGLE = 45,
 +
    ASPECT = WIDTH/HEIGHT,
 +
    NEAR = 0.1,
 +
    FAR = 10000;
 +
mutantcolors = ["white", "#ff6666", "orange", "yellow", "#66ff66", "#66ffff", "#ddaaff", "pink"]
mutantcolors = ["white", "#ff6666", "orange", "yellow", "#66ff66", "#66ffff", "#ddaaff", "pink"]
$(document).ready(function(){
$(document).ready(function(){

Revision as of 23:55, 24 September 2011