/** * Draw an arc. * * @param integer $x The x co-ordinate of the centre. * @param integer $y The y co-ordinate of the centre. * @param integer $r The radius of the arc. * @param integer $start The start angle of the arc. * @param integer $end The end angle of the arc. * @param string $color The line color of the arc. * @param string $fill The fill color of the arc. */ function arc($x, $y, $r, $start, $end, $color = 'black', $fill = 'none') { $s = new SWFShape(); $color = $this->allocateColor($color); $s->setLine(1, $color['red'], $color['green'], $color['blue'], $color['alpha']); if ($fill != 'none') { $fillColor = $this->allocateColor($fill); $f = $s->addFill($fillColor['red'], $fillColor['green'], $fillColor['blue'], $fillColor['alpha']); $s->setRightFill($f); } if ($end - $start <= 45) { $pts = Horde_Image::arcPoints($r, $start, $end); $s->movePenTo($x, $y); $s->drawLineTo($pts['x1'] + $x, $pts['y1'] + $y); $s->drawCurveTo($pts['x3'] + $x, $pts['y3'] + $y, $pts['x2'] + $x, $pts['y2'] + $y); $s->drawLineTo($x, $y); } else { $sections = ceil(($end - $start) / 45); for ($i = 0; $i < $sections; $i++) { $pts = Horde_Image::arcPoints($r, $start + $i * 45, $start + ($i + 1) * 45 > $end ? $end : $start + ($i + 1) * 45); // If we are on the first section, move the pen to the // centre and draw out to the edge. if ($i == 0 && $fill != 'none') { $s->movePenTo($x, $y); $s->drawLineTo($pts['x1'] + $x, $pts['y1'] + $y); } else { $s->movePenTo($pts['x1'] + $x, $pts['y1'] + $y); } // Draw the arc. $s->drawCurveTo($pts['x3'] + $x, $pts['y3'] + $y, $pts['x2'] + $x, $pts['y2'] + $y); } if ($fill != 'none') { // Draw a line from the edge back to the centre to close // off the segment. $s->drawLineTo($x, $y); } } return $this->_movie->add($s); }
<?php $s = new SWFShape(); $s->setLine(4, 0x7f, 0, 0); $s->setRightFill($s->addFill(0xff, 0, 0)); $s->movePenTo(10, 10); $s->drawLineTo(310, 10); $s->drawLineTo(310, 230); $s->drawCurveTo(10, 230, 10, 10); $m = new SWFMovie(); $m->setDimension(320, 240); $m->setRate(12.0); $m->add($s); $m->nextFrame(); header('Content-type: application/x-shockwave-flash'); $m->output();
/** * Draws a circle. * * @param integer $x The x co-ordinate of the centre. * @param integer $y The y co-ordinate of the centre. * @param integer $r The radius of the circle. * @param string $color The line color of the circle. * @param string $fill The color to fill the circle. */ public function circle($x, $y, $r, $color, $fill = 'none') { $s = new SWFShape(); $color = $this->allocateColor($color); $s->setLine(1, $color['red'], $color['green'], $color['blue'], $color['alpha']); if ($fill != 'none') { $fillColor = $this->allocateColor($fill); $f = $s->addFill($fillColor['red'], $fillColor['green'], $fillColor['blue'], $fillColor['alpha']); $s->setRightFill($f); } $a = $r * 0.414213562; // = tan(22.5 deg) $b = $r * 0.707106781; // = sqrt(2)/2 = sin(45 deg) $s->movePenTo($x + $r, $y); $s->drawCurveTo($x + $r, $y - $a, $x + $b, $y - $b); $s->drawCurveTo($x + $a, $y - $r, $x, $y - $r); $s->drawCurveTo($x - $a, $y - $r, $x - $b, $y - $b); $s->drawCurveTo($x - $r, $y - $a, $x - $r, $y); $s->drawCurveTo($x - $r, $y + $a, $x - $b, $y + $b); $s->drawCurveTo($x - $a, $y + $r, $x, $y + $r); $s->drawCurveTo($x + $a, $y + $r, $x + $b, $y + $b); $s->drawCurveTo($x + $r, $y + $a, $x + $r, $y); $this->_movie->add($s); }