#!/usr/bin/env python # coding: utf-8 # In[ ]: from ipycanvas import Canvas # # Gradients # # Unlike the Web2DCanvas, the color stops must be passed as a list of color stops when creating the gradient. Once created, the gradient is read-only, it cannot be modified. # # ## LinearGradient # # # In[ ]: canvas = Canvas(width=700, height=50) # In[ ]: gradient = canvas.create_linear_gradient( 0, 0, # Start position (x0, y0) 700, 0, # End position (x1, y1) # List of color stops [ (0, "red"), (1 / 6, "orange"), (2 / 6, "yellow"), (3 / 6, "green"), (4 / 6, "blue"), (5 / 6, "#4B0082"), (1, "violet"), ], ) # In[ ]: canvas.fill_style = gradient # In[ ]: canvas.fill_rect(0, 0, 700, 50) # In[ ]: canvas # ## RadialGradient # In[ ]: canvas2 = Canvas(width=570, height=200) # In[ ]: radial_gradient = canvas2.create_radial_gradient( 238, 50, 10, # Start circle (x0, y0, r0) 238, 50, 300, # End circle (x1, y1, r1) [ (0, "#8ED6FF"), (1, "#004CB3"), ], ) # In[ ]: canvas2.fill_style = radial_gradient # In[ ]: canvas2.fill_rect(0, 0, 570, 200) # In[ ]: canvas2