-
Notifications
You must be signed in to change notification settings - Fork 44
/
simple_clip.py
50 lines (40 loc) · 1.11 KB
/
simple_clip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import print_function
import time
from kiva.image import GraphicsContext
samples = 1
pt = (250, 250)
sz = (100, 100)
transparent = (1,1,1,0.)
gc_img = GraphicsContext((500,500))
#gc_img.clear(transparent)
# clear isn't working...
gc_img.bmp_array[:] = (255,255,255,0)
gc_img.set_fill_color((1,0,0,.5))
gc_img.set_stroke_color((0,0,1))
gc_img.rect(pt[0],pt[1],sz[0],sz[1])
gc_img.draw_path()
gc_main = GraphicsContext((500,500))
gc_main.set_fill_color((0,0,1,.5))
gc_main.set_stroke_color((0,1,0))
gc_main.rect(300,300,100,100)
gc_main.draw_path()
gc_main.clip_to_rect(pt[0],pt[1],sz[0],sz[1])
t1 = time.clock()
for i in range(samples):
gc_main.draw_image(gc_img)
t2 = time.clock()
print('with clip', t2 - t1)
gc_main.save("with_clip.bmp")
#gc_main.clear(transparent)
gc_main.bmp_array[:] = (255,255,255,255)
gc_main.clear_clip_path()
gc_main.set_fill_color((0,0,1,.5))
gc_main.set_stroke_color((0,1,0))
gc_main.rect(300,300,100,100)
gc_main.draw_path()
t1 = time.clock()
for i in range(samples):
gc_main.draw_image(gc_img)
t2 = time.clock()
print('without clip', t2 - t1)
gc_main.save("without_clip.bmp")