예제 #1
0
def main(args, config):
    print("Reading input text from stdin:")
    text = sys.stdin.read().strip()

    width, height = parse_size(args.size)

    layout = layout_text(text, 1)

    rng = default_rng(args.seed)
    chamber = make_superchamber(rng, width, height, layout)
    particles = generate_particles(rng, chamber)

    sim = Simulation(chamber, particles)

    out_file = (
        config["output_dir"] /
        f"cloudscript_{dt.datetime.now().isoformat().replace(':', '-')}.svg")
    surface = cairo.SVGSurface(str(out_file), width, height)
    renderer = BubbleChamberRenderer(surface, max_linewidth=args.max_linewidth)

    if args.grid:
        renderer.add_grid(width, height, chamber.rows, chamber.columns)

    fps = FPSCounter()

    sim.start()
    fps.start()
    while any(p.is_dirty for p in sim.particles):
        sim.step()
        renderer.render(sim)
        fps.frame_done()

    renderer.finalize(sim)
    surface.finish()
예제 #2
0
def _pointillism(args, config):
    width, height = parse_size(args.size)
    rng = default_rng(args.seed)

    out_file = (config["output_dir"] /
                f"technique_pointillism_{dt.datetime.now().isoformat()}.svg")
    surface = cairo.SVGSurface(str(out_file), width, height)

    ctx = cairo.Context(surface)

    # Divide the canvas in squares to show off different styles:
    ROWS = 3
    COLS = len(Pattern.__members__)
    draw_grid(ctx, width, height, ROWS, COLS)
    rowheight = height // ROWS
    colwidth = width // COLS
    radius = min(rowheight, colwidth) / 2

    for rown in range(ROWS):
        starty = rown * rowheight
        endy = starty + rowheight
        cy = (starty + endy) / 2
        grad_angle = rown * (pi / 2.0 / (ROWS - 1))
        offset_x = cos(grad_angle) * radius
        offset_y = sin(grad_angle) * radius

        for coln, pat in enumerate(Pattern):
            startx = coln * colwidth
            endx = startx + colwidth
            cx = (startx + endx) / 2

            ctx.arc(cx, cy, radius, 0, tau)
            # Cut out a square to observe clipping behavior
            # Note that it is constructed in the reverse winding direction to subtract it:
            ctx.rectangle(cx + (radius / 6), cy - (radius / 6), -radius / 3,
                          radius / 3)
            ctx.clip()

            # Finally, fill the outer circle:
            ctx.arc(cx, cy, radius, 0, tau)
            grad = PointLinearGradient(
                [Color(0.0, 0.0, 0.0),
                 Color(1.0, 1.0, 1.0)], pat)
            grad.fill(
                ctx,
                rng,
                cx - 0.5 * offset_x,
                cy - 0.5 * offset_y,
                cx + offset_x,
                cy + offset_y,
            )

            ctx.reset_clip()

    surface.finish()
예제 #3
0
def _circlepacking(args, config):
    width, height = parse_size(args.size)
    rng = default_rng(args.seed)

    out_file = (config["output_dir"] /
                f"technique_circlepacking_{dt.datetime.now().isoformat()}.svg")
    surface = cairo.SVGSurface(str(out_file), width, height)

    ctx = cairo.Context(surface)
    circles = pack(rng, width, height, args.grow_rate, args.max_circles,
                   args.unbounded)
    for c in circles:
        ctx.arc(*c.pos, c.r, 0, tau)
        ctx.stroke()

    surface.finish()
예제 #4
0
def main(args, config):
    width, height = parse_size(args.size)
    rng = default_rng(args.seed)

    out_file = (config["output_dir"] /
                f"wael_{dt.datetime.now().isoformat().replace(':', '-')}.png")
    surface = cairo.ImageSurface(cairo.Format.ARGB32, width, height)
    context = cairo.Context(surface)

    circles = pack(rng, width, height, args.grow_rate, args.max_eyeballs)
    eyes = [generator.random_eye(rng, c.pos, c.r) for c in circles]
    flesh = models.Flesh(FLESH_COLOR)

    flesh.draw(context)
    for eye in eyes:
        eye.draw(context)

    surface.write_to_png(out_file)
예제 #5
0
def main(args, config):
    print("Reading input text from stdin:")
    text = sys.stdin.read().strip()

    width, height = parse_size(args.size)

    out_file = (
        config["output_dir"]
        / f"colorhoney_{dt.datetime.now().isoformat().replace(':', '-')}.svg"
    )
    surface = cairo.SVGSurface(str(out_file), width, height)

    if args.tokki:
        renderer_cls = ColorTokkiRenderer
    else:
        renderer_cls = ColorHoneyRenderer

    renderer = renderer_cls(surface)
    renderer.render(text)
    surface.finish()
예제 #6
0
def main(args, config):
    width, height = parse_size(args.size)
    rng = default_rng(args.seed)

    out_file = (
        config["output_dir"] /
        f"selene_{dt.datetime.now().isoformat().replace(':', '-')}.svg")
    surface = cairo.SVGSurface(str(out_file), width, height)
    ctx = cairo.Context(surface)

    n_circles = rng.integers(4, 12)
    circles = circlepacking.pack(rng,
                                 width,
                                 height,
                                 width / 10.0,
                                 n_circles,
                                 unbounded=True)

    for circle in circles:
        randomly_fill_circle(ctx, rng, circle.pos[0], circle.pos[1], circle.r)

    background.draw_background(ctx, width, height)
    surface.finish()