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 = 4; $mouseX = 0; $mouseY = 0; $point = new Point(400, 400); //$startAngle = rand(0, 90); $startAngle = 30; echo 'Angle = '.$startAngle."\r\n"; $angles = array($startAngle); for ( $i=1; $i<$moves; $i++ ) { $angles[$i] = $angles[$i-1] + (90 - 2*$startAngle)/($moves-1); } $lineHeightDiv = 0; foreach ( $angles as $angle ) { $lineHeightDiv += sin($angle*pi()/180); } $lineHeight = ($point->Y-$mouseY)/$lineHeightDiv; echo 'LineHeight = '.$lineHeight."\r\n"; $lineWidthDiv = 0; foreach ( $angles as $angle ) { $lineWidthDiv += cos($angle*pi()/180); } $lineWidth = ($point->X-$mouseX)/$lineWidthDiv; echo 'LineWidth = '.$lineWidth."\r\n"; $points = array(new Point($mouseX, $mouseY)); for ( $i=1; $i<=$moves; $i++ ) { $x = $points[$i-1]->X + $lineWidth*cos($angles[$i]*pi()/180); $y = $points[$i-1]->Y + $lineHeight*sin($angles[$i]*pi()/180); $points[] = new Point($x, $y); } var_dump($points);

preferences:
48.95 ms | 402 KiB | 5 Q