Forum Archive

Gradients?

wsa

Any chance for linear and radial gradients in the canvas and scene modules in some future update?

There are ways to do this in pure python, but it ain't speedy.

omz

To some degree, you can simulate gradients with tinted images. Example:

from scene import *

class MyScene (Scene):
    def draw(self):
        background(0, 0, 0)
        fill(0, 0, 1) #blue
        rect(0, 0, 256, 256)
        tint(1, 0, 0) #red
        image('Gradient-1', 0, 0, 256, 256)

run(MyScene())

There are built-in 256x256 pixel images for different types of gradients ('Gradient-1' ... 'Gradient-5'). The gradients all go from fully-transparent to white, so you can achieve different 2-color gradients by drawing a filled rectangle behind the gradient image (which can be tinted with the second color, as in the example above).