Exemplo n.º 1
0
import numpy as np
from penkit import shapes
from penkit.preview import show_layer
from penkit.textures.util import concat, rotate_texture, translate, center
from penkit.write import write_plot

x_count = 18
y_count = 12
grid_spacing = 1.7
jitter = 0.9

l = ([], [])
for i in range(x_count * y_count):
    x, y = (i % x_count), (i // x_count)
    polygon = shapes.ngon(np.random.randint(3, 7))
    polygon = rotate_texture(polygon, np.random.uniform(0, 360))
    polygon = center(polygon)
    polygon = translate(polygon, (grid_spacing * x, grid_spacing * y))
    polygon = translate(
        polygon, (jitter * np.random.uniform(), jitter * np.random.uniform()))
    l = concat([l, polygon])

write_plot([l], 'examples/polygon_confetti.svg', height=8.5, width=11.0)
Exemplo n.º 2
0
def vertical_overlapping_circles(lowerBound, upperBound, x, offset):
    l = ([], [])
    for i in range(lowerBound, upperBound):
        circle = shapes.circle((x, i + offset), 1)
        l = concat([l, circle, ([np.nan], [np.nan])])
    return l


l = ([], [])
# centers at [0,-1], [0,0], [0,1]
l = concat([l, vertical_overlapping_circles(-1, 2, 0, 0)])

horizontal = math.sqrt(3) / 2
vertical = 1 / 2
l = concat([l, vertical_overlapping_circles(-2, 2, horizontal, 0.5)])
l = concat([l, vertical_overlapping_circles(-2, 3, horizontal * 2, 0)])
l = concat([l, vertical_overlapping_circles(-2, 2, horizontal * 3, 0.5)])
l = concat([l, vertical_overlapping_circles(-1, 2, horizontal * 4, 0)])

# outer circles
l = concat([
    l,
    shapes.circle((horizontal * 2, 0), 3), ([np.nan], [np.nan]),
    shapes.circle((horizontal * 2, 0), 3.1)
])

write_plot([l],
           'examples/flower_of_life.svg',
           height=8.5,
           width=8.5,
           stroke_thickness_pct=0.0015)
Exemplo n.º 3
0
                         hex_row_zero_origin[1] - np.sqrt(3) / 2 * i]))

    # time to remove stuff
    seg_length = len(hexagon[0])
    layer_length = len(grid[0])
    num_segments = int(layer_length / seg_length)
    mask = np.repeat(np.random.uniform(size=num_segments) < 0.6, seg_length)
    grid = (grid[0][mask], grid[1][mask])

    return grid


texture = hex_grid_imperfect(80)
texture = fit_texture(texture)
texture = (0.5 * texture[0], 0.5 * texture[1])

# rotate the texture
#texture = rotate_texture(texture, 50)

# create the surface
from penkit.surfaces import make_cylinder_surface, make_noise_surface
surface = make_cylinder_surface()

# project the texture onto the surface
from penkit.projection import project_and_occlude_texture
proj = project_and_occlude_texture(texture, surface, angle=45)

write_plot([proj],
           'examples/imperfect_hex_cylinder.svg',
           height=11.0,
           width=8.5)
Exemplo n.º 4
0
    flip = False
    for i in range(1, n):
        if current - i not in visited and current - i > 0:
            target = current - i
        else:
            target = current + i
        center = ((current + target) / 2.0, 0.)
        radius = i

        if flip:
            start_angle = 0 if target < current else -np.pi
            end_angle = -np.pi if target < current else 0
        else:
            start_angle = 0 if target < current else np.pi
            end_angle = np.pi if target < current else 0

        visited.add(target)

        arc = shapes.arc(center, radius / 2.0, start_angle, end_angle)

        plot = (np.concatenate(
            (plot[0], arc[0])), np.concatenate((plot[1], arc[1])))
        current = target
        flip = not flip
    return plot


write_plot([rotate_texture(draw_recaman(100), 90)],
           'examples/recaman.svg',
           height=11.0,
           width=8.5)
Exemplo n.º 5
0
#!/usr/bin/env python3
from penkit.textures import make_lines_texture
from penkit import textures
from penkit.write import write_plot
write_plot([textures.make_grid_texture(5, 5)], 'grid.svg')

Exemplo n.º 6
0
from penkit.write import write_plot
from penkit.fractal import dragon_curve

curve = dragon_curve(12)
write_plot([curve], 'dragon_curve.svg')

Exemplo n.º 7
0
import numpy as np
from penkit import shapes
from penkit.textures.util import concat, crop
from penkit.write import write_plot

l = ([], [])

for i in range(130):
    arc = shapes.circle((0, 0), i, 300)
    arc = crop(arc, -30, -20, 70, 80)

    arc2 = shapes.circle((1.5, 2.3), i * 1.05, 300)
    arc2 = crop(arc2, -30, -20, 70, 80)
    l = concat([l, arc, ([np.nan], [np.nan]), arc2, ([np.nan], [np.nan])])

write_plot([l],
           'examples/spider_moire.svg',
           height=8.5,
           width=8.5,
           stroke_thickness_pct=0.0015)
Exemplo n.º 8
0
from penkit.write import write_plot
from penkit.fractal import dragon_curve

curve = dragon_curve(12)
write_plot([curve], 'examples/dragon_curve.svg')