@@ -650,6 +650,19 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
650
650
self ._path_collection_id += 1
651
651
652
652
def draw_gouraud_triangle (self , gc , points , colors , trans ):
653
+ """
654
+ Write the code for a gouraud-shaded triangle to ``self.writer``.
655
+
656
+ Parameters
657
+ ----------
658
+ gc : `.GraphicsContextBase`
659
+ The graphics context.
660
+ points : (3, 2) array
661
+ The x and y coordinates of the three triangle points.
662
+ colors : (3, 4) array
663
+ The RGBA values of the three triangle points.
664
+ trans : `.Transform`
665
+ """
653
666
# This uses a method described here:
654
667
#
655
668
# http://www.svgopen.org/2005/papers/Converting3DFaceToSVG/index.html
@@ -685,9 +698,9 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
685
698
' \n 1 1 1 1 0 \n 0 0 0 0 1 ' )
686
699
writer .end ('filter' )
687
700
688
- avg_color = np .sum (colors [:, :], axis = 0 ) / 3.0
689
- # Just skip fully-transparent triangles
690
- if avg_color [ - 1 ] == 0.0 :
701
+ avg_color = np .average (colors , axis = 0 )
702
+ if avg_color [ - 1 ] == 0 :
703
+ # Skip fully-transparent triangles
691
704
return
692
705
693
706
trans_and_flip = self ._make_flip_transform (trans )
@@ -698,7 +711,7 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
698
711
x1 , y1 = tpoints [i ]
699
712
x2 , y2 = tpoints [(i + 1 ) % 3 ]
700
713
x3 , y3 = tpoints [(i + 2 ) % 3 ]
701
- c = colors [i ][: ]
714
+ rgba_color = colors [i ]
702
715
703
716
if x2 == x3 :
704
717
xb = x2
@@ -723,12 +736,13 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
723
736
writer .element (
724
737
'stop' ,
725
738
offset = '1' ,
726
- style = generate_css ({'stop-color' : rgb2hex (avg_color ),
727
- 'stop-opacity' : short_float_fmt (c [- 1 ])}))
739
+ style = generate_css ({
740
+ 'stop-color' : rgb2hex (avg_color ),
741
+ 'stop-opacity' : short_float_fmt (rgba_color [- 1 ])}))
728
742
writer .element (
729
743
'stop' ,
730
744
offset = '0' ,
731
- style = generate_css ({'stop-color' : rgb2hex (c ),
745
+ style = generate_css ({'stop-color' : rgb2hex (rgba_color ),
732
746
'stop-opacity' : "0" }))
733
747
734
748
writer .end ('linearGradient' )
0 commit comments