def gradientLine( ctx, points_list, hsl_palette_list, loop_palette = True ):
pal = hsl_palette_list[:]
if loop_palette:
pal.append( hsl_palette_list[0] ) # Duplicate first
rgb = Colz.hslToRgb( *pal[0] )
ctx.set_source_rgb( *rgb )
for i in range( 2, len(points_list), 2 ):
pal_pos = i * ( len(pal) - 1 ) / len(points_list)
col_current = math.floor( pal_pos )
col_next = math.ceil( pal_pos )
frac, whole = math.modf( pal_pos )
if col_current == col_next:
col_next = min( col_current + 1, len(pal) - 1 )
c_mix = Colz.interpolate( pal[col_current], pal[col_next], frac )
ctx.set_source_rgb( *c_mix.rgb )
ctx.move_to( points_list[i-2], points_list[i-1] )
ctx.line_to( points_list[i], points_list[i+1] )
ctx.stroke()
# Pass caito ctx, list of points, list of colors ( colz )
评论列表
文章目录