- var_dump: documentation ( source)
- rand: documentation ( source)
<?php
class Point {
public $X;
public $Y;
function __construct($X, $Y)
{
$this->X = $X;
$this->Y = $Y;
}
}
$moves = 10;
$mouseX = 200;
$mouseY = 200;
$point = new Point(300, 300);
$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 - $mouseX)*$xCoefs[$i]/$moves;
$y = $points[$i-1]->Y + ($point->Y - $mouseY)/$moves;
$points[] = new Point($x, $y);
}
var_dump($points);