1::<?php
2::// grphTri.php
3::// program to graph triangles
4::// ver 1.007 Andy Carter
5::// 1.008 $startY = $startY + $incY; to $startY += $incY
6::// 1.009 saved to "A" directory
7:://
8::// called by GET parameter passing
9:://
10::// sample GET input:
11::// width=400&height=208&Ybase=193&Ypeak=15&Xleft=15&Xpeak=148&Xright=385&Aside=2&Bside=1&Cside=3&S1=4&S2=5&S3=3&A1=53.1&A2=90&A3=36.9
12:://
13::// $width=400$height=208 image height and width
14::// $Ybase=193$Ypeak=15 from upper left: Y's triangle base and peak
15::// $Xleft=15$Xpeak=148$Xright=385 from upper: left X's left,peak
16::// $Aside=2$Bside=1$Cside=3 numbers to place on sides A bot B right C left
17::// angles opposite of sides a. top b. left c. right
18::// $S1=4$S2=5$S3=3 lengths of sides (to place in background)
19::// $A1=53.1$A2=90$A3=36.9 values angles (to place in background)
20::// $L1,$L2,$L3 optional alternatives to $S1=4$S2=5$S3=3
21::// $Title optional
22::// $iName set by calling program is this one were to save images NOT IMPLEMENTED
23::
24::$image = ImageCreate($width,$height);
25::$gbcolor = imagecolorallocate($image,192,192,192);
26::$black = imagecolorallocate($image,0,0,0);
27::$red = imagecolorallocate($image,255,0,0);
28::$green = imagecolorallocate($image,0,130,0);
29::
30::// Draw the triangle
31:: imageline($image,($Xleft-1),($Ybase-1),($Xright-1),($Ybase-1),$black);
32:: imageline($image,($Xright-1),($Ybase-1),($Xpeak-1),($Ypeak-1),$black);
33:: imageline($image,($Xleft-1),($Ybase-1),($Xpeak-1),($Ypeak-1),$black);
34::
35::
36::$sideNum = array ( (1*$Aside), (1*$Bside),(1*$Cside) );
37::
38::function shiftX($x) // attempt to place text centered
39:: {
40:: return($x-8);
41:: }
42::
43::function shiftY($y) // attempt to place text centered
44:: {
45:: return($y-10);
46:: }
47::
48::
49::// write out text information
50::$font = 4;
51::$startY = 10;
52::$incY = 12;
53::$font = 4;
54::// optional title
55::if(isset($Title)) {
56:: imagestring($image, $font, $Xleft , $startY,"::$Title", $green) ;
57:: $startY += $incY;
58:: }
59::// side information $Lx where x=1 .. 3 optional side information
60::// Lx could be as text of feet and inches
61::if(isset( $L1)) $desc = $L1; else $desc = $S1;
62:: imagestring($image, $font, $Xleft , $startY,"S1: $desc", $green) ;
63:: $startY += $incY ;
64::
65::if(isset( $L2)) $desc = $L2; else $desc = $S2;
66:: imagestring($image, $font, $Xleft , $startY,"S2: $desc", $green) ;
67:: $startY += $incY ;
68::if(isset( $L3)) $desc = $L3; else $desc = $S3;
69:: imagestring($image, $font, $Xleft , $startY,"S3: $desc ", $green) ;
70:: $startY += $incY ;
71::
72::// angle information
73:: imagestring($image, $font, $Xleft , $startY,"A1: $A1", $green) ;
74:: $startY += $incY ;
75::
76:: imagestring($image, $font, $Xleft , $startY,"A2: $A2", $green) ;
77:: $startY += $incY ;
78::
79:: imagestring($image, $font, $Xleft , $startY,"A3: $A3", $green) ;
80:: $startY += $incY ;
81::
82::// label sides and vertices
83:: for($cnt=0;$cnt<3;$cnt++) // 0,1,2 = sides & angles A,B,C
84:: {
85:: $subLabel = $sideNum[$cnt];
86:: switch($cnt)
87:: {
88:: case 0: // angle at peak horizontal line at
89:: imagestring($image, $font,shiftX($Xpeak),shiftY($Ypeak),"A$subLabel",$red);
90:: imagestring($image, $font,shiftX(($Xleft+$Xright)/2),shiftY($Ybase),"S$subLabel",$red);
91:: break;
92:: case 1: // angle at left right side
93:: imagestring($image, $font,shiftX($Xleft),shiftY($Ybase),"A$subLabel",$red);
94:: imagestring($image, $font,shiftX(($Xpeak+$Xright)/2),shiftY(($Ypeak+$Ybase)/2),"S$subLabel",$red);
95:: break;
96:: case 2: // angle at right left side
97:: imagestring($image, $font,shiftX($Xright),shiftY($Ybase),"A$subLabel",$red);
98:: imagestring($image, $font,shiftX(($Xpeak+$Xleft)/2),shiftY(($Ypeak+$Ybase)/2),"S$subLabel",$red);
99:: break;
100:: }
101:: }
102::
103::header("Content-type: image/png");
104::imagepng ($image);
105::imagedestroy($image);
106::?>
107::