Example #1
0
 /**
  * Convert an awGradient object to an SWFGradient one.
  * Returns an object as well as the style of the Flash gradient.
  *
  * @param $gradient The awGradient object to convert
  * @return array
  */
 function getGradient($gradient)
 {
     $flashGradient = new SWFGradient();
     // Get RGBA values for the gradient boundaries
     list($r1, $g1, $b1, $a1) = $this->getColor($gradient->from);
     list($r2, $g2, $b2, $a2) = $this->getColor($gradient->to);
     $flashGradient->addEntry(0, $r1, $g1, $b1, $a1);
     if (is_a($gradient, 'awBilinearGradient')) {
         $flashGradient->addEntry($gradient->center, $r2, $g2, $b2, $a2);
         $flashGradient->addEntry(1, $r1, $g1, $b1, $a1);
         return array($flashGradient, SWFFILL_LINEAR_GRADIENT);
     } else {
         $flashGradient->addEntry(1, $r2, $g2, $b2, $a2);
         if (is_a($gradient, 'awLinearGradient')) {
             return array($flashGradient, SWFFILL_LINEAR_GRADIENT);
         } else {
             return array($flashGradient, SWFFILL_RADIAL_GRADIENT);
         }
     }
 }
Example #2
0
 /**
  * Set the fill and line properties for a SWWFShape according to the 
  * given parameters.
  * 
  * @param SWFShape $shape
  * @param ezcGraphColor $color 
  * @param mixed $thickness 
  * @param mixed $filled 
  * @return void
  */
 protected function setShapeColor(SWFShape $shape, ezcGraphColor $color, $thickness, $filled)
 {
     if ($filled) {
         switch (true) {
             case $color instanceof ezcGraphLinearGradient:
                 $gradient = new SWFGradient();
                 $gradient->addEntry(0, $color->startColor->red, $color->startColor->green, $color->startColor->blue, 255 - $color->startColor->alpha);
                 $gradient->addEntry(1, $color->endColor->red, $color->endColor->green, $color->endColor->blue, 255 - $color->endColor->alpha);
                 $fill = $shape->addFill($gradient, SWFFILL_LINEAR_GRADIENT);
                 // Calculate desired length of gradient
                 $length = sqrt(pow($color->endPoint->x - $color->startPoint->x, 2) + pow($color->endPoint->y - $color->startPoint->y, 2));
                 $fill->scaleTo($this->modifyCoordinate($length) / 32768, $this->modifyCoordinate($length) / 32768);
                 $fill->rotateTo(rad2deg(asin(($color->endPoint->x - $color->startPoint->x) / $length) + 180));
                 $fill->moveTo($this->modifyCoordinate(($color->startPoint->x + $color->endPoint->x) / 2), $this->modifyCoordinate(($color->startPoint->y + $color->endPoint->y) / 2));
                 $shape->setLeftFill($fill);
                 break;
             case $color instanceof ezcGraphRadialGradient:
                 $gradient = new SWFGradient();
                 $gradient->addEntry(0, $color->startColor->red, $color->startColor->green, $color->startColor->blue, 255 - $color->startColor->alpha);
                 $gradient->addEntry(1, $color->endColor->red, $color->endColor->green, $color->endColor->blue, 255 - $color->endColor->alpha);
                 $fill = $shape->addFill($gradient, SWFFILL_RADIAL_GRADIENT);
                 $fill->scaleTo($this->modifyCoordinate($color->width) / 32768, $this->modifyCoordinate($color->height) / 32768);
                 $fill->moveTo($this->modifyCoordinate($color->center->x), $this->modifyCoordinate($color->center->y));
                 $shape->setLeftFill($fill);
                 break;
             default:
                 $fill = $shape->addFill($color->red, $color->green, $color->blue, 255 - $color->alpha);
                 $shape->setLeftFill($fill);
                 break;
         }
     } else {
         $shape->setLine($this->modifyCoordinate($thickness), $color->red, $color->green, $color->blue, 255 - $color->alpha);
     }
 }
