Zon

From Projects - ronaldteune.nl
Jump to: navigation, search


Work in progress code

<?php

$ha = -225; // house angle (0 = north, -180 = south)
$h = 1.98; // distance from roof to mirror (m)
$HB = 3.7; // width of house
$B = $HB - 1.32; // distance from left to mirror
$HL = 7.44; // length of house
$delta_e = 0; // additional height angle

$arr = file('asp2.csv');
//var_dump($a[0]);

$gd = imagecreatetruecolor(4000, 8000);

$red = imagecolorallocate($gd, 255, 0, 0); 
$green = imagecolorallocate($gd, 0, 150, 0);

$white = imagecolorallocate($gd, 255, 255, 255);

$black = imagecolorallocate($gd, 0, 0, 0);

imagefill($gd,0,0,$white);

imagerectangle($gd,0,0,1000*$HB,1000*$HL,$black);

$cols[0] = $black;
$cols[1] = $black;
$cols[2] = $black;
$cols[3] = imagecolorallocate($gd, 0, 0, 255);
$cols[4] = imagecolorallocate($gd, 0, 150, 0);
$cols[5] = imagecolorallocate($gd, 150, 150, 0);
$cols[6] = imagecolorallocate($gd, 150, 150, 150);
$cols[7] = imagecolorallocate($gd, 0, 150, 150);
$cols[8] = imagecolorallocate($gd, 150, 0, 150);
$cols[9] = imagecolorallocate($gd, 255, 0, 0);
$cols[10] = imagecolorallocate($gd, 0, 255, 0);
$cols[11] = $black;
$cols[12] = $black;



$debug = isset($_GET['debug']);

imagefilledrectangle($gd, round(($B*1000))-15,0,round(($B*1000))+15,30, $black);
for($i = 0; $i < $HB*1000; $i += 100) {
	imageline($gd, $i, 0, $i, $HL*1000,$black);
}
for($i = 0; $i < $HL*1000; $i += 100) {
	imageline($gd, 0,$i, $HB*1000, $i,$black);
}

for ($j = 1; $j < 365; $j++) {
	$row = explode(';',$arr[$j]);
	//var_dump($row);
	//var_dump($arr[$j]);
	//echo "<br>";
	$date = $row[0];
	$month = intval(substr($date,5,2));
	$t = 0;

	
	for($i = 1; $i < sizeof($row)-1; $i+=2) {
		
		$e = $row[$i]=='--'?0:$row[$i]+$delta_e; // height-angle
		$a = $row[$i+1]=='--'?0:$row[$i+1] + $ha; // width-angle
		if($debug)
			echo 'Time: '.$t.', E='.$e.', A='.$a.'<br />';
		
		$d = $h * tan(deg2rad(90-$e));
		$b = sin(deg2rad($a)) * $d;
		$l = sqrt(pow($d,2) - pow($b,2));
		if($debug)
			echo 'b='.$b.', l='.$l.', d='.$d.'<br /><br/>';
		
		$col = $cols[$month];
		if($t == 14)
			$col = $black;
		
		$t++;
		if($row[$i] == '--' || $row[$i+1] == '--')
			continue;	// no sun
		if(abs($a) > 90)
			continue; // sun out of view
		$X = round($b*-1*1000+$B*1000);
		$Y = round($l*1000);
		if($debug)
			echo $X.','.$Y.'<br /><br />';
		imagefilledrectangle($gd,$X-5,$Y-5,$X+5,$Y+5,$col);
		
		
	}
}
if(!$debug)
	header('Content-Type: image/png');
imagepng($gd);

?>