PHP Classes

File: example/motion.php

Recommend this page to a friend!
  Classes of Edgar Asatryan   PHP SVG Magick Library   example/motion.php   Download  
File: example/motion.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP SVG Magick Library
Compose vectorial graphics in SVG format
Author: By
Last change:
Date: 7 years ago
Size: 1,535 bytes
 

Contents

Class file image Download
<?php

use nstdio\svg\animation\AnimateMotion;
use
nstdio\svg\animation\MPath;
use
nstdio\svg\container\SVG;
use
nstdio\svg\desc\Desc;
use
nstdio\svg\shape\Circle;
use
nstdio\svg\shape\Path;
use
nstdio\svg\shape\Rect;

require_once
__DIR__ . '/../vendor/autoload.php';

$svg = new SVG("5cm", "3cm");
$svg->getElement()->setAttribute('viewBox', '0 0 500 300');

$desc = new Desc($svg, 'Example animMotion01 - demonstrate motion animation computations');
$svg->append($desc);

$rect = new Rect($svg, 298, 498, 1, 1);
$rect->fill = "none";
$rect->stroke = "blue";
$rect->strokeWidth = 2;
$svg->append($rect);

$path = new Path($svg, 100, 250);
$path->id = 'path1';
$path->curveTo(100,50, 400,50, 400,250);
$path->fill = "none";
$path->stroke = "blue";
$path->strokeWidth = 7.06;

$svg->append($path);

$circle1 = new Circle($svg, 100, 250, 17.64);
$circle2 = new Circle($svg, 250, 100, 17.64);
$circle3 = new Circle($svg, 400, 250, 17.64);
$circle1->fill = "blue";
$circle2->fill = "blue";
$circle3->fill = "blue";

$svg->append($circle1, $circle2, $circle3);

$path2 = new Path($svg, -25, -12.5);
$path2->lineTo(25, -12.5)
    ->
lineTo(0, -87.5)
    ->
closePath(false);
$path2->fill = "yellow";
$path2->stroke = "red";
$path2->strokeWidth = 7.06;

$svg->append($path2);

$mpath = new MPath($svg, $path);

$motion = new AnimateMotion($svg, $mpath);
$motion->dur = '6s';
$motion->repeatCount = 'indefinite';
$motion->rotate = 'auto';

$path2->append($motion);

//header('Content-Encoding: gzip');
echo mb_strlen(gzencode($svg->draw(), 9));