コード例 #1
0
ファイル: blokus.py プロジェクト: fogleman/Carolina
def create_piece(piece, mirror):
    bit_diameter = 0.125
    corner_radius = 0.1875
    groove_depth = 0.0625
    cells = [cell(x, y) for x, y in piece]
    mp = cascaded_union(cells).buffer(-corner_radius).buffer(corner_radius)
    g = GCode()
    for p in cells:
        g += GCode.from_geometry(p, G0Z, -groove_depth)
    g += GCode.from_geometry(mp.buffer(bit_diameter / 2), G0Z, -0.4, bit_diameter + 0.2, 3.5)
    if mirror:
        g = g.scale(-1, 1)
    g = g.origin()
    return g
コード例 #2
0
ファイル: letters.py プロジェクト: fogleman/Carolina
def load_letter(letter):
    if letter.isdigit():
        letter = 'NUM' + letter
    wkt = getattr(foam, letter)
    polygon = loads(wkt)
    g = GCode.from_geometry(polygon, 0.2, -0.1875)
    g = g.scale(6, 6).move(3, 4, 0.5, 0.5)
    return g
コード例 #3
0
ファイル: marker.py プロジェクト: fogleman/Carolina
def load_marker(z):
    sx, sy = W / 600, H / 800
    s = min(sx, sy)
    polygon = loads(WKT)
    polygon = scale(polygon, s, s)
    polygon = polygon.buffer(0.125)
    g = GCode.from_geometry(polygon, G0Z, z)
    g = g.move(3, 4, 0.5, 0.5)
    return g
コード例 #4
0
ファイル: supports.py プロジェクト: fogleman/Carolina
def create_supports():
    n = 18
    a = 116.56505
    p = create_support(1, 0.125, a)
    g = GCode.from_geometry(p, G0Z, -0.1)
    g = g.origin()
    g = pack_gcodes([g] * n, 6, 8, 0.125)[0]
    g = g.depth(G0Z, -0.2) + g.depth(G0Z, -0.4) + g.depth(G0Z, -0.6)
    g = HEADER + g + FOOTER
    g.save('supports.nc')
    im = g.render(0, 0, 6, 8, 96)
    im.write_to_png('supports.png')
コード例 #5
0
ファイル: supports.py プロジェクト: fogleman/Carolina
def create_mounts():
    a = 116.56505
    p = create_mount(5, 3.5, 1, 0.125, a)
    g = GCode.from_geometry(p, G0Z, -0.1)
    g1 = g.move(3, 0.25, 0.5, 0)
    g2 = g.origin().rotate(180).move(3, 5.5, 0.5, 1)
    g = g1 + g2
    g = g.depth(G0Z, -0.2) + g.depth(G0Z, -0.4) + g.depth(G0Z, -0.6)
    g = HEADER + g + FOOTER
    g.save('mounts.nc')
    im = g.render(0, 0, 6, 8, 96)
    im.write_to_png('mounts.png')
コード例 #6
0
ファイル: sophia.py プロジェクト: fogleman/Carolina
def create_s():
    c1 = create_circle(0, 1.03, 1, 20, 270-15)
    c2 = create_circle(0, -1.03, 1, 200, 450-15)
    s = LineString(c1 + list(reversed(c2)))
    s = s.buffer(0.4)
    g = GCode.from_geometry(s, 0, 0)
    g = g.scale_to_fit(6, 8)
    g = g.move(3, 4, 0.5, 0.5)
    g1 = g.depth(0.2, -0.3)
    g2 = g.depth(0.2, -0.6)
    g = HEADER + g1 + g2 + FOOTER
    g.save('sophia.nc')
    im = g.render(0, 0, 6, 8, 96)
    im.write_to_png('sophia.png')
コード例 #7
0
ファイル: hemi.py プロジェクト: fogleman/Carolina
def main():
    tw, th = 6, 8
    w, h = 24-2, 24-2
    p = 0
    shapes = load_shapes()
    shapes.append(circle(R))
    shapes.append(circle(R * 1.05))
    mp = MultiLineString(shapes)
    mp = fit_shape(mp, w, h, p)
    g = GCode.from_geometry(mp, G0Z, G1Z)
    im = g.render(0, 0, w, h, 96)
    im.write_to_png('hemi.png')
    for i in range(4):
        for j in range(3):
            print i, j
            tile = create_tile(i, j, tw, th)
            tmp = intersection(mp, tile)
            g = GCode.from_geometry(tmp, G0Z, G1Z)
            g = g.translate(-i * tw, -j * th)
            g = HEADER + g + FOOTER
            im = g.render(0, 0, tw, th, 96)
            im.write_to_png('hemi-tiles/%d.%d.png' % (j, i))
            g.save('hemi-tiles/%d.%d.nc' % (j, i))
コード例 #8
0
ファイル: blokus.py プロジェクト: fogleman/Carolina
def main():
    bit = 0.125
    r = 0.21875
    d = 0.09375
    steps = 16
    cells = [
        cell(0, 0),
        cell(1, 0),
        cell(1, 1),
        cell(2, 1),
        cell(3, 1),
    ]
    mp = cascaded_union(cells).buffer(-bit).buffer(bit)
    g = GCode()
    for p in cells:
        g += GCode.from_geometry(p, G0Z, -d)
    # for p in cells:
    #     g += GCode.from_geometry(p, G0Z, -bit)
    for step in range(steps):
        p = step / (steps - 1.0)
        a = radians(p * 90)
        x = sin(a) * r
        b = x + bit / 2 - r
        z = r - (r * r - x * x) ** 0.5
        print '%.3f, %.3f, %.3f, %.3f' % (p, x, b, z)
        g += GCode.from_geometry(mp.buffer(b), G0Z, -z)
    # g += GCode.from_geometry(mp.buffer(bit / 2), G0Z, -0.4)
    # g += GCode.from_geometry(mp.buffer(bit / 2), G0Z, -0.7)
    # g += GCode.from_geometry(mp.buffer(bit / 2), G0Z, -0.6, bit + 0.1, 3)
    g += GCode.from_geometry(mp.buffer(bit / 2), G0Z, -0.4, bit + 0.2, 3.5)
    g = g.scale(-1, 1)
    g = g.origin().translate(0, 0.5)
    g = HEADER + g + FOOTER
    p = 0#0.5
    im = g.render(-p, -p, 6 + p, 6 + p, 96*4)
    im.write_to_png('blokus.png')
    g.save('blokus.nc')
コード例 #9
0
ファイル: tile.py プロジェクト: fogleman/Carolina
def main():
    counties = load_polygons(COUNTY_SHAPEFILE)
    state = load_polygons(STATE_SHAPEFILE)
    for y in range(4):
        for x in range(14):
            tile = create_tile(x, y, 6, 8)
            county_shapes = intersection(counties, tile)
            state_shapes = intersection(state, tile, -0.25)
            if not county_shapes and not state_shapes:
                continue
            print x, y, len(county_shapes), len(state_shapes)
            g = GCode()
            for shape in county_shapes:
                g += GCode.from_geometry(shape, G0Z, G1Z_COUNTY)
            for shape in state_shapes:
                g += GCode.from_geometry(shape, G0Z, G1Z_STATE1)
            for shape in state_shapes:
                g += GCode.from_geometry(shape, G0Z, G1Z_STATE2)
            g = g.translate(-tile.bounds[0], -tile.bounds[1])
            g = HEADER + g + FOOTER
            g.save('tiles/%02d.%02d.nc' % (y, x))
            p = 0.1
            surface = g.render(0 - p, 0 - p, 6 + p, 8 + p, 96)
            surface.write_to_png('tiles/%02d.%02d.png' % (y, x))
コード例 #10
0
ファイル: generate.py プロジェクト: fogleman/Carolina
def generate_county(shape, name, text):
    result = []
    polygons = get_polygons(shape, SCALE)
    max_polygon = max(polygons, key=attrgetter('area'))
    for i, polygon in enumerate(polygons):
        g = GCode.from_geometry(polygon, G0Z, G1Z_BEVEL)
        if text and polygon == max_polygon:
            x, y = polygon.centroid.coords[0]
            dx, dy = TEXT_OFFSETS.get(name, (0, 0))
            scale = TEXT_SIZES.get(name, TEXT_SIZE)
            angle = TEXT_ANGLES.get(name, 0)
            g += generate_text(name, x + dx, y + dy, scale, angle)
        g = g.origin()
        g.name = ('%s %d' % (name, i)) if i else name
        result.append(g)
    return result
コード例 #11
0
ファイル: megan.py プロジェクト: fogleman/Carolina
def main2():
    bit = 0.0625
    s = 1.82748538
    for letter in 'MEGAN':
        p = load_letter(letter)
        p = scale(p, s, s)
        p = p.buffer(bit / 2)
        g = GCode.from_geometry(p, G0Z, -bit)
        g = g.origin()
        depths = [-bit, -bit*2, -bit*3, -bit*4]
        gs = [g.depth(G0Z, d) for d in depths]
        g = reduce(operator.add, gs)
        g = HEADER + g + FOOTER
        im = g.render(0, 0, 6, 8, 96)
        im.write_to_png('megan-%s.png' % letter)
        g.save('megan-%s.nc' % letter)
コード例 #12
0
ファイル: megan.py プロジェクト: fogleman/Carolina
def main():
    bit = 0.25
    mp = load_letters('MEGAN')
    mp = mp.buffer(-bit / 2)
    mps = []
    while not mp.is_empty:
        mps.append(mp)
        mp = mp.buffer(-bit / 2)
    g = GCode()
    for mp in mps:
        g += GCode.from_geometry(mp, G0Z, -0.21875 * 1.0)
    g = g.rotate(90).origin().translate(2, 0)
    g = HEADER + g + FOOTER
    im = g.render(0, 0, 6, 8, 96)
    im.write_to_png('megan.png')
    g.save('megan.nc')
コード例 #13
0
ファイル: generate.py プロジェクト: fogleman/Carolina
def best_scale(width, height):
    result = None
    shapes = load_county_shapes('37')
    for county in COUNTIES:
        shape = shapes[county.name]
        polygons = get_polygons(shape, 1)
        for polygon in polygons:
            sizes = []
            g = GCode.from_geometry(polygon, 0, 0)
            for angle in range(0, 180, 5):
                w, h = g.rotate(angle).size
                size = min(width / w, height / h)
                sizes.append((size, angle))
            size = max(sizes)
            print county.name, size
            if result is None or size < result:
                result = size
    print result
    return result
コード例 #14
0
ファイル: usa.py プロジェクト: fogleman/Carolina
def main():
    # 8x3
    i, j = 5, 1
    tw, th = 6, 8
    w, h = 48-2, 24-2
    p = 0
    shapes = load_shapes()
    mp = MultiPolygon(shapes)
    mp = fit_shape(mp, w, h, p)
    for i in range(7):
        for j in range(3):
            print i, j
            tile = create_tile(i, j, tw, th)
            tmp = intersection(mp, tile)
            g = GCode.from_geometry(tmp, G0Z, G1Z)
            g = g.translate(-i * tw, -j * th)
            g = HEADER + g + FOOTER
            im = g.render(0, 0, tw, th, 96)
            im.write_to_png('usa-tiles/%d.%d.png' % (j, i))
            g.save('usa-tiles/%d.%d.nc' % (j, i))