示例#1
0
def draw_xor_circles_othello(drawing):

    paper_centre = Point(102.5, 148)
    n = 20
    size = 6
    all_paths = []
    layer1 = drawing.add_layer("1-cyan")
    layer1_paths = []
    for r in range(0, n+1):
        x = paper_centre.x + (r - n/2)*size
        # print(x)
        for c in range(0, n+1):
            shapes = []
            y = paper_centre.y + (c - n/2)*size
            shapes.append(drawing.make_circle(Point(x,y), size/2))
            if(random.random() > 0.5):
                sf = ShapeFiller(shapes)
                paths = sf.get_paths(drawing.pen_type.pen_width * 0.4)
                layer1_paths.extend(paths)
                square = drawing.make_square(Point(x - size/2, y - size/2), size)
                shapes.append(square)
                
            sf = ShapeFiller(shapes)
            paths = sf.get_paths(drawing.pen_type.pen_width * 0.4)
            all_paths.extend(paths)
    
    drawing.add_polylines(all_paths)
    drawing.add_polylines(layer1_paths, container=layer1, stroke=svgwrite.rgb(0, 255, 255, '%'))
示例#2
0
def draw_diamonds(d):

    paper_centre = Point(102.5, 148)
    paper_size = Point(192, 270)
    size = 10
    lines = []
    nr = 8
    nc = 12
    for r in range(0, nr):
        for c in range(0, nc):
            d_centre = paper_centre + Point(r - (nr-1)/2, c - (nc-1)/2) * size * 2
            lines.append(make_diamond(d_centre, size))
            
            line1 = make_diamond(d_centre, size/3)
            line2 = make_diamond(d_centre, size*2/3)
            sf = ShapeFiller([line1, line2])
            fill = sf.get_paths(d.pen_type.pen_width * 0.4)
            lines.extend(fill)
                
    for r in range(0, nr-1):
        for c in range(0, nc-1):
            d_centre = paper_centre + Point(r - (nr-2)/2, c - (nc-2)/2) * size * 2
            
            line1 = make_diamond(d_centre, size/2)
            line2 = make_diamond(d_centre, size*3/4)
            sf = ShapeFiller([line1, line2])
            fill = sf.get_paths(d.pen_type.pen_width * 0.4)
            lines.extend(fill)
                
            line3 = make_diamond(d_centre, size/4)
            sf = ShapeFiller([line3])
            fill = sf.get_paths(d.pen_type.pen_width * 0.4)
            lines.extend(fill)
                
    d.add_polylines(lines)
示例#3
0
def draw_riley_movement_in_squares(drawing):    

    paper_centre = Point(102.5, 148)
    size = 90
    sq_size = 14
    n = 12
    top_y = paper_centre[1] - (n/2) * sq_size
    left_x = paper_centre[0] - (n/2) * sq_size
    right_x = paper_centre[0] + (n/2) * sq_size
    for r in range(0, n):
        y = top_y + sq_size * r
        x = left_x
        print(x,y)
        ix_x = 0
        a = 0
        x_width = sq_size
        while x < right_x:
            c = math.cos(a)
            x_factor = 0.06 + 0.94 * abs(math.pow(abs(c), 2.5))
            new_x = x + sq_size * x_factor
            if new_x > right_x:
                new_x = right_x
            print(x, y, new_x, x_factor)
            if (ix_x + r) % 2 == 1:
                shape = [(x, y), (new_x, y), (new_x, y + sq_size), (x, y + sq_size)]
                sf = ShapeFiller([shape])
                paths = sf.get_paths(drawing.pen_type.pen_width * 0.4)
                drawing.add_polylines(paths)
            x = new_x
            ix_x += 1
            a += math.pi / 29.6
示例#4
0
def draw_big_a(d):

    paper_centre = Point(102.5, 148)
    fontsize = 96 * 8 * 0.5
    family = "Arial"
    text = "ﷺ"
    ext = d.text_bound(text, fontsize=fontsize, family=family)
    text_place = Point(paper_centre.x - ext.width / 2,
                       paper_centre.y + ext.height / 2)
    letter_paths = d.make_text(text,
                               text_place,
                               fontsize=fontsize,
                               family=family)
    sf = ShapeFiller(letter_paths)
    paths = []
    for path in sf.get_paths(0.4 * d.pen_type.pen_width,
                             angle=math.pi / 2):  # math.pi/2):
        paths.append(path)

    d.add_polylines(paths,
                    container=d.add_layer("1"),
                    stroke=svgwrite.rgb(30, 100, 30, '%'))

    closed_letter_paths = []
    for letter_path in letter_paths:
        x = [_ for _ in letter_path]
        x.append(x[0])
        closed_letter_paths.append(x)

    d.add_polylines(closed_letter_paths, container=d.add_layer("0"))
示例#5
0
def test_shape_filler(d):
    '''
    yd = -45
    points = [
        [(50, 150+yd), (50, 160+yd), (60, 160+yd), (60, 150+yd)],
        [(53, 153+yd), (53, 157+yd), (57, 157+yd), (57, 153+yd)],
        ]
        '''

    centre = (50, 50)
    star = []
    n = 5
    for i in range(0, 2 * n):
        a = 2 * math.pi * i / (2 * n)
        r = 7 + 11 * (i % 2)
        c = d.get_circle_point(centre, r, a)
        star.append(c)
    points = [star]
    # points = []
    points.append(d.make_circle(centre, 7, int(5 * 2 * math.pi * 2)))
    points.append(d.make_circle(centre, 9, int(9 * 2 * math.pi * 2)))
    points.append(d.make_circle(centre, 11, int(11 * 2 * math.pi * 2)))
    points.append(d.make_circle(centre, 18, int(18 * 2 * math.pi * 2)))
    points.append(d.make_circle(centre, 20, int(20 * 2 * math.pi * 2)))

    angle = 0.45 * math.pi + (105 / 360) * 2 * math.pi
    # angle=0
    sf = ShapeFiller(points)
    for path in sf.get_paths(10 * d.pen_type.pen_width / 5, angle=angle):
        # for path in sf.get_paths(3):
        d.add_polyline(path)
示例#6
0
def text_in_circle(d, centre, text, radius, fontsize, family, fill, container=None):

    container = d.default_container(container)
    angle = - math.pi / 2 * 0.9
    lines = []
    for letter in text:
        ext = d.text_bound_letter(letter, fontsize, family)
        w = ext[0]
        angle_diff = w / radius * 1.2
        ((w, h), text_paths) = d.make_spiral_letter(letter, fontsize, centre, radius, angle=angle, family=family)
        angle += angle_diff
        if len(text_paths) > 0:
            if fill:
                sf = ShapeFiller(text_paths)
                filled_text_paths = sf.get_paths(d.pen_type.pen_width / 5)
                lines.extend(filled_text_paths)
            else:
                lines.extend(text_paths)
        
    d.add_polylines(lines, container=container)
    
    if False: # fill:
        d.add_dot(centre, radius + 7.3, r_start = radius  + 5.8, stroke=svgwrite.rgb(0, 0, 0, '%'), container=container)
        d.add_dot(centre, radius - 1.8, r_start = radius  - 3.3, stroke=svgwrite.rgb(0, 0, 0, '%'), container=container)    
    else:
        d.add_circle(centre, radius + 7.3)
        d.add_circle(centre, radius + 5.8)
        d.add_circle(centre, radius - 1.9)
        d.add_circle(centre, radius - 3.3)
    
    lines = []
    lines.append(d.make_circle(centre, radius + 8.3))
    lines.append(d.make_circle(centre, radius - 4.3))
    return lines
示例#7
0
def test_text_and_shape(d):

    letter_paths = d.make_text("TEST", (20, 80), 96, family="Arial")
    circle = d.make_circle((50, 70), 15)
    letter_paths.append(circle)
    sf = ShapeFiller(letter_paths)
    for path in sf.get_paths(4 * d.pen_type.pen_width / 5, angle=math.pi / 2):
        d.add_polyline(path)
示例#8
0
def createtiles_tri(drawing, tile_size):

    delta = drawing.pen_type.pen_width * 1.1 # 1.5 # 0.75
    diag = math.sqrt(2)
    shape = [Point(delta,delta), Point(delta,tile_size-delta), Point(tile_size-delta,delta)]
    sf = ShapeFiller([shape])
    tile = sf.get_paths(row_width = drawing.pen_type.pen_width * 0.4)
    
    return [tile]
示例#9
0
def complex_fill(d):

    points = []
    centre = (150, 50)
    sq = d.make_rect(centre, 20, 20)
    points = d.make_rotated_polyline(sq, centre, 13)
    sf = ShapeFiller(points)
    for path in sf.get_paths(4 * d.pen_type.pen_width / 5, angle=math.pi / 2):
        d.add_polyline(path)
示例#10
0
def fill_test(d):

    points = []
    for j in range(0, 8):
        layer = d.add_layer(f'{j+1}-layer')
        for i in range(2, 11):
            tl = (20 + 20 * j, 20 + 20 * i)
            sq = d.make_rect(tl, 18, 18)
            sf = ShapeFiller([sq])
            for path in sf.get_paths(i * d.pen_type.pen_width / 10):
                d.add_polyline(path, container=layer)
示例#11
0
def star_gen2(drawing):

    centre = Point(102.5, 148)
    size = 80
    inner = 0  # 15
    ratio = 0.7
    size = (size - inner) * ratio + inner
    points = [(size, 0), (size, 0.5), (size, 1), (size, 1.5)]
    n = 5
    for i in range(0, n):
        size = (size - inner) * ratio + inner
        ix = 0
        while (ix < len(points)):
            a = points[ix]
            b = points[ix + 1] if ix + 1 < len(points) else (points[0], 2)
            new_angle = (a[1] + b[1]) / 2
            new_elem = (size, new_angle)
            points.insert(ix + 1, new_elem)
            ix += 2
    print(points)
    shape = []
    sizes = []
    for point in points:
        r = point[0]
        if r not in sizes:
            sizes.append(r)
        radians = math.pi * point[1]
        c = math.cos(radians)
        s = math.sin(radians)
        shape.append(Point(centre.x + r * c, centre.y + r * s))
    shapes = [shape]
    sizes = sorted(sizes)[::-1]
    shapes.extend([drawing.make_circle(centre, size) for size in sizes[4:]])
    # shapes.extend([drawing.make_circle(centre, size) for size in sizes[0:3]])
    # shapes.extend([drawing.make_circle(centre, size-1) for size in sizes[0:3]])
    # shapes.extend([drawing.make_circle(centre, size) for size in sizes])
    # shapes.extend([drawing.make_circle(centre, size-1) for size in sizes])

    r_inner = sizes[-1] - 1
    while r_inner > 0:
        shapes.append(drawing.make_circle(centre, r_inner))
        r_inner -= 1.1

    sf = ShapeFiller(shapes)
    paths = sf.get_paths(drawing.pen_type.pen_width *
                         0.4)  # , angle=math.pi/2)

    drawing.add_polylines(paths,
                          container=drawing.add_layer("1"),
                          stroke=svgwrite.rgb(100, 100, 0, '%'))
    # drawing.add_polylines([drawing.make_circle(centre, size) for size in sizes[0:3]])

    layer2 = drawing.add_layer("2-dots")

    for point in points:
        r = point[0]
        radians = math.pi * point[1]
        c = math.cos(radians)
        s = math.sin(radians)
        dot_r = r / 20
        centre_r = r + dot_r + 2
        circle_centre = Point(centre.x + centre_r * c, centre.y + centre_r * s)
        if r > 15:
            drawing.add_dot(circle_centre, dot_r)
            r2 = dot_r  # points[0][0] / 20 * ratio * ratio * ratio
            if r < points[0][0]:
                centre2_r = points[0][0] + r2 + 2
                circle_centre2 = Point(centre.x + centre2_r * c,
                                       centre.y + centre2_r * s)
                drawing.add_dot(circle_centre2, r2, container=layer2)
            if r < points[0][0] * ratio:
                centre2_r = points[0][0] * ratio + r2 + 2
                circle_centre2 = Point(centre.x + centre2_r * c,
                                       centre.y + centre2_r * s)
                drawing.add_dot(circle_centre2, r2, container=layer2)
            if r < points[0][0] * ratio * ratio:
                centre2_r = points[0][0] * ratio * ratio + r2 + 2
                circle_centre2 = Point(centre.x + centre2_r * c,
                                       centre.y + centre2_r * s)
                drawing.add_dot(circle_centre2, r2, container=layer2)
示例#12
0
def draw_3d_shade(d):

    cameraToWorld = numpy.identity(4)
    cameraToWorld[3][2] = 10
    t = Transform3D(cameraToWorld,
                    canvasWidth=2,
                    canvasHeight=2,
                    imageWidth=100,
                    imageHeight=100)

    h = 1
    s = 0.3
    base_points = [(s, s, s, h), (s, -s, s, h), (-s, -s, s, h), (-s, s, s, h),
                   (s, s, -s, h), (s, -s, -s, h), (-s, -s, -s, h),
                   (-s, s, -s, h)]

    a = math.pi / 3

    family = "Wingdings"
    letters = [x for x in "`¬!£$%&*()_+={:<>?@}~[;,./'#]"]
    letters = [x for x in "^_`abcdefghi"]

    family = 'Arial'
    letters = [x for x in "happy anniversary b xxx  "]

    ix_letter = 0

    for c in range(2, 7):
        for r in range(1, 5):
            scale = 0.75
            dx = 0 + 25 * r
            dy = 0 + 25 * c
            a += math.pi / 30

            letter = letters[ix_letter]
            ix_letter += 1
            if ix_letter == len(letters):
                ix_letter = 0
            # letter = "a"

            all_faces = []

            world_points = [p for p in base_points]
            zc = 0
            xc = 0
            yc = 0
            world_points = [(p[0] + xc, p[1] + yc, p[2] + zc, p[3])
                            for p in world_points]
            world_points = Transform3D.rotZ(world_points, a)
            world_points = Transform3D.rotX(world_points, a)
            world_points = [(p[0], p[1], p[2] + 8, p[3]) for p in world_points]

            faces3d = cube_open_faces(world_points)

            # should order by distance, nearest first
            # need to progressively clip this based upon the overall face projection
            # pass in the face drawing as a method?

            for face3d in faces3d:
                proj_face_points = t.project(face3d)
                # StandardDrawing.log(proj_face_points)
                if Transform3D.isForward(proj_face_points):
                    if letter != " ":
                        proj_face_lines = get_face_draw_text(d,
                                                             t,
                                                             face3d,
                                                             letter,
                                                             family=family)
                        proj_face_lines = [[
                            (x[0] * scale + dx, x[1] * scale + dy)
                            for x in proj_face_line
                        ] for proj_face_line in proj_face_lines]
                        sf = ShapeFiller(proj_face_lines)
                        paths = sf.get_paths(d.pen_type.pen_width / 5 * 2)
                        d.add_polylines(paths)

                    proj_face_lines = get_face_draw_edge(t, face3d)
                    proj_face_lines = [[(x[0] * scale + dx, x[1] * scale + dy)
                                        for x in proj_face_line]
                                       for proj_face_line in proj_face_lines]
                    d.add_polylines(proj_face_lines)
