Jump to content

Pixel control with arrays


drseuss

Recommended Posts

Hello everyone,

 

i'm playing with the PHP GD library, just to keep myself practicing.

 

In the code I am grabbing the coords from a DB and putting them in an array.

 

The code works, but I don't think its the best way of doing it... it just doesn't look right.

 

I'm not really used to making arrays out of loops, but this is my code;

 

$place = 0;

$pixelQ = $class->query("select * from pixelCoords where owner='1'");
while($pixelF = $class->fetch()) {

$corners[$place+1] = array('x' => $pixelF['x'], 'y' => $pixelF['y']);
$place++;
}

This is a small part of the script, of me calling the array to be used;

 

imagesetpixel($gd, round($x),round($y), $red);
  $a = rand(1, $place);
  $x = ($x + $corners[$a]['x']) / 2;
  $y = ($y + $corners[$a]['y']) / 2;

Link to comment
https://forums.phpfreaks.com/topic/204592-pixel-control-with-arrays/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.