3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Point { public $x; public $y; function __construct($x, $y) { $this->x = $x; $this->y = $y; } } $moves = 10; $mouseX = 100; $mouseY = 100; $point = new Point(200, 200); $delta = 1/(1-rand(0, 99)/100); if (rand(0, 1) == 0) { $delta = 1/$delta; } $xCoefs = array($delta); for ( $i=1; $i<=$moves; $i++ ) { $xCoefs[$i] = $xCoefs[$i-1] - ($delta - 1/$delta)/$moves; } $points = array(new Point($mouseX, $mouseY)); for ( $i=1; $i<=$moves; $i++ ) { $x = $points[$i-1]->X + ($point->X - $points[$i-1]->X)*$xCoefs[$i]/$moves; $y = $points[$i-1]->Y + ($point->Y - $points[$i-1]->Y)/$moves; $points[] = new Point($x, $y); } var_dump($points);

preferences:
28.99 ms | 402 KiB | 5 Q