[ Index ] |
|
Code source de jpGraph 2.2 |
1 <?php 2 include ("../jpgraph.php"); 3 include ("../jpgraph_scatter.php"); 4 5 $polex = 6; 6 $poley = 40; 7 8 function FldCallback($x,$y,$a) { 9 GLOBAL $polex, $poley; 10 $maxr = 3000; 11 12 // Size and arrow size is constant 13 $size=""; 14 $arrowsize=""; 15 16 // Since we have different scales we need the data points 17 // to be of the same magnitude to give it a distance 18 // interpretation. 19 $x *= 10; 20 21 // Colors gets colder the further out we go from the center 22 $r = ($x-$polex*10)*($x-$polex*10)+($y-$poley)*($y-$poley); 23 $f = $r/$maxr; 24 if( $f > 1 ) $f=1; 25 $red = floor((1-$f)*255); 26 $blue = floor($f*255); 27 $color = array($red,0,$blue); 28 //echo "x=$x, y=$y, blue=$blue, red=$red<br>"; 29 return array($color,$size,$arrowsize); 30 } 31 32 // Create data for a simulated pseudo-magnetic radient field 33 $datax = array(); 34 $datay = array(); 35 $angle = array(); 36 for($x=1; $x < 10; ++$x ) { 37 for($y=10; $y<100; $y += 10) { 38 $a = -1; 39 if( $x==$polex && $y==$poley ) continue; 40 if( $x==$polex ) { 41 if( $y > $poley ) $a=90; 42 else $a = 270; 43 } 44 if( $y==$poley ) { 45 if( $x > $polex ) $a=0; 46 else $a=180; 47 } 48 if( $a == -1 ) { 49 $d1 = $y-$poley; 50 $d2 = ($polex-$x)*20; 51 if( $y < $poley ) $d2 *= -1; 52 $h = sqrt($d1*$d1+$d2*$d2); 53 $t = -$d2/$h; 54 $ac = acos($t); 55 if( $y < $poley ) $ac += M_PI; 56 $a = $ac * 180/M_PI; 57 } 58 $datax[] = $x; 59 $datay[] = $y; 60 $angle[] = $a; 61 } 62 } 63 64 // Setup the graph 65 $graph = new Graph(300,200); 66 $graph->SetScale("intlin",0,100,0,10); 67 $graph->SetMarginColor('lightblue'); 68 69 70 // ..and titles 71 $graph->title->Set("Field plot"); 72 73 // Setup the field plot 74 $fp = new FieldPlot($datay,$datax,$angle); 75 76 // Setup formatting callback 77 $fp->SetCallback('FldCallback'); 78 79 // First size argument is length (in pixels of arrow) 80 // Second size argument is roughly size of arrow. Arrow size is specified as 81 // an integer in the range [0,9] 82 $fp->arrow->SetSize(20,2); 83 $fp->arrow->SetColor('navy'); 84 85 $graph->Add($fp); 86 87 // .. and output 88 $graph->Stroke(); 89 90 ?> 91 92
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:27:55 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |