def draw(ctx, width, height, frame_no, frame_count): ctx.set_source_rgba(*Color(1).get_rgba()) ctx.paint() for i in range(200): ctx.set_source_rgba(*Color.of_hsl(i / 200, 1, 0.5).get_rgba()) ctx.rectangle(i + 50, 50, 1, 50) ctx.fill() for i in range(200): ctx.set_source_rgba(*Color.of_hsl(0.25, i / 200, 0.5).get_rgba()) ctx.rectangle(i + 50, 150, 1, 50) ctx.fill() for i in range(200): ctx.set_source_rgba(*Color.of_hsl(0.25, 1, i / 200).get_rgba()) ctx.rectangle(i + 50, 250, 1, 50) ctx.fill()
def draw(ctx, width, height, frame_no, frame_count): ctx.set_source_rgba(*Color(1).get_rgba()) ctx.paint() ctx.set_source_rgba(*Color.of_hsl(0, 0.5, 0.5).get_rgba()) ctx.rectangle(50, 50, 100, 100) ctx.fill() ctx.set_source_rgba(*Color.of_hsl(0.33, 0.5, 0.5).get_rgba()) ctx.rectangle(200, 50, 100, 100) ctx.fill() ctx.set_source_rgba(*Color.of_hsl(0.66, 0.5, 0.5).get_rgba()) ctx.rectangle(350, 50, 100, 100) ctx.fill() ctx.set_source_rgba(*Color.of_hsl(0, 0.25, 0.5).get_rgba()) ctx.rectangle(50, 200, 100, 100) ctx.fill() ctx.set_source_rgba(*Color.of_hsl(0, 0.5, 0.25).get_rgba()) ctx.rectangle(200, 200, 100, 100) ctx.fill() ctx.set_source_rgba(*Color.of_hsl(0, 0.5, 0.5).get_rgba()) ctx.rectangle(330, 180, 100, 100) ctx.fill() ctx.set_source_rgba(*Color.of_hsla(0.5, 0.5, 0.5, 0.5).get_rgba()) ctx.rectangle(370, 220, 100, 100) ctx.fill()
def draw(ctx, width, height, frame_no, frame_count): ctx.set_source_rgba(*Color(0)) ctx.paint() # Vary hue, with s = 1, l = 0.5. # The hue is the position on the colour circle: # - hue 0 is pure red # - as hue increases the colour moves through yellow towards green # - hue 0.33 is pure green # - as hue increases the colour moves through cyan towards blue # - hue 0.66 is pure blue # - as hue increases the colour moves through magenta towards red # - as the hue approaches 1, the colour goes back to pure red. # This is a circular parameter, th eci#ycle starts again at 1 for i in range(200): ctx.set_source_rgba(*Color.of_hsl(i / 200, 1, 0.5)) ctx.rectangle(2 * i + 100, 100, 2, 100) ctx.fill() # Vary saturation, with h = 0.33 (green), l = 0.5. # With saturation 1, the colour is pure (fully saturated). # Reducing the saturation makes the colour more "grey". # When the saturation is 0, the colour is totally grey. All hues look identical ar zero saturation, # they all become the same grey (the shade og grey depends on the lightness value) for i in range(200): ctx.set_source_rgba(*Color.of_hsl(0.33, i / 200, 0.5)) ctx.rectangle(2 * i + 100, 300, 2, 100) ctx.fill() # Vary lightness, with h = 0.33 (green), s = 1. # Changing the lightness creates lighter or darker versions of the same colour, # rather like looking at the same object in a brighter or darker room. # When lightness is 0, all colours are black. When lightness is 1, all colours are white. for i in range(200): ctx.set_source_rgba(*Color.of_hsl(0.33, 1, i / 200)) ctx.rectangle(2 * i + 100, 500, 2, 100) ctx.fill()
def draw(ctx, width, height, frame_no, frame_count): ctx.set_source_rgba(*Color(1)) ctx.paint() # We use Color.of_hsl() to create an HSL colour. # A hue of 0 gives pure red. We then set the saturation ot 0.5, which greys the colour # out a little, and lightness to 0.5 which creates a slightly dark red. ctx.set_source_rgba(*Color.of_hsl(0, 0.5, 0.5)) ctx.rectangle(50, 50, 100, 100) ctx.fill() # Same as before, but a hue of 0.33 gives the equivalent green colour ctx.set_source_rgba(*Color.of_hsl(0.33, 0.5, 0.5)) ctx.rectangle(200, 50, 100, 100) ctx.fill() # Same as before, but a hue of 0.66 gives the equivalent blue colour ctx.set_source_rgba(*Color.of_hsl(0.66, 0.5, 0.5)) ctx.rectangle(350, 50, 100, 100) ctx.fill() ctx.set_source_rgba(*Color.of_hsl(0, 0.25, 0.5)) ctx.rectangle(50, 200, 100, 100) ctx.fill() ctx.set_source_rgba(*Color.of_hsl(0, 0.5, 0.25)) ctx.rectangle(200, 200, 100, 100) ctx.fill() ctx.set_source_rgba(*Color.of_hsl(0, 0.5, 0.5)) ctx.rectangle(330, 180, 100, 100) ctx.fill() # Here we create a rectangle with a colour Color.of_hsla(0.5, 0.5, 0.5, 0.3). # That is blue-green with a 0.3 alpha value (30% opacity, ie 70% transparent). # This overlaps the previous rectangle, and you can see the background through it. ctx.set_source_rgba(*Color.of_hsla(0.5, 0.5, 0.5, 0.3)) ctx.rectangle(370, 220, 100, 100) ctx.fill()
def draw_hsl(ctx, pixel_width, pixel_height, frame_no, frame_count): setup(ctx, pixel_width, pixel_height, background=Color('cornflowerblue')) pos = [10, 10] w = 70 h = 100 Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.1, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.2, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.3, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.4, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.5, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.6, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.7, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.8, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.9, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(1.0, 0.5, 0.5)) pos[0] += w pos = [10, 120] Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.0, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.1, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.2, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.3, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.4, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.6, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.7, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.8, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 0.9, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.0, 1.0, 0.5)) pos[0] += w pos = [10, 230] Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 0.0)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 0.1)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 0.2)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 0.3)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 0.4)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 0.5)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 0.6)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 0.7)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 0.8)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 0.9)) pos[0] += w Rectangle(ctx).of_corner_size(pos, w, h).fill(Color.of_hsl(0.66, 0.5, 1.0)) pos[0] += w