Пример #1
0
def prepare_data():
    surface = gz.Surface(1000, 1000)
    offset = np.array((500, 500))
    gz.square(l=1000, xy=offset, fill=(0, 0, 0)).draw(surface)

    radius, corners, stroke_width = get_extinction_symbol_params(400)
    gz.circle(r=radius, xy=offset, stroke=(1, 1, 1),
              stroke_width=stroke_width).draw(surface)
    gz.polyline(points=corners + offset,
                close_path=True,
                fill=None,
                stroke=(1, 1, 1),
                stroke_width=stroke_width).draw(surface)
    surface.write_to_png('extinction_symbol.png')

    print('STIPPLING EXTINCTION SYMBOL')
    points = stipple_image_points('extinction_symbol.png',
                                  n_points=2500,
                                  scale_factor=1,
                                  max_iterations=50)
    np.save('extinction_symbol', points)

    points = np.load('extinction_symbol.npy')
    write_tsp('extinction_symbol.tsp', points)
    run_linkern('extinction_symbol.tsp', 'extinction_symbol.cyc',
                '../../tools/linkern.exe')
    postprocess_cyc('extinction_symbol.npy',
                    'extinction_symbol.cyc',
                    'extinction_symbol_processed.npy', (width, height),
                    radius=110 / 128,
                    segment_length=5)
Пример #2
0
def make_frame(t):
    surface = gz.Surface(R, R)
    background = gz.square(l=R, xy= [R/2,R/2], fill=(1,1,1))
    background.draw(surface)
    cir = gz.circle(R/2, stroke=(1,1,1), fill=(0, 1, 0, 0.5), stroke_width=1, xy=[R/2, R/2])
    tri = gz.regular_polygon(R/2, 3, stroke=(1,1,1), fill=(1, 0, 0, 0.5), stroke_width=1, xy=[R/2, R/2], angle=2*t/DURATION*np.pi)
    sqr = gz.square(R/2, stroke=(1,1,1), fill=(0, 0, 1, 0.5), stroke_width=1, xy=[R/2, R/2], angle=-2*t/DURATION*np.pi)
    grp = gz.Group([cir, tri, sqr])
    grp.draw(surface)
    im = surface.get_npimage()
    return im
Пример #3
0
def prepare_data():
    surface = gz.Surface(width, height)
    offset = np.array((width / 2, height / 2))
    gz.square(l=width, xy=offset, fill=(0, 0, 0)).draw(surface)

    radius, corners, stroke_width = get_extinction_symbol_params(0.35 * width)
    gz.circle(r=radius, xy=offset, stroke=(1, 1, 1),
              stroke_width=stroke_width).draw(surface)
    gz.polyline(points=corners + offset,
                close_path=True,
                fill=None,
                stroke=(1, 1, 1),
                stroke_width=stroke_width).draw(surface)

    img = surface.get_npimage()[:, :, 0]
    img = gaussian_filter(img, sigma=width / 50, truncate=10)
    imsave(f'extinction_symbol_soft_{width}.png', img)
Пример #4
0
def make_frame(t):
    surface = gz.Surface(W, H)
    # hsl is hue color wheel degree, lightness percent, saturation percent
    hue = t * (100 / D) / 100
    color = colorsys.hls_to_rgb(hue, 0.5, 1)
    square = gz.square(l=W * 2, fill=color, xy=(1, 1))
    square.draw(surface)
    return surface.get_npimage()
Пример #5
0
def make_frame(t):
    surface = gz.Surface(W, H)
    # hsl is hue color wheel degree, lightness percent, saturation percent
    hue = t * (100 / D) / 100
    color = colorsys.hls_to_rgb(hue, .5, 1)
    square = gz.square(l=W * 2, fill=color, xy=(1, 1))
    square.draw(surface)
    return surface.get_npimage()
Пример #6
0
    def make_frame(self, time_decimal):
        """
        render frame
        :param time_decimal: time in seconds
        :return: 3d numpy array
        """
        time_decimal = time_decimal + self.offset
        time = time_decimal * 1000 - self.minimum
        surface = gizeh.Surface(WIDTH + PADDING * 2, HEIGHT + PADDING * 2)
        cords = get_action_at_time(self.replay, time)

        left = (.2, 0, 0)
        right = (.2, 0, 0)

        click = cords["clicks"]
        if click in [1, 5, 15]:
            left = (.9, 0, 0)
        if click in [2, 10, 15]:
            right = (.9, 0, 0)

        size_multiplier = 1.15 if click else 1
        mouse = gizeh.circle(10 * size_multiplier, xy=(cords["x pos"] + PADDING,
                                                       cords["y pos"] + PADDING),
                             fill=(1, 0, 0), stroke=(0, 1, 0), stroke_width=2)

        sqrl = gizeh.square(l=30, fill=left, xy=(surface.width - 60, surface.height - 24))
        sqrr = gizeh.square(l=30, fill=right, xy=(surface.width - 25, surface.height - 24))
        clicks = gizeh.Group([sqrl, sqrr])

        render_objects = list()
        for i in self.objects:
            if i.appear <= time:
                i.visable = True
            if i.disappear <= time:
                i.visable = False

            if i.visable:
                render_objects.extend(i.render(time))
        hit_objects = gizeh.Group(render_objects)

        hit_objects.draw(surface)
        mouse.draw(surface)
        clicks.draw(surface)
        return surface.get_npimage()
Пример #7
0
def make_station_icon(surface, settings, n, constants, text=None):
    x_pos, y_pos = constants.icon_xy
    if constants.theme.lower() == 'tokyu':
        fill = constants.line_color
        stroke = [1, 1, 1]
        stroke_width = 5
        text_fill = [1, 1, 1]
        letter_mod = -10
    else:
        fill = [1, 1, 1]
        stroke = constants.line_color
        stroke_width = 15
        text_fill = [0, 0, 0]
        letter_mod = 0

    if constants.icon_shape.lower() == 'square':
        mod = 40
        gz.square(constants.icon_size,
                  xy=[x_pos, y_pos],
                  stroke=stroke,
                  stroke_width=stroke_width,
                  fill=fill).draw(surface)
    else:
        mod = 45
        gz.circle(constants.icon_size,
                  xy=[x_pos, y_pos],
                  stroke=constants.line_color,
                  stroke_width=30,
                  fill=[1, 1, 1]).draw(surface)

    if text:
        line, num = text.split('-')
    else:
        line, num = settings[n].station_number.split('-')
    gz.text(line,
            constants.icon_text_font,
            constants.icon_line_fontsize + letter_mod,
            xy=[x_pos, y_pos - mod],
            fill=text_fill).draw(surface)
    gz.text(num,
            constants.icon_text_font,
            constants.icon_station_fontsize - letter_mod,
            xy=[x_pos, y_pos + 30],
            fill=text_fill).draw(surface)
Пример #8
0
def make_frame(t):
    surface = gz.Surface(R, R)
    background = gz.square(l=R, xy= [R/2,R/2], fill = colorsys.hls_to_rgb(1,.5,1))
    background.draw(surface)
    G = 2 ** (np.log2(total_zoom)*t/DURATION)
    T = [total_translation[0] * t/DURATION, total_translation[1] * t/DURATION]
    theta = total_rotation*t/DURATION
    group.translate([-final_state.center[0],-final_state.center[1]]).scale(G).rotate(theta).translate(
        [final_state.center[0],final_state.center[1]]).translate(T).draw(surface)
    grp2.translate([-final_state.center[0],-final_state.center[1]]).scale(G).rotate(theta).translate(
        [final_state.center[0],final_state.center[1]]).translate(T).draw(surface)
    return surface.get_npimage()
Пример #9
0
def make_frame(t):
    surface = gz.Surface(Width, Height)
    center = []
    T = round(t * widthNumber * heightNumber / Duration)

    x = (T % widthNumber) * Length + Length / 2
    y = (T // widthNumber) * Length + Length / 2

    square = gz.square(l=Length, xy=[x, y], fill=(0, 0, 0))
    square.draw(surface)

    return surface.get_npimage()
Пример #10
0
def prepare_data():
    surface = gz.Surface(2000, 2000)
    offset = np.array((1000, 1000))
    gz.square(l=2000, xy=offset, fill=(0, 0, 0)).draw(surface)

    radius, corners, stroke_width = get_extinction_symbol_params(800)
    gz.circle(r=radius, xy=offset, stroke=(1, 1, 1),
              stroke_width=stroke_width).draw(surface)
    gz.polyline(points=corners + offset,
                close_path=True,
                fill=None,
                stroke=(1, 1, 1),
                stroke_width=stroke_width).draw(surface)
    surface.write_to_png('extinction_symbol.png')

    print('STIPPLING EXTINCTION SYMBOL')
    points = stipple_image_points('extinction_symbol.png',
                                  n_points=500,
                                  scale_factor=1,
                                  max_iterations=100)
    np.save('extinction_symbol', points)
Пример #11
0
def test_random_squares():
    np.random.seed(123)
    L = 200
    surface = gz.Surface(L, L, bg_color=(1, 1, 1))
    n_squares = 1000
    angles = 2 * np.pi * np.random.rand(n_squares)
    sizes = 20 + 20 * np.random.rand(n_squares)
    positions = L * np.random.rand(n_squares, 2)
    colors = np.random.rand(n_squares, 3)

    for angle, size, position, color in zip(angles, sizes, positions, colors):
        square = gz.square(size, xy=position, angle=angle, fill=color,
                           stroke_width=size / 20)
        square.draw(surface)

    assert is_like_sample(surface, 'random_squares')
Пример #12
0
def make_frame(t):
    global b_coords, r_coords
    # Create template to work on
    surface = gizeh.Surface(W, H)

    # Generate new coordinates
    b_coords = rand_movement(b_coords)
    r_coords = rand_movement(r_coords)

    # Specify and draw circle and square
    b_circle = gizeh.circle(25, xy=b_coords, fill=(0, 0, 1))
    r_square = gizeh.square(l=50, xy=r_coords, fill=(1, 0, 0), angle=PI*t)

    b_circle.draw(surface)
    r_square.draw(surface)
    # Return a numpy array
    return surface.get_npimage()
Пример #13
0
def draw_sqr(color, x, y):
    sqr = gz.square(l=500, fill=color, xy=(x, y))

    r = int(color[0] * 255)
    g = int(color[1] * 255)
    b = int(color[2] * 255)
    string = "(" + str(r) + ", " + str(g) + ", " + str(b) + ")"
    text2 = gz.text(string,
                    fontfamily="Tahoma",
                    fontsize=24,
                    fill=(0, 0, 0),
                    xy=(x + 20, y + 20))
    text3 = gz.text(string,
                    fontfamily="Tahoma",
                    fontsize=23,
                    fill=(1, 1, 1),
                    xy=(x + 20, y + 20))

    return gz.Group([sqr, text2, text3])
Пример #14
0
def make_frame(t):
    surface = gz.Surface(R, R)
    background = gz.square(l=R, xy= [R/2,R/2], fill = (1,1,1,1))
    background.draw(surface)
    points = []
    a = A * t / DURATION
    b = B * t / DURATION
    m = M * t / DURATION
    n1 = N1 * (t + 1.0) / DURATION
    n2 = N2 * t / DURATION
    n3 = N3 * t / DURATION
    for i in range(NPOINTS):
    	theta = 2 * np.pi * i / NPOINTS
    	r = sf(A, B, M, N1, n2, n3, theta) * R/4
    	points.append((r * np.cos(theta), r * np.sin(theta)))
    line = gz.polyline(points, stroke=(0,0,0,1), stroke_width=0.4)
    line.translate([R/2,R/2]).draw(surface)
    im = surface.get_npimage()
    return im
Пример #15
0
def test_random_squares():
    np.random.seed(123)
    L = 200
    surface = gz.Surface(L, L, bg_color=(1, 1, 1))
    n_squares = 1000
    angles = 2 * np.pi * np.random.rand(n_squares)
    sizes = 20 + 20 * np.random.rand(n_squares)
    positions = L * np.random.rand(n_squares, 2)
    colors = np.random.rand(n_squares, 3)

    for angle, size, position, color in zip(angles, sizes, positions, colors):
        square = gz.square(size,
                           xy=position,
                           angle=angle,
                           fill=color,
                           stroke_width=size / 20)
        square.draw(surface)

    assert is_like_sample(surface, 'random_squares')
def half(t, side="left"):
    points = list(gz.geometry.polar_polygon(NFACES, R, NSQUARES))
    ipoint = 0 if side == "left" else NSQUARES // 2
    points = (points[ipoint:] + points[:ipoint])[::-1]

    surface = gz.Surface(W, H)
    for (r, th, d) in points:
        center = W * (0.5 + gz.polar2cart(r, th))
        angle = -(6 * np.pi * d + t * np.pi / DURATION)
        color = colorsys.hls_to_rgb((2 * d + t / DURATION) % 1, 0.5, 0.5)
        square = gz.square(l=0.17 * W,
                           xy=center,
                           angle=angle,
                           fill=color,
                           stroke_width=0.005 * W,
                           stroke=(1, 1, 1))
        square.draw(surface)
    im = surface.get_npimage()
    return (im[:, :W // 2] if side == "left" else im[:, W // 2:])
Пример #17
0
def make_frame(t):
    surface = gz.Surface(R, R)
    background = gz.square(l=R, xy= [R/2,R/2], fill = (1,1,1,1))
    background.draw(surface)
    r = R/4
    ith = -np.pi/2
    C = pytweening.easeInOutSine(t/DURATION)
    # C = t/DURATION
    for i in range(NCIRCLES):
		th = ith + (i+1)*(2*np.pi*NROTATIONS) * C
		center = gz.polar2cart(R/4,th)
		color = (1.0,1.0,1.0,1.0/255)
		if i % 3 == 0:
			color = (1.0,0,0,1.0/255)
		elif i % 3 == 1:
			color = (0,1.0,0,1.0/255)
		else:
			color = (0,0,1.0,1.0/255)
		cir = gz.circle(R/4 - (i/4), fill=color, xy=center)
		cir.translate([R/2,R/2]).draw(surface)
    im = 255*((surface.get_npimage()) % 2)
    return im
Пример #18
0
    def draw(self, filename_to_write):
        surface = gizeh.Surface(width=300, height=300)
        square = gizeh.square(l=600, fill=(1, 1, 1), xy=(0, 0))
        square.draw(surface)

        #start resizing them and stuff
        moved_to_corner = Resizing.movePointsToCorner(self.lines)
        resized = Resizing.scalePoints(moved_to_corner, 300, 10.0)
        scooted = Resizing.scootPoints(resized, 0.0)

        if len(scooted) % 2 != 0:
            scooted.pop()
        for i in range(0, len(scooted), 2):
            point_1 = scooted[i]
            point_2 = scooted[i + 1]
            points = [(int(point_1[0]), int(point_1[1])),
                      (int(point_2[0]), int(point_2[1]))]
            line_to_draw = gizeh.polyline(points,
                                          stroke_width=3,
                                          stroke=(0, 0, 0),
                                          fill=(1, 1, 1))
            line_to_draw.draw(surface)
        surface.write_to_png(f"{filename_to_write}.png")
Пример #19
0
def half(t, side="left"):
    points = list(
        gizeh.geometry.polar_polygon(
            NFACES,
            amplitude * np.sin(2 * np.pi * frequency * t + phase_shift) +
            vertical_shift, NSQUARES))
    ipoint = 0 if side == "left" else int(NSQUARES / 2)
    points = (points[ipoint:] + points[:ipoint])[::-1]

    surface = gizeh.Surface(W, H)
    for (r, th, d) in points:
        center = W * (0.5 + gizeh.polar2cart(r, th))
        angle = -(6 * np.pi * d + t * np.pi / DURATION)
        color = hsl_to_rgb((2 * d + t / DURATION) % 1, .5, .5)
        square = gizeh.square(l=0.17 * W,
                              xy=center,
                              angle=angle,
                              fill=color,
                              stroke_width=0.005 * W,
                              stroke=(1, 1, 1))
        square.draw(surface)
    im = surface.get_npimage()
    return (im[:, :int(W / 2)] if (side == "left") else im[:, int(W / 2):])
Пример #20
0
import gizeh
import numpy as np
surface = gizeh.Surface(width=400, height=400)
Pi = 3.14
circ = gizeh.circle(r=30, xy=(50, 50), fill=(0, 0, 0))
rect = gizeh.rectangle(lx=60, ly=45, xy=(100, 100), fill=(0, 1, 0))
sqr = gizeh.square(l=20, stroke=(1, 1, 1), stroke_width=1.5)
arc = gizeh.arc(r=20, a1=Pi / 4, a2=3 * Pi / 4, fill=(1, 1, 1))
text = gizeh.text("Hello world",
                  fontfamily="Impact",
                  fontsize=40,
                  fill=(1, 1, 1),
                  xy=(100, 100),
                  angle=Pi / 12)
polygon = gizeh.regular_polygon(r=40,
                                n=5,
                                angle=np.pi / 4,
                                xy=[40, 50],
                                fill=(1, 0, 1))
line = gizeh.polyline(points=[(0, 0), (20, 30), (40, 40), (0, 10)],
                      stroke_width=3,
                      stroke=(1, 0, 0),
                      fill=(0, 1, 0))
circ.draw(surface)
rect.draw(surface)
sqr.draw(surface)
arc.draw(surface)
text.draw(surface)
polygon.draw(surface)
line.draw(surface)
Пример #21
0
                    parent.children.append(c)


if __name__ == '__main__':

    np.random.seed(12)
    x1, y1, x2, y2, x3, y3 = 0.5 * np.random.randn(6) + np.array(
        [-1.5, 1.5, 1, 1, -1, -1])
    r1, r2, r3 = tangential_radii_from_centers(x1, y1, x2, y2, x3, y3)
    # r1 = 0.75*r1
    # r2 = 0.75*r2
    # r3 = 0.75*r3

    import gizeh as gz
    surface = gz.Surface(800, 800)
    gz.square(xy=(400, 400), l=800, fill=(0, 0, 0)).draw(surface)
    (xl, yl, rl), (xr, yr, rr) = apollonian_circles_(x1, y1, r1, x2, y2, r2,
                                                     x3, y3, r3)

    outer = ApollonianCircle(xr, yr, rr, [])
    inner1 = ApollonianCircle(x1, y1, r1, [])
    inner2 = ApollonianCircle(x2, y2, r2, [])
    inner3 = ApollonianCircle(x3, y3, r3, [])
    outer.neighbors = [inner1, inner2, inner3]
    inner1.neighbors = [outer, inner2, inner3]
    inner1.neighbors = [inner1, outer, inner3]
    inner1.neighbors = [inner1, inner2, outer]

    G = ApollonianGasket(outer, inner1, inner2, inner3)
    G.fill_gasket(min_radius=0.015)
    # for i in range(2):
Пример #22
0
def square(color, position):
    return gizeh.square(40, fill=color, xy=position, stroke_width=2)
Пример #23
0
"""
This generates a picture with 100 squares of random size, angle,
color and position.
"""

import gizeh as gz
import numpy as np

L = 200  # <- dimensions of the final picture
surface = gz.Surface(L, L, bg_color=(1, 1, 1))

# We generate 1000 random values of size, angle, color, position.
# 'rand' is a function that generates numbers between 0 and 1
n_squares = 1000  # number of squares
angles = 2 * np.pi * np.random.rand(
    n_squares)  # n_squares angles between 0 and 2pi
sizes = 20 + 20 * np.random.rand(n_squares)  # all sizes between 20 and 40
positions = L * np.random.rand(n_squares, 2)  # [ [x1, y1] [x2 y2] [x3 y3]]...
colors = np.random.rand(n_squares, 3)

for angle, size, position, color in zip(angles, sizes, positions, colors):
    square = gz.square(size,
                       xy=position,
                       angle=angle,
                       fill=color,
                       stroke_width=size / 20)  # stroke is black by default.
    square.draw(surface)

surface.write_to_png("random_squares.png")
Пример #24
0
"""
This generates a picture with 100 squares of random size, angle,
color and position.
"""

import gizeh as gz
import numpy as np 

L = 200 # <- dimensions of the final picture
surface = gz.Surface(L, L, bg_color=(1,1,1))

# We generate 1000 random values of size, angle, color, position.
# 'rand' is a function that generates numbers between 0 and 1
n_squares = 1000 # number of squares
angles = 2*np.pi* np.random.rand(n_squares) # n_squares angles between 0 and 2pi
sizes = 20 + 20 * np.random.rand(n_squares) # all sizes between 20 and 40
positions = L * np.random.rand(n_squares, 2) # [ [x1, y1] [x2 y2] [x3 y3]]...
colors = np.random.rand(n_squares, 3)


for angle, size, position, color in zip(angles, sizes, positions, colors):
    square = gz.square(size, xy=position, angle=angle, fill=color,
                       stroke_width=size/20) # stroke is black by default.
    square.draw(surface)

surface.write_to_png("random_squares.png")
Пример #25
0
#                         n = 3,
#                        xy= [W/2, H/2], # coordinates of the center
#                        stroke= (0,0,0), stroke_width=1) # 'red' in RGB coordinates

# triangle.draw( surface ) # draw the triangle on the surface

# square = gz.square(W/4, stroke=(0,0,0), stroke_width = 1, xy= [W/2, H/2])

# square.draw( surface )

# circle = gz.circle(W/8, stroke=(0,0,0), stroke_width = 1, xy= [W/2, H/2])
# circle.draw(surface)

tri = gz.regular_polygon(W/2, 3, stroke=(0,0,0), stroke_width=1, xy=[W/2, H/2])
cir = gz.circle(W/2, stroke=(0,0,0), stroke_width=1, xy=[W/2, H/2])
sqr = gz.square(W/2, stroke=(0,0,0), stroke_width=1, xy=[W/2, H/2])
grp = gz.Group([tri, cir, sqr])
grp.draw(surface)

# surface.get_npimage() # export as a numpy array (we will use that)
surface.write_to_png("shapes.png")

# NFACES, R, NSQUARES, DURATION = 3, 0.3,  70, 10

# def half(t, side="left"):
#     # pdb.set_trace()
#     points = gz.geometry.polar_polygon(NFACES, R, NSQUARES)
#     ipoint = 0 if side=="left" else NSQUARES/2
#     points = (points[ipoint:]+points[:ipoint])[::-1]

#     surface = gz.Surface(W,H)
Пример #26
0
	"""
	sides = 0
	weight = state.radius/R * 2.5 + 0.5
	# if itr % 2 == 0:
	# 	fill = (0,0,0)
	# else: fill = (1,1,1)
	if (shape == CIRCLE):
		SHAPES.append(gz.circle(state.radius, stroke=(0,0,0), stroke_width=0, xy=state.center, fill = fill))
		return
	elif (shape == TRIANGLE):
		sides = 3
	elif (shape == SQUARE):
		sides = 4
	SHAPES.append(gz.regular_polygon(state.radius, sides, stroke=(0,0,0), stroke_width=0, xy=state.center, fill = fill, angle=state.angle))

background = gz.square(l=R*2, xy= [R,R], fill=(1,1,1))
background.draw(surface)
state = Translation([R, R+R/4], -np.pi/2, R)
add_shape(ORDER[0], state, 0)
draw_pointer_circles(state.radius, state.center, state.angle)
for itr in range(1,len(ORDER)):
	old_shape = ORDER[itr - 1]
	new_shape = ORDER[itr]
	state.iterate(old_shape, new_shape)
	add_shape(new_shape, state, itr)
	draw_pointer_circles(state.radius, state.center, state.angle)
group = gz.Group(SHAPES) 

group2 = gz.Group(grp2)
group.draw(surface)
group2.draw(surface)