From 21702826896371885195404288af11e4c8a1be13 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Tue, 2 Mar 2021 14:01:10 -0600 Subject: [PATCH 1/4] add a draw_gradient example to the benchmarking suite --- enable/gcbench/suite.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/enable/gcbench/suite.py b/enable/gcbench/suite.py index 39bb9d867..9616a0b15 100644 --- a/enable/gcbench/suite.py +++ b/enable/gcbench/suite.py @@ -52,6 +52,18 @@ def gen_points(count=100): return points.reshape(count // 2, 2) +def gen_moderate_complexity_path(obj): + import math + + obj.arc(150, 100, 50, math.pi, 1.5*math.pi) + obj.move_to(150,50) + obj.line_to(250, 75) + obj.line_to(150, 100) + obj.curve_to(115, 75, 135, 125, 100, 100) + + return obj + + class draw_path: def __init__(self, gc, module): self.gc = gc @@ -137,3 +149,25 @@ def __call__(self): self.gc.set_text_position(4, y) self.gc.show_text(line) y -= self.font.size * 1.4 + + +class draw_gradient: + def __init__(self, gc, module): + self.gc = gc + + def __call__(self): + import numpy as np + # colors are 5 doubles: offset, red, green, blue, alpha + starting_color = np.array([0.0, 1.0, 1.0, 1.0, 1.0]) + ending_color = np.array([1.0, 0.0, 0.0, 0.0, 1.0]) + with self.gc: + gen_moderate_complexity_path(self.gc) + self.gc.linear_gradient( + 100, + 100, + 250, + 75, + np.array([starting_color, ending_color]), + 'pad', + ) + self.gc.fill_path() From d93e0982fa83dd11efb056ada8e235d1b16d5895 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Tue, 2 Mar 2021 14:16:22 -0600 Subject: [PATCH 2/4] add a show_text_radial_gradient benchmark example to the suite --- enable/gcbench/suite.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/enable/gcbench/suite.py b/enable/gcbench/suite.py index 9616a0b15..e84132aac 100644 --- a/enable/gcbench/suite.py +++ b/enable/gcbench/suite.py @@ -151,7 +151,7 @@ def __call__(self): y -= self.font.size * 1.4 -class draw_gradient: +class draw_path_linear_gradient: def __init__(self, gc, module): self.gc = gc @@ -171,3 +171,41 @@ def __call__(self): 'pad', ) self.gc.fill_path() + + +class show_text_radial_gradient: + def __init__(self, gc, module): + from kiva.api import Font + + self.text = [ + 'The quick brown', + 'fox jumped over', + 'the lazy dog', + '狐假虎威', + ] + self.font = Font('Times New Roman', size=36) + self.gc = gc + + def __call__(self): + import numpy as np + from kiva import constants + + starting_color = np.array([0.0, 1.0, 1.0, 1.0, 1.0]) + ending_color = np.array([1.0, 0.0, 0.0, 0.0, 1.0]) + with self.gc: + self.gc.radial_gradient( + 128, + 128, + 150, + 128, + 128, + np.array([starting_color, ending_color]), + 'pad', + ) + self.gc.set_text_drawing_mode(constants.TEXT_FILL_STROKE) + self.gc.set_font(self.font) + y = 256 - self.font.size * 1.4 + for line in self.text: + self.gc.set_text_position(4, y) + self.gc.show_text(line) + y -= self.font.size * 1.4 \ No newline at end of file From eb2ff9a6792073f2d56ed6dfbc912b8b23b3dd12 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Tue, 2 Mar 2021 14:22:16 -0600 Subject: [PATCH 3/4] newline at end of file --- enable/gcbench/suite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enable/gcbench/suite.py b/enable/gcbench/suite.py index e84132aac..a2c62da7a 100644 --- a/enable/gcbench/suite.py +++ b/enable/gcbench/suite.py @@ -208,4 +208,4 @@ def __call__(self): for line in self.text: self.gc.set_text_position(4, y) self.gc.show_text(line) - y -= self.font.size * 1.4 \ No newline at end of file + y -= self.font.size * 1.4 From 1bd220c68dc8f942bd64ca1ff547defddc08898f Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Wed, 3 Mar 2021 07:19:34 -0600 Subject: [PATCH 4/4] suggestions from code review --- enable/gcbench/suite.py | 52 +++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/enable/gcbench/suite.py b/enable/gcbench/suite.py index a2c62da7a..aecd2aecd 100644 --- a/enable/gcbench/suite.py +++ b/enable/gcbench/suite.py @@ -56,10 +56,10 @@ def gen_moderate_complexity_path(obj): import math obj.arc(150, 100, 50, math.pi, 1.5*math.pi) - obj.move_to(150,50) + obj.move_to(150, 50) obj.line_to(250, 75) obj.line_to(150, 100) - obj.curve_to(115, 75, 135, 125, 100, 100) + obj.curve_to(115, 75, 135, 125, 100, 100) return obj @@ -153,30 +153,43 @@ def __call__(self): class draw_path_linear_gradient: def __init__(self, gc, module): - self.gc = gc - - def __call__(self): import numpy as np # colors are 5 doubles: offset, red, green, blue, alpha starting_color = np.array([0.0, 1.0, 1.0, 1.0, 1.0]) ending_color = np.array([1.0, 0.0, 0.0, 0.0, 1.0]) + self.grad_args = ( + 100, + 100, + 250, + 75, + np.array([starting_color, ending_color]), + 'pad', + ) + self.gc = gc + + def __call__(self): with self.gc: gen_moderate_complexity_path(self.gc) - self.gc.linear_gradient( - 100, - 100, - 250, - 75, - np.array([starting_color, ending_color]), - 'pad', - ) + self.gc.linear_gradient(*self.grad_args) self.gc.fill_path() class show_text_radial_gradient: def __init__(self, gc, module): + import numpy as np from kiva.api import Font + starting_color = np.array([0.0, 1.0, 1.0, 1.0, 1.0]) + ending_color = np.array([1.0, 0.0, 0.0, 0.0, 1.0]) + self.grad_args = ( + 128, + 128, + 150, + 128, + 128, + np.array([starting_color, ending_color]), + 'pad', + ) self.text = [ 'The quick brown', 'fox jumped over', @@ -187,21 +200,10 @@ def __init__(self, gc, module): self.gc = gc def __call__(self): - import numpy as np from kiva import constants - starting_color = np.array([0.0, 1.0, 1.0, 1.0, 1.0]) - ending_color = np.array([1.0, 0.0, 0.0, 0.0, 1.0]) with self.gc: - self.gc.radial_gradient( - 128, - 128, - 150, - 128, - 128, - np.array([starting_color, ending_color]), - 'pad', - ) + self.gc.radial_gradient(*self.grad_args) self.gc.set_text_drawing_mode(constants.TEXT_FILL_STROKE) self.gc.set_font(self.font) y = 256 - self.font.size * 1.4