Skip to content

Instantly share code, notes, and snippets.

@Kyslik
Created March 1, 2019 09:05
Show Gist options
  • Save Kyslik/5b9a66b9b0852c91f1310c279a9f2543 to your computer and use it in GitHub Desktop.
Save Kyslik/5b9a66b9b0852c91f1310c279a9f2543 to your computer and use it in GitHub Desktop.
$points = [];
for ($x = 0; $x <= 349; $x++) {
for($y = 0; $y <= 349; $y++) {
$point = ['x' => $x, 'y' => $y, 'is_water' => false];
$rgb = imagecolorat($imageResource, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if ($r === $waterR && $g === $waterG && $b === $waterB) {
$point['is_water'] = true;
}
$points[] = $point;
}
}
Location::insert($points);
for ($x = 0; $x <= 349; $x++) {
$points = [];
for($y = 0; $y <= 349; $y++) {
$point = ['x' => $x, 'y' => $y, 'is_water' => false];
$rgb = imagecolorat($imageResource, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if ($r === $waterR && $g === $waterG && $b === $waterB) {
$point['is_water'] = true;
}
$points[] = $point;
}
Location::insert($points);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment