예제 #1
0
    blocks = meta.samples // blocksize

    print("%d Frames at %d samples" % (blocks, blocksize))

    N = blocksize
    T = 1.0 / blocksize * 1.25
    for n, b in enumerate(audio_chunks(data, blocksize)):
        padded = "{0:03d}".format(n)
        drawing = Drawing(args.width, args.height, origin=(0, 0))
        if args.multichannel and meta.channels > 1:
            reflect = [(1, 1), (-1, 1), (1, -1), (-1, -1)]
            for i in range(meta.channels - 1):
                scene = render_frame(drawing,
                                     spectrum(b.T[i]),
                                     plotter='osci',
                                     width=args.width,
                                     height=args.height)
        else:
            if meta.channels > 1:
                b = b.T[0]
            scene = render_frame(drawing,
                                 spectrum(b),
                                 plotter='osci',
                                 width=args.width,
                                 height=args.height)
        drawing.saveSvg(
            os.path.join(args.outdir, "spectrum_" + padded + '.svg'))
        progress(n, blocks)

    stdout.write('\n')
예제 #2
0
파일: flash.py 프로젝트: sansculotte/vizzy
        path.Z()
        return path

    def render(self, drawing=None, thickness=1.0):
        drawing = drawing or Drawing(self.width, self.height, origin=(0, 0))
        drawing.append(self.render_path(thickness))
        return drawing


if __name__ == '__main__':
    try:
        nodes = int(sys.argv[1])
    except (ValueError, IndexError):
        nodes = 23

    flash = Flash()
    flashes = [flash]
    current = 0
    for _ in range(nodes):
        if flash.current_point().within_perimeter(flash.end, 10):
            flash = Flash()
            flashes.append(flash)
            current += 1
        flash.random_walk()

    drawing = Drawing(500, 500, origin=(0, 0))
    for flash in flashes:
        drawing.append(flash.render_path())
    drawing.saveSvg('/tmp/flash.svg')
예제 #3
0
class Tiling:
    def __init__(self, vertex_1: Vertex, vertex_2: Vertex, vertex_3: Vertex):
        self._vertices = {}
        self._edges = {}
        self._tiles = {}

        self._edges_to_tiles = {}

        self._tiles_to_colours = {}
        self._vertices_to_colours = {}

        self._boundary = [vertex_1, vertex_2, vertex_3]

        self._colour_values = ["#eeeeee", "#111111", "#bb9977", "#99bb77"]
        self._drawing = Drawing(2, 2, origin='center')
        self._drawing.setRenderSize(4096)

        self._populate_data()

    def _populate_data(self):
        for index, vertex in enumerate(self._boundary):
            self._vertices[vertex] = vertex

            edge = Edge(*tuple(set(self._boundary) - {vertex}))
            self._edges[edge] = edge

            self._vertices_to_colours[vertex] = index + 1

        tile = Tile(*self._boundary)
        self._tiles[tile] = tile

        self._tiles_to_colours[tile] = 0

        for edge in self._edges:
            self._edges_to_tiles[edge] = {tile}

        self._drawing.draw(
            tile, fill=self._colour_values[self._tiles_to_colours[tile]])

    def _build_new_tile(self, vertex_1: Vertex, vertex_2: Vertex) -> Vertex:
        edge = self._edges[Edge(vertex_1, vertex_2)]

        #assert len(self._edges_to_tiles[edge]) == 1
        inner_tile = tuple(self._edges_to_tiles[edge])[0]
        inner_vertex = tuple(inner_tile.vertices - {vertex_1, vertex_2})[0]

        reflected_vertex = Line.from_points(vertex_1,
                                            vertex_2).reflection(inner_vertex)

        reflected_vertex = self._add_vertex(reflected_vertex)

        self._add_edge(Edge(vertex_1, reflected_vertex))
        self._add_edge(Edge(vertex_2, reflected_vertex))

        new_tile = self._add_tile(Tile(vertex_1, reflected_vertex, vertex_2))

        self._vertices_to_colours[
            reflected_vertex] = self._vertices_to_colours[inner_vertex]
        self._tiles_to_colours[new_tile] = self._vertices_to_colours[
            inner_vertex] ^ self._tiles_to_colours[inner_tile]

        self._drawing.draw(
            new_tile,
            fill=self._colour_values[self._tiles_to_colours[new_tile]])

        return reflected_vertex

    def _add_vertex(self, vertex: Vertex) -> Vertex:
        if vertex not in self._vertices:
            self._vertices[vertex] = vertex

        return self._vertices[vertex]

    def _add_edge(self, edge: Edge):
        if edge not in self._edges:
            self._edges[edge] = edge
            self._edges_to_tiles[edge] = set()

    def _add_tile(self, tile: Tile):
        if tile not in self._tiles:
            self._tiles[tile] = tile

        tile = self._tiles[tile]

        edge_1 = self._edges[Edge(tile.vertex_2, tile.vertex_3)]
        edge_2 = self._edges[Edge(tile.vertex_3, tile.vertex_1)]
        edge_3 = self._edges[Edge(tile.vertex_1, tile.vertex_2)]

        self._edges_to_tiles[edge_1].add(tile)
        self._edges_to_tiles[edge_2].add(tile)
        self._edges_to_tiles[edge_3].add(tile)

        return tile

    def _draw(self, depth: int):
        with open('images/logo-depth-{}-data.json'.format(depth), 'w') as f:
            json.dump([path.args for path in self._drawing.elements],
                      f,
                      indent=2)
        self._drawing.saveSvg('images/logo-depth-{}.svg'.format(depth))

    def create_tiles(self, depth: int):
        if depth == 0:
            self._draw(depth)
            return

        self.create_tiles(depth=depth - 1)

        print(f"Populating depth {depth}...")
        new_boundary = [
            self._build_new_tile(self._boundary[0], self._boundary[-1])
        ]
        index = 0

        counter = 0
        num_tiles = (3 * sqrt(3) * ((2 + sqrt(3))**depth -
                                    (2 - sqrt(3))**depth)).as_int()

        while True:
            new_vertex = self._build_new_tile(new_boundary[-1],
                                              self._boundary[index])
            counter += 1
            print(f"created {counter} / {num_tiles} tiles...", end="\r")

            if new_vertex in self._boundary:
                index += 1
            elif new_vertex in new_boundary:
                break
            else:
                new_boundary.append(new_vertex)

        self._boundary = new_boundary
        self._draw(depth)

        print(f"Populated, found {len(self._tiles)} tiles")
예제 #4
0
        drawing = Drawing(args.width, args.height, origin=(0, 0))

        if len(b) < blocksize:
            b = np.lib.pad(b, ((blocksize - len(b)) // 2), 'constant')

        if args.multichannel and meta.channels > 1:
            reflect = [(1, 1), (-1, 1), (1, -1), (-1, -1)]
            for i in range(meta.channels - 1):
                drawing = render_frame(drawing,
                                       b.T[i],
                                       plotter='flash',
                                       width=args.width,
                                       height=args.height,
                                       reflect=reflect[i % meta.channels],
                                       opts={'thickness': args.thickness})
        else:
            if meta.channels > 1:
                b = b.T[0]
            drawing = render_frame(drawing,
                                   b,
                                   plotter='flash',
                                   width=args.width,
                                   height=args.height,
                                   opts={'thickness': args.thickness})

        drawing.saveSvg(
            os.path.join(args.outdir, "audioflash_" + padded + '.svg'))
        progress(n, blocks)

    stdout.write('\n')
예제 #5
0
theta1, theta2 = math.pi * 2 / p1, math.pi * 2 / p2
phiSum = math.pi * 2 / q
r1 = triangleSideForAngles(theta1 / 2, phiSum / 2, theta2 / 2)
r2 = triangleSideForAngles(theta2 / 2, phiSum / 2, theta1 / 2)

tGen1 = htiles.TileGen.makeRegular(p1, hr=r1, skip=1)
tGen2 = htiles.TileGen.makeRegular(p2, hr=r2, skip=1)

decorator1 = TileDecoratorFish(p1, p2, q)

tLayout = TileLayoutFish()
tLayout.addGenerator(tGen1, ((0, 1) * 10)[:p1], decorator1)
tLayout.addGenerator(tGen2, ((0, 1, 2) * 10)[:p2], htiles.TileDecoratorNull())
startTile = tLayout.startTile(code=0, rotateDeg=rotate)

tiles = tLayout.tilePlane(startTile, depth=depth)

d = Drawing(2, 2, origin='center')
d.draw(euclid.shapes.Circle(0, 0, 1), fill='silver')
for tile in tiles:
    d.draw(tile, layer=0)
for tile in tiles:
    d.draw(tile, layer=1)
for tile in tiles:
    d.draw(tile, layer=2)

d.setRenderSize(w=400)
d.saveSvg('Tess02.svg')

#Rest of code I already commented in Tess01
예제 #6
0
        d.draw(tile, hwidth=0.2, fill="white")
    for tile in tiles:
        d.draw(tile, drawVerts=True, hradius=0.3, hwidth=0.2, fill="black", opacity=0.6)

t1 = 4
t2 = 3
s = 3

theta1, theta2 = math.pi*2/t1, math.pi*2/t2
phiSum = math.pi*2/s

r1 = triangleSideForAngles((1/2)*(theta1, phiSum, theta2)
r2 = triangleSideForAngles((1/2)*(theta2, phiSum, theta1)

tile_generator1 = htiles.TileGen.makeRegular(t1, hr=r1, skip=1)
tile_generator2 = htiles.TileGen.makeRegular(t2, hr=r2, skip=1)

tile_layout = htiles.TileLayout()
tile_layout.addGenerator(tile_generator1, (1,)*t1)
tile_layout.addGenerator(tile_generator2, (0,)*t2)
starting_tile = tile_layout.defaultStartTile(rotateDeg=45)

tiles = tile_layout.tilePlane(starting_tile, depth=5)

d = Drawing(4, 4, origin='center')
d.draw(euclid.shapes.Circle(0,0,4), fill='blue')
drawTiles(d, tiles)

d.setRenderSize=(w=400)
d.saveSvg('images/tileTriangleSquare.svg')
theta1, theta2 = math.pi * 2 / p1, math.pi * 2 / p2
phiSum = math.pi * 2 / q
# above values of p1, p2, q will set angles of each triangle in the tessellation by dividing pi/2 over each
# specified value

r1 = triangleSideForAngles(theta1 / 2, phiSum / 2, theta2 / 2)
r2 = triangleSideForAngles(theta2 / 2, phiSum / 2, theta1 / 2)
#solves for the last side of each triange given input parameters of such

tGen1 = htiles.TileGen.makeRegular(p1, hr=r1, skip=1)
tGen2 = htiles.TileGen.makeRegular(p2, hr=r2, skip=1)
tLayout = htiles.TileLayout()
tLayout.addGenerator(tGen1, (1, ) * p1)
tLayout.addGenerator(tGen2, (0, ) * p2)
#Generates the iterations of tiles

startTile = tLayout.defaultStartTile(rotateDeg=10)
#draws tiles with 360/rotateDeg sides

tiles = tLayout.tilePlane(startTile, depth=4)
#depth specifies how many iterations tessellation will repeat

d = Drawing(2, 2, origin='center')
d.draw(euclid.shapes.Circle(0, 0, 1), fill='silver')
drawTiles(d, tiles)
#draws disk where tessllation will be contained within

d.setRenderSize(w=400)
d.saveSvg('Tess01.svg')
#will save in an image file called Tess01 in same project file
예제 #8
0
                b = np.lib.pad(b, ((blocksize-len(b)) // 2), 'constant')
            if args.multichannel and channels > 1:
                reflect = [(1,1), (-1,1), (1,-1), (-1,-1)]
                for i in range(channels - 1):
                    drawing = Drawing(args.width, args.height)
                    drawing = drawSamples(drawing, b.T[i], args.width, args.height)
            else:
                if channels > 1:
                    b = b.T[0]
                drawing = Drawing(args.width, args.height)
                drawing = drawSamples(drawing, b, args.width, args.height)
            sys.stdout.write('frame: %s' % padded)
            sys.stdout.flush()
            sys.stdout.write("\b" * 13)
            drawing.saveSvg(
                os.path.join("%s/%s.svg" % (args.outfile, padded))
            )

    else:
        if args.multichannel and channels > 1:
            reflect = [(1,1), (-1,1), (1,-1), (-1,-1)]
            for i in range(channels - 1):
                drawing = Drawing(args.width, args.height)
                drawing = drawSamples(
                    drawing, data.T[i], args.width, args.height,
                    show_progress=True
                )
        else:
            if channels > 1:
                data = data.T[0]
            drawing = Drawing(args.width, args.height)
edges = []
for i, point in enumerate(points):
    v1 = vertices[i]
    v2 = vertices[(i + 1) % p1]
    edge = Hypercycle.fromPoints(*v1,
                                 *v2,
                                 *point,
                                 segment=True,
                                 excludeMid=True)
    edges.append(edge)
decoratePoly = Polygon(edges=edges, vertices=vertices)
decorator1 = htiles.TileDecoratorPolygons(decoratePoly)
tLayout.setDecorator(decorator1, 0)

startTile = tLayout.defaultStartTile(rotateDeg=rotate)
tiles = tLayout.tilePlane(startTile, depth=6)

d = Drawing(2, 2, origin='center')
#d.draw(euclid.shapes.Circle(0, 0, 1), fill='silver')
for tile in tiles:
    d.draw(tile, hwidth=0.05, fill='green')
tiles[0].decorator = None
d.draw(Hypercycle.fromPoints(*tiles[0].vertices[0], *tiles[0].vertices[1],
                             *pointBase),
       hwidth=0.05,
       fill='black')

d.setRenderSize(w=300)
d.saveSvg('Tess03.svg')
d