用我的PHP代码用hsl和函数着色

时间:2012-05-03 10:28:50

标签: php html

我已经完成了这个代码,但它没有按照我想要的方式工作。我正在尝试为一根绳子上色。颜色由函数getcolor决定,该函数由称为原始变换的函数决定,该函数将原始分数转换为1-9的分数,用于我的开关案例。有人可以提供一些帮助吗? $col由另一个函数分配 - 为了论证,我们可以将它定义为:$col= 0

<?php

$raw= 650;
function rawtransform($raw) {
  $score = (int)($raw/50)-9;
}
    //==========================================================================
//            Function to decide which color system                         //
//==========================================================================   
function getcolor($score, $col)
{
switch ($score){
// to return the function best way is to declare the case outcome as a variable eg.$truecol
case 1: /*500-550(Raw Score)*/
    $truecol="<span style=\"color: hsl($col,100%,90%);\">";
    break;
case 2: //550-600
    $truecol="<span style=\"color: hsl($col,100%,80%);\">";
    break;
case 3: //600-650
    $truecol="<span style=\"color: hsl($col,100%,70%);\">";
    break;
case 4: //650-700
    $truecol="<span style=\"color: hsl($col,100%,60%);\">";
    break;
case 5: //700-750
    $truecol="<span style=\"color: hsl($col,100%,50%);\">";
    break;
case 6: //750-800
    $truecol="<span style=\"color: hsl($col,100%,40%);\">";
    break;
case 6: //800-850
    $truecol="<span style=\"color: hsl($col,100%,30%);\">";
    break;
case 7: //850-900;
    break;
case 8: //900-950
    $truecol="<span style=\"color: hsl($col,100%,20%);\">";
    break;
case 9: //950-1000
    $truecol="<span style=\"color: hsl($col,100%,10%);\">";
    break;
   }
}

   $query="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC";

$seq=chunk_split($query,50,"<br />");
getcolor($score);
function colorSequence ($seq,$position,$truecol,$TFBSlength){
    $nucleotides = str_split($seq);
    foreach ($nucleotides as $index => $nucl){
        if ($index == $position){
            echo $truecol;
        }
        if ($index == $position + $TFBSlength){
            echo "</span>";
        }

        echo $nucl;
    }
    echo "\n";
}
colorSequence($seq,49,$truecol,1);
?>

输出不包括选择的核苷酸的着色。谁知道为什么?

1 个答案:

答案 0 :(得分:0)

您不会将getcolor($score);的返回值分配给变量。我打赌在调用$truecol = getcolor($score);之前它应该是colorSequence($seq,49,$truecol,1);