def draw_color_scheme(ctx, pixel_width, pixel_height, frame_no, frame_count): setup(ctx, pixel_width, pixel_height, background=Color("white")) # Fill a square with red Square(ctx).of_corner_size((50, 50), 200).fill(cs.RED) # Fill a square with a lighter version of RED, stroke with a darker version Square(ctx).of_corner_size( (300, 50), 200).fill(cs.RED.light1).stroke(cs.RED.dark1, 10)
def draw(ctx, width, height, frame_no, frame_count): setup(ctx, width, height, width=5, background=Color(0.8)) # The square function is a convenience function that adds a square as a new the path. # You can fill or stroke it as you wish. square(ctx, (1, 1), 1) ctx.set_source_rgba(*Color(1, 0, 0)) ctx.fill() # Square objects can be filled, stroked, filled and stroked. Square(ctx).of_corner_size((3, 1), 1).fill(Color(0, .5, 0)) Square(ctx).of_corner_size((1, 3), 1).stroke(Color(0, .5, 0), 0.1) Square(ctx).of_corner_size((3, 3), 1).fill(Color(0, 0, 1)).stroke(Color(0), 0.2)
def draw(ctx, width, height, frame_no, frame_count): setup(ctx, width, height, background=Color(0.8)) # Create a circular clip region and draw some squares in it with Transform(ctx): Circle(ctx).of_center_radius((190, 190), 100).clip() Square(ctx).of_corner_size((100, 100), 80).fill(Color('red')) Square(ctx).of_corner_size((100, 200), 80).fill(Color('green')) Square(ctx).of_corner_size((200, 100), 80).fill(Color('blue')) Square(ctx).of_corner_size((200, 200), 80).fill(Color('black')) with Transform(ctx): Text(ctx).of("ABC", (150, 350)).font("Times").size(150).align_left().align_top().clip() circles = [(200, 380, 'orange'), (200, 450, 'cyan'), (300, 380, 'green'), (300, 450, 'purple'), (400, 380, 'yellow'), (400, 450, 'blue')] for x, y, color in circles: Circle(ctx).of_center_radius((x, y), 70).fill(Color(color))
def plot_easing_function(ctx, x, y, fn): tw = Tween(0).ease(-100, 100, fn) poly = [(i, tw[i]) for i in range(100)] ctx.save() ctx.translate(x, y) Square(ctx).of_corner_size((0, -100), 100).stroke(Color(0.5), 2) Polygon(ctx).of_points(poly).open().stroke(Color('red'), 2) ctx.restore()
def draw(ctx, width, height, frame_no, frame_count): cs = DarkColorScheme() setup(ctx, width, height, background=cs.BACKGROUND) colors = [ cs.RED, cs.GREEN, cs.BLUE, cs.WHITE, cs.GREY, cs.BLACK, cs.YELLOW, cs.CYAN, cs.MAGENTA, cs.ORANGE, ] Transform(ctx).translate(50, 50) for i, color in enumerate(colors): Square(ctx).of_corner_size((i * 50, 0), 50).fill(color.dark3) Square(ctx).of_corner_size((i * 50, 50), 50).fill(color.dark2) Square(ctx).of_corner_size((i * 50, 100), 50).fill(color.dark1) Square(ctx).of_corner_size((i * 50, 150), 50).fill(color) Square(ctx).of_corner_size((i * 50, 200), 50).fill(color.light1) Square(ctx).of_corner_size((i * 50, 250), 50).fill(color.light2) Square(ctx).of_corner_size((i * 50, 300), 50).fill(color.light3)
def draw(ctx, width, height, frame_no, frame_count): setup(ctx, width, height, background=Color(1)) cs = ArtisticColorScheme() colors = [ cs.RED, cs.BLUE, cs.GREEN, cs.YELLOW, cs.MAGENTA, cs.STEEL, cs.CREAM, cs.LIME, cs.BLACK, cs.GREY, cs.WHITE, ] Transform(ctx).translate(50, 50) for i, color in enumerate(colors): Square(ctx).of_corner_size((i * 50, 0), 50).fill(color.dark3) Square(ctx).of_corner_size((i * 50, 50), 50).fill(color.dark2) Square(ctx).of_corner_size((i * 50, 100), 50).fill(color.dark1) Square(ctx).of_corner_size((i * 50, 150), 50).fill(color) Square(ctx).of_corner_size((i * 50, 200), 50).fill(color.light1) Square(ctx).of_corner_size((i * 50, 250), 50).fill(color.light2) Square(ctx).of_corner_size((i * 50, 300), 50).fill(color.light3)
def draw(ctx, width, height, frame_no, frame_count): setup(ctx, width, height, background=Color(1)) colors = [ Color(0.5, 0, 0), # red Color(0, 0.5, 0), # green Color(0, 0, 0.5), #blue Color(0, 0.5, 0.5), # cyan Color(0.5, 0, 0.5), # magenta Color(0.5, 0.5, 0), # yellow Color(1, 1, 1), # white Color(0.5, 0.5, 0.5), # grey ] Transform(ctx).translate(50, 50) for i, color in enumerate(colors): Square(ctx).of_corner_size((i * 50, 0), 50).fill(color.dark3) Square(ctx).of_corner_size((i * 50, 50), 50).fill(color.dark2) Square(ctx).of_corner_size((i * 50, 100), 50).fill(color.dark1) Square(ctx).of_corner_size((i * 50, 150), 50).fill(color) Square(ctx).of_corner_size((i * 50, 200), 50).fill(color.light1) Square(ctx).of_corner_size((i * 50, 250), 50).fill(color.light2) Square(ctx).of_corner_size((i * 50, 300), 50).fill(color.light3)
def draw(ctx, width, height, frame_no, frame_count): setup(ctx, width, height, width=5, background=Color(0.8)) # Create a circular clip region and draw some squares in it ctx.save() Circle(ctx).of_center_radius((1.9, 1.9), 1).clip() Square(ctx).of_corner_size((1, 1), .8).fill(Color('red')) Square(ctx).of_corner_size((1, 2), .8).fill(Color('green')) Square(ctx).of_corner_size((2, 1), .8).fill(Color('blue')) Square(ctx).of_corner_size((2, 2), .8).fill(Color('black')) ctx.restore() ctx.save() Text(ctx).of("ABC", (1.5, 3.5)).font("Times", weight=FONT_WEIGHT_BOLD).size(1.5).align_left().align_top().clip() circles = [(2, 3.8, 'orange'), (2, 4.5, 'cyan'), (3, 3.8, 'green'), (3, 4.5, 'purple'), (4, 3.8, 'yellow'), (4, 4.5, 'blue')] for x, y, color in circles: Circle(ctx).of_center_radius((x, y), 0.7).fill(Color(color)) ctx.restore()
def draw(ctx, width, height, frame_no, frame_count): setup(ctx, width, height, width=10, background=Color(0.8)) gradient = LinearGradient().of_points( (0, 1), (0, 3)).with_start_end(Color(0), Color('red')).build() Square(ctx).of_corner_size((1, 1), 2).fill(gradient) gradient = LinearGradient().of_points( (3, 1), (6.2, 2.5)).with_start_end(Color(1), Color('green')).build() Rectangle(ctx).of_corner_size((4, 1), 2.2, 1.5).fill(gradient) gradient = LinearGradient().of_points( (7, 1), (9, 1)).with_start_end(Color('blue'), Color('yellow')).build() Circle(ctx).of_center_radius((8, 2), 1.5).fill(gradient) gradient = LinearGradient().of_points((0, 4), (0, 6)).with_stops( ((0, Color(0)), (0.5, Color('red')), (1.0, Color('blue')))).build() Square(ctx).of_corner_size((1, 4), 2).fill(gradient) gradient = LinearGradient().of_points((4, 4), (6, 6)).with_stops( ((0, Color(0)), (0.5, Color('red')), (0.8, Color('green')), (1.0, Color('blue')))).build() Square(ctx).of_corner_size((4, 4), 2).fill(gradient) gradient = LinearGradient().of_points((7, 4), (7, 6)).with_stops( ((0, Color(0)), (0.5, Color('red')), (0.5, Color('blue')), (1.0, Color('blue')))).build() Square(ctx).of_corner_size((7, 4), 2).fill(gradient) gradient = LinearGradient().of_points((0, 7), (0, 9)).with_stops( ((0, Color(0)), (0.5, Color('red')), (1.0, Color('blue')))).build() Square(ctx).of_corner_size((1.1, 7.1), 1.8).stroke(gradient, .2) gradient = LinearGradient().of_points((4, 7), (6, 9)).with_stops( ((0, Color(0)), (0.5, Color('red')), (0.8, Color('green')), (1.0, Color('blue')))).build() Square(ctx).of_corner_size((4.1, 7.1), 1.8).stroke(gradient, .2) gradient = LinearGradient().of_points((7, 7), (7, 9)).with_stops( ((0, Color(0)), (0.5, Color('red')), (0.5, Color('blue')), (1.0, Color('blue')))).build() Square(ctx).of_corner_size((7.1, 7.1), 1.8).stroke(gradient, .2)
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count): setup(ctx, pixel_width, pixel_height, background=Color(0.8)) red = Color('red') green = Color('green') blue = Color('blue') thickness = 2 Line(ctx).of_start_end((150, 150), (50, 50)).stroke(red, thickness) Line(ctx).of_start_end((300, 150), (200, 50)).as_ray().stroke(red, thickness) Line(ctx).of_start_end((450, 150), (350, 50)).as_line().stroke(red, thickness) Triangle(ctx).of_corners((50, 200), (150, 200), (125, 300)).stroke(green, thickness) Square(ctx).of_corner_size((200, 200), 100).stroke(green, thickness) Rectangle(ctx).of_corner_size((350, 200), 100, 75).stroke(green, thickness) Polygon(ctx).of_points([(50, 350), (250, 400), (250, 500), (50, 375)]).stroke(blue, thickness) Polygon(ctx).of_points([(300, 350), (500, 400), (500, 500), (300, 375)]).open().stroke(blue, thickness)