示例#13
0
def draw_false_prophets(d):

    # A4
    top_left = (0, 0)
    x_size = 210
    y_size = 297
    projection_angle=math.pi*0.2
    p = perlin.PerlinNoise(scale=400, octaves=2)
    polylines = d.make_surface(top_left, x_size, int(y_size / math.cos(projection_angle)), p.calc2d, projection_angle=projection_angle)

    # clip to margin around edge of paper
    topleft = (20, 20)
    shapes = [d.make_rect(topleft, x_size - 2 * topleft[0], y_size - 2 * topleft[1])]
    sf = ShapeFiller(shapes)
    polylines = sf.clip(polylines, inverse=True)
    
    # medallion
    medallion_centre = (int(x_size/2), int(y_size/2))
    shapes = [d.make_circle(medallion_centre, 29, x_scale = 0.7), d.make_circle(medallion_centre, 27, x_scale = 0.7)]
    sf = ShapeFiller(shapes)
    polylines = sf.clip(polylines, union=True)
    new_lines = sf.get_paths(d.pen_type.pen_width / 5)
    for line in new_lines:
        polylines.append(line)
    
    image_path = d.make_image_spiral_single('burroughs.jpg', medallion_centre, 25, x_scale = 0.7)
    polylines.append(image_path)

    family='CNC Vector'
    # family = 'HersheyScript1smooth'
    family = 'Arial'
    family = 'Caslon Antique'
    header_pos = (int(x_size/2), 40)
    fontsize = 36
    text = "False Prophets Of The New Millenium."
    ext = d.text_bound(text, fontsize, family)
    position = (header_pos[0] - ext.width/2, header_pos[1])
    text_paths = d.make_text(text, position, fontsize=fontsize, family=family)
    rect_width = 0.5
    rect1 = d.make_rect((position[0] - 2, position[1] + ext.y_bearing - 2), ext.width + 4, ext.height + 4)
    rect2 = d.make_rect((position[0] - (2+rect_width), position[1] + ext.y_bearing - (2+rect_width)), ext.width + (4+2*rect_width), ext.height + (4+2*rect_width))
    sf = ShapeFiller([rect1, rect2])
    polylines = sf.clip(polylines, union=True)
    rect_paths = sf.get_paths(d.pen_type.pen_width / 5)
    for p in rect_paths:
        polylines.append(p)
    sf = ShapeFiller(text_paths)
    filled_text_paths = sf.get_paths(d.pen_type.pen_width / 5)
    for p in filled_text_paths:
        polylines.append(p)
    
    for text_path in text_paths:
        polylines.append(text_path)

    # legend

    family='CNC Vector'
    # family = 'HersheyScript1smooth'
    family = 'Caslon Antique'
    fontsize = 24
    text = "WAKEFIELD"
    ext = d.text_bound(text, fontsize, family)
    
    position = (medallion_centre[0] - ext.width/2, medallion_centre[1]+30+4+ext.height)
    text_paths = d.make_text(text, position, fontsize=fontsize, family=family)
    sf = ShapeFiller(text_paths)
    filled_text_paths = sf.get_paths(d.pen_type.pen_width / 5)
    
    rect_width = 0.5
    rect1 = d.make_rect((position[0] - 2, position[1] + ext.y_bearing - 2), ext.width + 4, ext.height + 4)
    rect2 = d.make_rect((position[0] - (2+rect_width), position[1] + ext.y_bearing - (2+rect_width)), ext.width + (4+2*rect_width), ext.height + (4+2*rect_width))
    sf = ShapeFiller([rect1, rect2])
    polylines = sf.clip(polylines, union=True)
    rect_paths = sf.get_paths(d.pen_type.pen_width / 5)
    for p in rect_paths:
        polylines.append(p)
    for text_path in filled_text_paths:
        polylines.append(text_path)

    polylines2 = []
    family = 'Aquifer'
    family = 'Caslon Antique'
    fontsize = 48

    row_ext = d.text_bound("Op", fontsize, family)
    
    header_pos = (int(x_size/2), 80)
    text = "False Prophets Of"
    ext = d.text_bound(text, fontsize, family)
    position = (header_pos[0] - ext.width/2, header_pos[1])
    text_paths = d.make_text(text, position, fontsize=fontsize, family=family)
    sf = ShapeFiller(text_paths)
    filled_text_paths = sf.get_paths(d.pen_type.pen_width / 5)
    for p in filled_text_paths:
        polylines2.append(p)
        
    header_pos = (header_pos[0], header_pos[1] + row_ext.height + 2)
    text = "The New Millenium"
    ext = d.text_bound(text, fontsize, family)
    position = (header_pos[0] - ext.width/2, header_pos[1])
    text_paths = d.make_text(text, position, fontsize=fontsize, family=family)
    sf = ShapeFiller(text_paths)
    filled_text_paths = sf.get_paths(d.pen_type.pen_width / 5)
    for p in filled_text_paths:
        polylines2.append(p)

    d.add_polylines(polylines)