def test_add_colors(self): lg = LinearGradient() lg.add_colors(['white', 'red', 'blue', 'green'], opacity=0.5) result = '<linearGradient>' \ '<stop offset="0.0" stop-color="white" stop-opacity="0.5" />' \ '<stop offset="0.333" stop-color="red" stop-opacity="0.5" />' \ '<stop offset="0.667" stop-color="blue" stop-opacity="0.5" />' \ '<stop offset="1.0" stop-color="green" stop-opacity="0.5" />' \ '</linearGradient>' self.assertEqual(lg.tostring(), result)
except KeyError: return random.sample(colors[using_color][label - 1], 1)[0] else: return random.sample(colors[using_color], 1)[0] if have_gradient: defs = Defs(id='gradients') colors_gradient = [] gradient_direction = [(1, 1), (0, 1), (1, 0)] for gradient_index in range(gradient_cnt): l_g = LinearGradient((0, 0), random.choice(gradient_direction), id='gradient_%d' % gradient_index) l_g.add_colors(random.sample(colors[using_color], 2)) defs.add(l_g) colors_gradient.append('url(#gradient_%d)' % gradient_index) colors[using_color] += colors_gradient dwg.add(defs) # start x_p0 = [] for i in range(triangle_leftest + 1): x_p0.append(0) if uni_left: y_p0 = [] for i in range(triangle_leftest + 1): y_p0.append(int(height / triangle_leftest * i))