PHP code example of alto / bezier

1. Go to this page and download the library: Download alto/bezier library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alto / bezier example snippets


use Alto\Bezier\CubicCurve;
use Alto\Bezier\Point;

$curve = new CubicCurve(
    new Point(0, 0),
    new Point(40, 160),
    new Point(160, -40),
    new Point(200, 120)
);

$mid = $curve->pointAt(0.5);
[$left, $right] = $curve->split(0.4);
$heading = $curve->tangent(0.5);

use Alto\Bezier\QuadraticCurve;
use Alto\Bezier\NOrderCurve;
use Alto\Bezier\Point;

$quadratic = new QuadraticCurve(
    new Point(0, 0),
    new Point(50, 120),
    new Point(120, 0)
);

$wave = new NOrderCurve(...array_map(
    fn(int $i) => new Point($i * 20, sin($i / 2) * 40 + 60),
    range(0, 7)
));

$path = sprintf(
    'M %s C %s %s %s',
    ...array_map(fn(Point $p) => $p->x.' '.$p->y, $curve->toArray())
);