phpaintings: painting number 1: Microsoft stock quotes

http://www.lewislacook.com/phpaintings/painting1.php

Yes, it looks MUCH like the previous experiment I did with dynamically generated images(it should, seeing as how it's built on the previous experiment's code); this one, however, relies on external data to decide how many (randomly-placed)solid lines, dashed lines, and randomly-colored pixels to use. The external data is generated from Yahoo stock quotes for Microsoft stock…

SOURCE CODE HERE:
written in PHP, using the GD Library
__________________________________________________
/*
phpainting #1
by Lewis LaCook
August 2004
==generates psudo-random dynamic PNG, with lines and pixels determined by Microsoft stock
*/
Class yahoo
{
function get_stock_quote($symbol)
{
$url = sprintf("http://finance.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgv" ,$symbol);
$fp = fopen($url, "r");
if(!fp)
{
echo "error : cannot recieve stock quote information";
}
else
{
$array = fgetcsv($fp , 4096 , ', ');
fclose($fp);
$this->symbol = $array[0];
$this->last = $array[1];
$this->date = $array[2];
$this->time = $array[3];
$this->change = $array[4];
$this->open = $array[5];
$this->high = $array[6];
$this->low = $array[7];
$this->volume = $array[8];
}
}
}
$quote = new yahoo;
$quote->get_stock_quote("MSFT");
srand((double) microtime()*1000000);
//set up image
$heightd0;
$widthH0;
$rgbRange0=rand(0, 255);
$rgbRange1=rand(0, 255);
$rgbRange2=rand(0, 255);
$rgbRange3=rand(0, 255);
$rgbRange4=rand(0, 255);
$rgbRange5=rand(0, 255);
$rgbRange6=rand(0, 255);
$rgbRange7=rand(0, 255);
$rgbRange8=rand(0, 255);
$rgbRange=rand(0, 255);

$im=ImageCreate($width, $height);
$color[0]=ImageColorAllocate($im, $rgbRange0, $rgbRange5,$rgbRange8);
$color[1]=ImageColorAllocate($im, $rgbRange4, $rgbRange3, $rgbRange5);
$color[3]=ImageColorAllocate($im, $rgbRange8, $rgbRange2,$rgbRange1);
$color[4]=ImageColorAllocate($im, $rgbRange0, $rgbRange8, $rgbRange7);
$color[5]=ImageColorAllocate($im, $rgbRange5, $rgbRange8,$rgbRange6);
$color[6]=ImageColorAllocate($im, $rgbRange9, $rgbRange8, $rgbRange5);
$color[7]=ImageColorAllocate($im, $rgbRange5, $rgbRange1,$rgbRange8);
$color[8]=ImageColorAllocate($im, $rgbRange6, $rgbRange6, $rgbRange7);
//draw on image
//canvas
ImageFill($im, 0, 0, array_rand($color));

//pixels
for($i=0; $i <= $quote->last; $i++){
imagesetpixel($im, rand(0, 480), rand(0,640), array_rand($color));
}
//lines
//dashed
for($x=0; $x <= $quote->high; $x++){
imagedashedline($im,rand(0, 480), rand(0,640),rand(0, 480), rand(0,640),array_rand($color));
}
//filled
for($x=0; $x <= $quote->low; $x++){
imageline($im,rand(0, 480), rand(0,640),rand(0, 480), rand(0,640),array_rand($color));
}
//output image
Header("Content-type: image/png");
ImagePng($im);
//clean up
ImageDestroy($im);

_______________________________________________________









***************************************************************************

Lewis LaCook

net artist, poet, freelance web developer/programmer

http://www.lewislacook.com/

XanaxPop:Mobile Poem Blog>> http://www.lewislacook.com/xanaxpop/

Stamen Pistol: http://stamenpistol.blogspot.com/

Cell:440.258.9232

Sidereality: http://www.sidereality.com/

























———————————
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!