Example #3
0
#!/usr/bin/php
<?php 
$m = new SWFMovie(8);
$shape = new SWFShape();
$gradient = new SWFGradient();
$gradient->addEntry(0, 255, 0, 0, 255);
$gradient->addEntry(0.25, 0x80, 0x20, 0x20, 0xff);
$gradient->addEntry(0.8, 0x40, 0x40, 0x40, 0xff);
$fill = $shape->addGradientFill($gradient, SWFFILL_LINEAR_GRADIENT);
#$fill->moveTo(-163, -163); # this is added by swftoscript, but is wrong
$shape->setLine(1, 0, 0, 0, 255);
$shape->setRightFill($fill);
$shape->drawLine(100, 0);
$shape->drawLine(0, 100);
$shape->drawLine(-100, 0);
$shape->drawLine(0, -100);
$m->add($shape);
$m->save("test08.swf");
Example #4
0
$values["B"] = rand(20, 230);
$values["C"] = rand(20, 230);
$values["D"] = rand(20, 230);
$values["E"] = rand(20, 230);
$values["F"] = rand(20, 270);
$values["G"] = rand(20, 270);
$values["H"] = rand(20, 270);
$max = 270;
$width = 540;
$height = 320;
$m = new SWFMovie();
$m->setDimension($width, $height);
$m->setBackground(251, 121, 34);
$m->setRate(30.0);
$font = new SWFFont("BabelSans-B.fdb");
$g = new SWFGradient();
$g->addEntry(0.0, 0, 0, 0);
$g->addEntry(1.0, 0xff, 0xff, 0xff);
function box($w, $h)
{
    global $g;
    $s = new SWFShape();
    $f = $s->addFill($g, SWFFILL_LINEAR_GRADIENT);
    $f->scaleTo(0.05);
    $s->setRightFill($f);
    //$s->setRightFill($s->addFill(255,255,255));
    $s->movePenTo(0, 0);
    $s->drawLineTo($w, 0);
    $s->drawLineTo($w, -$h);
    $s->drawLineTo(0, -$h);
    $s->drawLineTo(0, 0);
Example #5
0
 /**
  * Draw a rectangle filled with a gradient from $color1 to
  * $color2.
  *
  * @param integer $x       The left x-coordinate of the rectangle.
  * @param integer $y       The top y-coordinate of the rectangle.
  * @param integer $width   The width of the rectangle.
  * @param integer $height  The height of the rectangle.
  * @param string  $color   The outline color of the rectangle.
  * @param string  $fill1   The name of the start color for the gradient.
  * @param string  $fill2   The name of the end color for the gradient.
  */
 function gradientRectangle($x, $y, $width, $height, $color = 'black', $fill1 = 'black', $fill2 = 'white')
 {
     $s = new SWFShape();
     if ($color != 'none') {
         $color = $this->allocateColor($color);
         $s->setLine(1, $color['red'], $color['green'], $color['blue'], $color['alpha']);
     }
     $fill1 = $this->allocateColor($fill1);
     $fill2 = $this->allocateColor($fill2);
     $gradient = new SWFGradient();
     $gradient->addEntry(0.0, $fill1['red'], $fill1['green'], $fill1['blue'], $fill1['alpha']);
     $gradient->addEntry(1.0, $fill2['red'], $fill2['green'], $fill2['blue'], $fill2['alpha']);
     $f = $s->addFill($gradient, SWFFILL_LINEAR_GRADIENT);
     $f->scaleTo($width / $this->_width);
     $f->moveTo($x, $y);
     $s->setRightFill($f);
     $verts[0] = array('x' => $x, 'y' => $y);
     $verts[1] = array('x' => $x + $width, 'y' => $y);
     $verts[2] = array('x' => $x + $width, 'y' => $y + $height);
     $verts[3] = array('x' => $x, 'y' => $y + $height);
     $first_done = false;
     foreach ($verts as $vert) {
         if (!$first_done) {
             $s->movePenTo($vert['x'], $vert['y']);
             $first_done = true;
             $first_x = $vert['x'];
             $first_y = $vert['y'];
         }
         $s->drawLineTo($vert['x'], $vert['y']);
     }
     $s->drawLineTo($first_x, $first_y);
     return $this->_movie->add($s);
 }