$cnt = count($chars);
        if ($bsw == "") {
            $cnt = 0;
        }
        for ($i = 0; $i < $cnt; $i++) {
            $char = $chars[$i];
            $i++;
            $cfill = $chars[$i];
            $i++;
            $crot = $chars[$i];
            $i++;
            $x = hex2num($chars[$i]);
            $i++;
            $y = hex2num($chars[$i]);
            //creates illegal number characters... (but it works for now) max num 2869?
            $data .= $char . $cfill . $crot . num2hex($x - $xadj) . num2hex($y + $yadj);
        }
    }
}
/**
 * color options and transparency
 * 
 * 12 testing options
 * 3 line options - none (black), colorize, color 
 * 2 fill options - transparent or color    
 * 2 size options - 1 or other
 */
if ($colorize) {
    $line = '';
    //ignore line color
} else {
Beispiel #2
0
function moveBSW($bsw, $mx, $my)
{
    if (isPunc($bsw)) {
        return $bsw;
    }
    $first = substr($bsw, 0, 3);
    $cluster = bsw2cluster($bsw);
    $seq = bsw2seq($bsw);
    $chars = str_split($cluster, 3);
    $bsw = $first;
    for ($i = 0; $i < count($chars); $i++) {
        //sym as base,fill,rot
        $bsw .= $chars[$i++];
        $bsw .= $chars[$i++];
        $bsw .= $chars[$i++];
        //move x and y
        $x = $chars[$i++];
        $bsw .= num2hex(hex2num($x) - $mx);
        $y = $chars[$i];
        $bsw .= num2hex(hex2num($y) - $my);
    }
    if ($seq) {
        $bsw .= '0fd' . $seq;
    }
    return $bsw;
}
 public function __construct($bsw)
 {
     $this->bsw = $bsw;
     $this->lane = substr($bsw, 0, 3);
     $this->cluster = bsw2cluster($bsw);
     $this->seq = bsw2seq($bsw);
     /**
      * Step 1: break apart
      */
     $keys = array();
     $xs = array();
     // x position
     $ys = array();
     // y position
     $ws = array();
     // width
     $hs = array();
     // height
     $bsw = bsw2cluster($bsw);
     $chars = str_split($bsw, 3);
     $cnt = count($chars);
     if ($bsw != "") {
         for ($i = 0; $i < $cnt; $i++) {
             $char = $chars[$i];
             $i++;
             $fill = char2fill($chars[$i]);
             $i++;
             $rot = char2rot($chars[$i]);
             $key = $char . $fill . $rot;
             $keys[] = $key;
             $i++;
             $xs[] = hex2num($chars[$i]);
             $i++;
             $ys[] = hex2num($chars[$i]);
             $sym = new Symbol($key);
             $ws[] = $sym->getWidth();
             $hs[] = $sym->getHeight();
         }
         /**
          * Step 2: determing width, height, and center
          */
         $xMin = $xs[0];
         $xMax = $xMin + 2;
         $yMin = $ys[0];
         $yMax = $yMin + 2;
         $cxMin = 0;
         $cxMax = 0;
         $cyMin = 0;
         $cyMax = 0;
         $centering = 0;
         // centering count
     } else {
         //make up values
         $xMin = 0;
         $xMax = $xMin + 2;
         $yMin = 0;
         $yMax = $yMin + 2;
         $cxMin = 0;
         $cxMax = 0;
         $cyMin = 0;
         $cyMax = 0;
         $centering = 0;
         // centering count
     }
     foreach ($keys as $num => $key) {
         $base = substr($key, 0, 3);
         $W = $ws[$num];
         $H = $hs[$num];
         $X = $xs[$num];
         $Y = $ys[$num];
         if ($xMin > $X) {
             $xMin = $X;
         }
         if ($yMin > $Y) {
             $yMin = $Y;
         }
         if ($xMax < $X + $W) {
             $xMax = $X + $W;
         }
         if ($yMax < $Y + $H) {
             $yMax = $Y + $H;
         }
         //check for centering
         if (isHead($base) or isTrunk($base)) {
             if ($centering == 0) {
                 $cxMin = $X;
                 $cxMax = $X + $W;
                 $cyMin = $Y;
                 $cyMax = $Y + $H;
             } else {
                 if ($cxMin > $X) {
                     $cxMin = $X;
                 }
                 if ($cyMin > $Y) {
                     $cyMin = $Y;
                 }
                 if ($cxMax < $X + $W) {
                     $cxMax = $X + $W;
                 }
                 if ($cyMax < $Y + $H) {
                     $cyMax = $Y + $H;
                 }
             }
             $centering++;
         }
     }
     $this->width = $xMax - $xMin;
     $this->height = $yMax - $yMin;
     if ($centering) {
         $this->centerX = ($cxMin + $cxMax) / 2 - $xMin;
         $this->centerY = ($cyMin + $cyMax) / 2 - $yMin;
     } else {
         $this->centerX = ($xMin + $xMax) / 2;
         $this->centerY = ($yMin + $yMax) / 2;
     }
     //rebuild bsw with zero relative x and y
     $this->bsw = $this->lane;
     foreach ($keys as $num => $key) {
         $this->bsw .= key2bsw($key);
         $X = $xs[$num];
         $this->bsw .= num2hex($X - $xMin);
         //$this->centerX);
         $Y = $ys[$num];
         $this->bsw .= num2hex($Y - $yMin);
         //$this->centerY);
     }
     //already zero based
     //    $this->centerX -= $xMin;
     //    $this->centerY -= $yMin;
     if ($this->seq) {
         $this->bsw .= '0fd' . $this->seq;
     }
 }