2015-04-29 22 views
9

Tôi đang làm việc với jpgraph và tạo biểu đồ radar.Tô màu gradient trong hình đa giác tùy chỉnh của tôi jpgraph

Đối mặt với vấn đề với tô màu đa giác tùy chỉnh tô đầy với màu gradient.

Tôi có chức năng điền vào một đa giác màu gradient với đáy phẳng và tôi muốn tô màu gradient trong đa giác hình dạng tùy chỉnh của tôi. Có ai giúp tôi không? Tôi có thể làm cái này như thế nào?

Output hiện tại:

enter image description here

mong muốn Output:

enter image description here

Bạn có thể tìm thấy những lớp gradient tại đây.

http://code.google.com/r/linksoftafrica-maison-george/source/browse/libs/jpgraph/jpgraph_gradient.php

// Fill a special case of a polygon with a flat bottom 
// with a gradient. Can be used for filled line plots. 
// Please note that this is NOT a generic gradient polygon fill 
// routine. It assumes that the bottom is flat (like a drawing 
// of a mountain) 
function FilledFlatPolygon($pts,$from_color,$to_color) { 
    if(count($pts) == 0) return; 

    $maxy=$pts[1]; 
    $miny=$pts[1];   
    $n = count($pts) ; 
    for($i=0, $idx=0; $i < $n; $i += 2) { 
     $x = round($pts[$i]); 
     $y = round($pts[$i+1]); 
     $miny = min($miny,$y); 
     $maxy = max($maxy,$y); 
    } 

    $colors = array(); 
    $this->GetColArray($from_color,$to_color,abs($maxy-$miny)+1,$colors,$this->numcolors); 
    for($i=$miny, $idx=0; $i <= $maxy; ++$i) { 
     $colmap[$i] = $colors[$idx++]; 
    } 

    $n = count($pts)/2 ; 
    $idx = 0 ; 
    while($idx < $n-1) { 
     $p1 = array(round($pts[$idx*2]),round($pts[$idx*2+1])); 
     $p2 = array(round($pts[++$idx*2]),round($pts[$idx*2+1])); 

     // Find the largest rectangle we can fill 
     $y = max($p1[1],$p2[1]) ; 
     for($yy=$maxy; $yy > $y; --$yy) { 
      $this->img->current_color = $colmap[$yy]; 
      $this->img->Line($p1[0],$yy,$p2[0]-1,$yy); 
     } 

     if($p1[1] == $p2[1]) continue; 

     // Fill the rest using lines (slow...) 
     $slope = ($p2[0]-$p1[0])/($p1[1]-$p2[1]); 
     $x1 = $p1[0]; 
     $x2 = $p2[0]-1; 
     $start = $y; 
     if($p1[1] > $p2[1]) { 
      while($y >= $p2[1]) { 
       $x1=$slope*($start-$y)+$p1[0]; 
       $this->img->current_color = $colmap[$y]; 
       $this->img->Line($x1,$y,$x2,$y); 
       --$y; 
      } 
     } 
     else { 
      while($y >= $p1[1]) { 
       $x2=$p2[0]+$slope*($start-$y); 
       $this->img->current_color = $colmap[$y]; 
       $this->img->Line($x1,$y,$x2,$y); 
       --$y; 
      } 
     } 
    } 
} 
+0

Bạn có thể muốn cung cấp mã của mình để mã có thể được sao chép. – spenibus

Trả lời

1

Có vẻ với tôi rằng mã hiện tại của bạn là không thích hợp cho nhiệm vụ này. Bạn cần mã cho hình tam giác có hình cầu Gouraud (đa giác 3 mặt).

Khi bạn có mã cho điều đó, bạn chỉ cần vẽ ba hình tam giác ở vị trí của tam giác nằm ở giữa biểu đồ và hai điểm nằm trên trục radar.

Thật không may, tôi không tìm thấy mã sẵn sàng cho jpgraph.

Các vấn đề liên quan