Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions enable/gcbench/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,3 +149,65 @@ def __call__(self):
self.gc.set_text_position(4, y)
self.gc.show_text(line)
y -= self.font.size * 1.4


class draw_path_linear_gradient:
def __init__(self, gc, module):
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])
Comment on lines +156 to +159
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this setup of the gradient array out of __call__ and into __init__.

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(*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',
'the lazy dog',
'狐假虎威',
]
self.font = Font('Times New Roman', size=36)
self.gc = gc

def __call__(self):
from kiva import constants

with self.gc:
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
for line in self.text:
self.gc.set_text_position(4, y)
self.gc.show_text(line)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL. Nothing renders this how I would expect.

y -= self.font.size * 1.4