コード例 #1
0
ファイル: oep.py プロジェクト: haimesh/Python_Gizeh_Animation
def animation4(t):

    W = H = 480
    WSQ = W/4 
    a = np.pi/8 
    points = [(0,0),(1,0),(1-np.cos(a)**2,np.sin(2*a)/2),(0,0)]
    surface = gz.Surface(W,H)
    for k, (c1,c2) in enumerate([[(.7,0.05,0.05),(1,0.5,0.5)],
                                [(0.05,0.05,.7),(0.5,0.5,1)]]):

        grad = gz.ColorGradient("linear",xy1=(0,0), xy2 = (1,0),
                               stops_colors= [(0,c1),(1,c2)])
        r = min(np.pi/2,max(0,np.pi*(t-DURATION/3)/DURATION))
        triangle = gz.polyline(points,xy=(-0.5,0.5), fill=grad,
                        angle=r, stroke=(1,1,1), stroke_width=.02)
        square = gz.Group([triangle.rotate(i*np.pi/2)
                              for i in range(4)])
        squares = (gz.Group([square.translate((2*i+j+k,j))
                            for i in range(-3,4)
                            for j in range(-3,4)])
                   .scale(WSQ)
                   .translate((W/2-WSQ*t/DURATION,H/2)))

        squares.draw(surface)

    return surface.get_npimage()
コード例 #2
0
ファイル: testfile.py プロジェクト: JoepStorm/NEAT_Foundation
    def make_frame(t):
        speed = t * -20
        surface = gz.Surface(w, h, bg_color=(1, 1, 1))

        x0 = (coords[0] + 1) * scale        # change coords with neat
        x1 = (coords[1] + 1) * scale + speed  # change coords with neat and remove +speed
        height_support = h / 2 + beamheight * 50

        support0 = support.translate(xy=[x0, height_support])
        group = gz.Group((support0,))
        group.draw(surface)

        support1 = support.translate(xy=[x1, height_support])
        group = gz.Group((support1,))
        group.draw(surface)

        group = gz.Group((beam,))
        group.draw(surface)


        # Get the moments
        momentenfunction(beamwidth)
        # Draw text
        text1 = gz.text(str(round(momenten[0])), fontfamily="Impact", fontsize=14, fill=(0, 0, 1), xy=[x0, 30])
        text2 = gz.text(str(round(momenten[1])), fontfamily="Impact", fontsize=14, fill=(0, 0, 1), xy=[(x0 + x1) / 2, 80])
        text3 = gz.text(str(round(momenten[2])), fontfamily="Impact", fontsize=14, fill=(0, 0, 1), xy=[x1, 30])

        group = gz.Group((text1, text2, text3))
        group.draw(surface)

        return surface.get_npimage()
コード例 #3
0
ファイル: movie.py プロジェクト: felix0901/NEAT
    def make_frame(t):
        inputs = sim.get_scaled_state()
        if hasattr(net, 'activate'):
            action = net.activate_cpu(inputs)
            #action = net.activate(inputs)
            #action = net.my_activate(inputs)
        else:
            action = net.advance(inputs, sim.time_step, sim.time_step)

        sim.step(force_function(action))

        surface = gz.Surface(w, h, bg_color=(1, 1, 1))

        # Convert position to display units
        visX = scale * sim.x

        # Draw cart.
        group = gz.Group((cart, )).translate((visX, 0))
        group.draw(surface)

        # Draw pole.
        group = gz.Group((pole, )).translate(
            (visX, 0)).rotate(sim.theta, center=(150 + visX, 80))
        group.draw(surface)

        return surface.get_npimage()
コード例 #4
0
def make_frame(t):
    """Draw text elements in each frame"""
    surface = gz.Surface(W, H, bg_color=(0,0,0))
    for i, line in enumerate(text):
        job, name = line
        ypos = LINE_HEIGHT * i - int(t * SCROLLSPEED) + BOTTOM_START
        
        txt = gz.text(job, "Amiri", TEXTSIZE, fontweight='bold', \
                      h_align='right', fill=(1,1,1))
        left = gz.Group([txt]).translate((LEFTCOL, ypos))
        left.draw(surface)
        txt = gz.text(name, "Amiri", TEXTSIZE, \
                      fontweight='normal',h_align='left', fill=(1,1,1))
        right = gz.Group([txt]).translate((RIGHTCOL, ypos))
        right.draw(surface)
    return surface.get_npimage()
コード例 #5
0
def main_func(r, g, b):
    colors = generate_shade(r, g, b)
    original_color = generate_color_master()
    items = []

    bg = colors[0]
    mg = colors[1]
    fg = colors[2]

    items.append(draw_sqr(bg[0], 250, 250))
    items.append(draw_sqr(bg[1], 750, 250))
    items.append(draw_sqr(bg[2], 750 + 500, 250))
    items.append(draw_sqr(bg[3], 750 + 1000, 250))
    items.append(draw_sqr(bg[4], 750 + 1500, 250))
    items.append(draw_sqr(bg[5], 750 + 2000, 250))
    items.append(draw_sqr(original_color[0], 750 + 2500, 250))

    items.append(draw_sqr(mg[0], 250, 250 + 500))
    items.append(draw_sqr(mg[1], 750, 250 + 500))
    items.append(draw_sqr(mg[2], 750 + 500, 250 + 500))
    items.append(draw_sqr(mg[3], 750 + 1000, 250 + 500))
    items.append(draw_sqr(mg[4], 750 + 1500, 250 + 500))
    items.append(draw_sqr(mg[5], 750 + 2000, 250 + 500))
    items.append(draw_sqr(original_color[1], 750 + 2500, 250 + 500))

    items.append(draw_sqr(fg[0], 250, 250 + 1000))
    items.append(draw_sqr(fg[1], 750, 250 + 1000))
    items.append(draw_sqr(fg[2], 750 + 500, 250 + 1000))
    items.append(draw_sqr(fg[3], 750 + 1000, 250 + 1000))
    items.append(draw_sqr(fg[4], 750 + 1500, 250 + 1000))
    items.append(draw_sqr(fg[5], 750 + 2000, 250 + 1000))
    items.append(draw_sqr(original_color[2], 750 + 2500, 250 + 1000))

    return gz.Group(items)
コード例 #6
0
def make_frame(t):
    surface = gz.Surface(W, H, bg_color=(1, 1, 1))
    for i, letter in enumerate("GIZEH"):
        angle = max(0, min(1, 2 * t / D - 1.0 * i / 5)) * 2 * np.pi
        txt = gz.text(letter, "Amiri", 3 * r / 2, fontweight='bold')
        group = (gz.Group([polygon, txt]).rotate(angle).translate(
            (W * (i + 1) / 6, H / 2)))
        group.draw(surface)
    return surface.get_npimage()
コード例 #7
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()
コード例 #8
0
    def make_frame(t):
        inputs = sim.get_scaled_state()
        action = net.serial_activate(inputs)
        sim.step(force_function(action))

        surface = gz.Surface(w, h, bg_color=(1, 1, 1))

        # Convert position to display units
        visX = scale * sim.x

        # Draw cart.
        group = gz.Group((cart, )).translate((visX, 0))
        group.draw(surface)

        # Draw pole.
        group = gz.Group((pole, )).translate(
            (visX, 0)).rotate(sim.theta, center=(150 + visX, 80))
        group.draw(surface)

        return surface.get_npimage()
コード例 #9
0
def convert_quickdraw_strokes_to_gizeh_group(strokes,
                                             color=[0, 0, 0],
                                             stroke_width=5):
    lines_list = []
    for stroke in strokes:
        x, y = stroke
        points = list(zip(x, y))
        line = gz.polyline(points=points,
                           stroke=color,
                           stroke_width=stroke_width)
        lines_list.append(line)
    return gz.Group(lines_list)
コード例 #10
0
def make_yinyang(size=200, r=80, filename="yin_yang.png"):
    surface = gz.Surface(size, size, bg_color=(0, .3, .6))
    yin_yang = gz.Group([
        gz.arc(r, pi / 2, 3 * pi / 2, fill=(1, 1, 1)),
        gz.arc(r, -pi / 2, pi / 2, fill=(0, 0, 0)),
        gz.arc(r / 2, -pi / 2, pi / 2, fill=(1, 1, 1), xy=[0, -r / 2]),
        gz.arc(r / 2, pi / 2, 3 * pi / 2, fill=(0, 0, 0), xy=[0, r / 2]),
        gz.circle(r / 8, xy=[0, +r / 2], fill=(1, 1, 1)),
        gz.circle(r / 8, xy=[0, -r / 2], fill=(0, 0, 0))
    ])
    yin_yang.translate([size / 2, size / 2]).draw(surface)
    surface.write_to_png(filename)
    return 0
コード例 #11
0
def update_gizeh_image():
    star1 = gz.star(radius=70,
                    ratio=.4,
                    fill=(1, 1, 1),
                    angle=-np.pi / 2,
                    stroke_width=2,
                    stroke=(1, 0, 0))
    star2 = gz.star(radius=55, ratio=.4, fill=(1, 0, 0), angle=-np.pi / 2)
    # Gizeh coords are right-down.
    stars = gz.Group([star1, star2]).translate(
        [random.randint(100, 412),
         random.randint(100, 412)])
    stars.draw(surface)
コード例 #12
0
def test_star():
    surface = gz.Surface(200, 200, bg_color=(1, 0.9, 0.6))

    star1 = gz.star(radius=70,
                    ratio=.4,
                    fill=(1, 1, 1),
                    angle=-np.pi / 2,
                    stroke_width=2,
                    stroke=(1, 0, 0))
    star2 = gz.star(radius=55, ratio=.4, fill=(1, 0, 0), angle=-np.pi / 2)
    stars = gz.Group([star1, star2]).translate([100, 100])
    stars.draw(surface)

    assert is_like_sample(surface, 'star')
コード例 #13
0
ファイル: bubble_sort.py プロジェクト: zhuyunhe/daily-note
def draw_list(list, count):
    length = len(list)
    for index in range(length):
        color = (random_color_r + list[index] * 0.2625,
                 random_color_g + list[index] * 0.123625, 0)
        circle = gizeh.circle(r=30,
                              xy=[80 * (index + 1), 100 * (count + 1)],
                              fill=color)
        text = gizeh.text(str(list[index]),
                          fontfamily="Impact",
                          fontsize=40,
                          fill=(0, 0, 0),
                          xy=(80 * (index + 1), 100 * (count + 1)))
        group = gizeh.Group([circle, text])
        group.draw(surface)
コード例 #14
0
def draw_person(surface, scale=1.0, position=[0, 0], stroke_width=6):
    body_parts = {'face': [0, 0], 't-shirt': [0, 250], 'pants': [0, 480]}
    gz_body_parts = []
    for name, pos in body_parts.items():
        strokes = get_drawing(name, random.randint(1, 1000))
        strokes_gz = convert_quickdraw_strokes_to_gizeh_group(
            strokes, stroke_width=stroke_width / scale)
        strokes_gz = strokes_gz.translate(pos)
        gz_body_parts.append(strokes_gz)
    scale *= np.mean([1200, 900]) / 750
    pos[0] = position[0] * 1200 - (scale * (255 / 2))
    pos[1] = position[1] * 900 - (scale * (750 / 2))
    gz_body_parts = gz.Group(gz_body_parts).scale(scale).translate(xy=pos)
    gz_body_parts.draw(surface)
    surface.write_to_png(
        '/home/pi/Documents/reconnaissance_objets/detections/detection.png')
コード例 #15
0
def test_yin_yang():
    L = 200  # <- dimensions of the final picture
    surface = gz.Surface(L, L, bg_color=(0, .3, .6))  # blue background
    r = 70  # radius of the whole yin yang

    yin_yang = gz.Group([
        gz.arc(r, np.pi / 2, 3 * np.pi / 2, fill=(1, 1, 1)),  # white half
        gz.arc(r, -np.pi / 2, np.pi / 2, fill=(0, 0, 0)),  # black half
        gz.arc(r / 2, -np.pi / 2, np.pi / 2, fill=(1, 1, 1), xy=[0, -r / 2]),
        gz.arc(r / 2, np.pi / 2, 3 * np.pi / 2, fill=(0, 0, 0), xy=[0, r / 2]),
        gz.circle(r / 8, xy=[0, +r / 2], fill=(1, 1, 1)),  # white dot
        gz.circle(r / 8, xy=[0, -r / 2], fill=(0, 0, 0))
    ])  # black dot

    yin_yang.translate([L / 2, L / 2]).draw(surface)

    assert is_like_sample(surface, 'yin_yang')
コード例 #16
0
 def draw_person(self, dataset, scale=1.0, position=[0, 0], stroke_width=6):
     body_parts = {
         'face': [0, 0],
         't-shirt': [0, 250],
         'pants': [0, 480]
     }  # dict of parts + translation
     gz_body_parts = []
     for name, pos in body_parts.items():
         strokes = dataset.get_drawing(name, random.randint(1, 1000))
         strokes_gz = self._convert_quickdraw_strokes_to_gizeh_group(
             strokes, stroke_width=stroke_width / scale)
         strokes_gz = strokes_gz.translate(pos)
         gz_body_parts.append(strokes_gz)
     scale *= np.mean([self._width, self._height]) / 750
     pos[0] = position[0] * self._width - (scale * (255 / 2))
     pos[1] = position[1] * self._height - (scale * (750 / 2))
     gz_body_parts = gz.Group(gz_body_parts).scale(scale).translate(xy=pos)
     gz_body_parts.draw(self._surface)
コード例 #17
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])
コード例 #18
0
def make_frame(t):
    surface = gz.Surface(s, s, bg_color=black)
    progress = t / dur

    circles = []
    prevRadius = baseRadius
    for i in range(numOfCircles):
        r = baseRadius if i == 0 else prevRadius + ratio
        prevRadius = r
        modRadius = r - ratio * 2 * progress
        circles.append(
            gz.circle(modRadius,
                      stroke=(255, 0, 0, .5),
                      stroke_width=10,
                      xy=center))
        circles.append(
            gz.circle(modRadius * .9,
                      stroke=(255, 0, 0, .2),
                      stroke_width=30,
                      xy=center))
    circles.reverse()
    grCircles = gz.Group(circles)
    grCircles.draw(surface)

    stageScale = animateScale(progress, pipeline)
    rand = np.random.randint(10, 30)

    redHeart = createHeart(stroke=red, stroke_width=3,
                           fill=red).rotate(-hpi,
                                            center=center).scale(stageScale,
                                                                 center=center)

    shakingHeart = createHeart(stroke=opacRed,
                               stroke_width=rand).rotate(
                                   -hpi + np.random.randint(-1, 1) / 20,
                                   center=center).scale(0.05 + stageScale,
                                                        center=center)

    redHeart.draw(surface)
    shakingHeart.draw(surface)

    return surface.get_npimage()
コード例 #19
0
def createHeart(stroke, stroke_width, fill=None):

    line = gz.polyline(points=points,
                       stroke_width=stroke_width,
                       stroke=stroke,
                       fill=red)
    arc1 = gz.arc(r=radius,
                  a1=ofstRadian,
                  a2=-ofstRadian,
                  stroke=stroke,
                  stroke_width=stroke_width,
                  xy=[A[0] - arcX, A[1] - arcY],
                  fill=red)
    arc2 = gz.arc(r=radius,
                  a1=ofstRadian,
                  a2=-ofstRadian,
                  stroke=stroke,
                  stroke_width=stroke_width,
                  xy=[C[0] - arcX, C[1] + arcY],
                  fill=red)

    return gz.Group([line, arc1, arc2])
コード例 #20
0
def test_transparent_colors():
    L = 200  # <- dimensions of the final picture
    surface = gz.Surface(L, L, bg_color=(1, 1, 1))  # <- white background
    radius = 50
    centers = [
        gz.polar2cart(40, angle)
        for angle in [0, 2 * np.pi / 3, 4 * np.pi / 3]
    ]
    colors = [
        (1, 0, 0, .4),  # <- Semi-tranparent red (R,G,B, transparency)
        (0, 1, 0, .4),  # <- Semi-tranparent green
        (0, 0, 1, .4)
    ]  # <- Semi-tranparent blue
    circles = gz.Group([
        gz.circle(radius,
                  xy=center,
                  fill=color,
                  stroke_width=3,
                  stroke=(0, 0, 0)) for center, color in zip(centers, colors)
    ])
    circles.translate([L / 2, L / 2]).draw(surface)

    assert is_like_sample(surface, 'transparent_colors')
コード例 #21
0
def drawing(boxes, objs, colors, classes):

    surface = gz.Surface(width=720, height=560)  # in pixels
    rect = gz.rectangle(lx=720, ly=560, xy=(360, 280), fill=(1, 1, 1))
    rect.draw(surface)

    LABELS = open("yolo/coco.names").read().strip().split("\n")
    colors = [
        colors[i] for i in range(len(colors)) if LABELS[classes[i]] != 'person'
    ]
    #print(len(colors))

    i = 0
    for strokes in objs:
        lines_list = []
        for stroke in strokes['image']:
            x, y = stroke

            x = tuple([(z * boxes[i][2]) // 255 for z in x])
            y = tuple([(z * boxes[i][3]) // 255 for z in y])

            x = tuple([z + boxes[i][0] for z in x])
            y = tuple([z + boxes[i][1] for z in y])

            points = list(zip(x, y))
            line = gz.polyline(points=points,
                               stroke=[0, 0, 0],
                               stroke_width=2,
                               fill=colors[i])
            lines_list.append(line)

        lines = gz.Group(lines_list)
        lines.draw(surface)
        i += 1

    #surface.write_to_png("gallery/circle.png")
    return surface
コード例 #22
0
def draw_person(surface, boxes, objs, colors, classes):

    LABELS = open("yolo/coco.names").read().strip().split("\n")
    colors = [
        colors[i] for i in range(len(colors)) if LABELS[classes[i]] == 'person'
    ]

    i = 0
    for obj in objs:
        k = 0
        for strokes in obj:
            lines_list = []
            for stroke in strokes['image']:
                x, y = stroke

                x = tuple([(z * boxes[i][2]) // 255 for z in x])
                y = tuple([(z * boxes[i][3]) // 255 for z in y])

                x = tuple([z + boxes[i][0] for z in x])
                y = tuple(
                    [z + boxes[i][1] + ((k * boxes[i][3]) // 255) for z in y])

                points = list(zip(x, y))
                #print(colors[i])
                line = gz.polyline(points=points,
                                   stroke=[0, 0, 0],
                                   stroke_width=2,
                                   fill=colors[i])
                lines_list.append(line)

            lines = gz.Group(lines_list)
            lines.draw(surface)
            k += 200
        i += 1

    surface.write_to_png("gallery/circle.png")
コード例 #23
0
# MAKE THE FIRST TRIANGLE

gradient = gz.ColorGradient('radial', [(0, (.3, .2, .8)), (1, (.4, .6, .8))],
                            xy1=(0, 0),
                            xy2=(0, r / 3),
                            xy3=(0, r))

triangle = gz.regular_polygon(r,
                              n=3,
                              fill=gradient,
                              stroke=(0, 0, 0),
                              stroke_width=3,
                              xy=(r, 0))

# BUILD THE FRACTAL RECURSIVELY

fractal = gz.Group([triangle.rotate(a) for a in angles])
for i in range(6):
    fractal = gz.Group([
        fractal.scale(.5).rotate(-np.pi).translate(
            gz.polar2cart(3 * r / 2, np.pi + a)) for a in angles
    ] + [fractal])

# PLACE AND DRAW THE FRACTAL (this will take time)

fractal.rotate(-np.pi / 2).translate((L / 2, 1.1 * L / 2)).draw(surface)

# SAVE
surface.write_to_png("logo.png")
コード例 #24
0
"""
This generates a picture of 3 semi-transparent circles of different colors
which overlap to some extent.
"""

import gizeh as gz
from numpy import pi # <- 3.14... :)

L = 200 # <- dimensions of the final picture

surface = gz.Surface(L,L, bg_color=(1,1,1)) # <- white background

radius = 50
centers = [ gz.polar2cart(40, angle) for angle in [0, 2*pi/3, 4*pi/3]]
colors = [ (1,0,0,.4), # <- Semi-tranparent red (R,G,B, transparency)
           (0,1,0,.4), # <- Semi-tranparent green
           (0,0,1,.4)] # <- Semi-tranparent blue

circles = gz.Group( [ gz.circle(radius, xy=center, fill=color,
                                stroke_width=3, stroke=(0,0,0)) # black stroke
                      for center, color in zip(centers, colors)] )

circles.translate([L/2,L/2]).draw(surface)

surface.write_to_png("transparent_colors.png")
コード例 #25
0
def eval_genomes(genomes, config):
    global generation
    generation += 1
    best_genome = None
    best_fitness = 0

    for genome_id, genome in genomes:
        genome.fitness = eval_genome(genome, config)

        if genome.fitness > best_fitness:
            best_genome = genome
            best_fitness = genome.fitness

    # visualization for best genome
    if visualize:
        net = neat.nn.FeedForwardNetwork.create(best_genome, config)
        sim = cart_pole.CartPole(**initial_values)

        while sim.t < simulation_seconds:
            inputs = sim.get_scaled_state()
            action = net.activate(inputs)

            force = cart_pole.discrete_actuator_force(action)
            sim.step(force)

            if abs(sim.x) >= sim.position_limit or abs(
                    sim.theta) >= sim.angle_limit_radians:
                break

            cart = gz.rectangle(lx=25 * scale,
                                ly=12.5 * scale,
                                xy=(150 * scale, 80 * scale),
                                fill=(0, 1, 0))

            force_direction = 1 if force > 0 else -1

            force_rect = gz.rectangle(lx=5,
                                      ly=12.5 * scale,
                                      xy=(150 * scale - force_direction *
                                          (25 * scale) / 2, 80 * scale),
                                      fill=(1, 0, 0))

            cart_group = gz.Group([cart, force_rect])

            star = gz.star(radius=10 * scale,
                           fill=(1, 1, 0),
                           xy=(150 * scale, 25 * scale),
                           angle=-math.pi / 2)

            pole = gz.rectangle(lx=2.5 * scale,
                                ly=50 * scale,
                                xy=(150 * scale, 55 * scale),
                                fill=(1, 1, 0))

            pole_group = gz.Group([pole, star])

            # convert position to display units
            visX = sim.x * 50 * scale

            # draw background
            surface = gz.Surface(w, h, bg_color=(0, 0, 0))

            # draw cart, pole and text
            group = gz.Group([
                cart_group.translate((visX, 0)),
                pole_group.translate(
                    (visX, 0)).rotate(sim.theta,
                                      center=(150 * scale + visX, 80 * scale)),
                gz.text('Gen %d Time %.2f (Fitness %.2f)' %
                        (generation, sim.t, best_genome.fitness),
                        fontfamily='NanumGothic',
                        fontsize=20,
                        fill=(1, 1, 1),
                        xy=(10, 25),
                        fontweight='bold',
                        v_align='top',
                        h_align='left'),
                gz.text('x: %.2f' % (sim.x, ),
                        fontfamily='NanumGothic',
                        fontsize=20,
                        fill=(1, 1, 1),
                        xy=(10, 50),
                        fontweight='bold',
                        v_align='top',
                        h_align='left'),
                gz.text('dx: %.2f' % (sim.dx, ),
                        fontfamily='NanumGothic',
                        fontsize=20,
                        fill=(1, 1, 1),
                        xy=(10, 75),
                        fontweight='bold',
                        v_align='top',
                        h_align='left'),
                gz.text('theta: %d' % (sim.theta * 180 / math.pi, ),
                        fontfamily='NanumGothic',
                        fontsize=20,
                        fill=(1, 1, 1),
                        xy=(10, 100),
                        fontweight='bold',
                        v_align='top',
                        h_align='left'),
                gz.text('dtheta: %d' % (sim.dtheta * 180 / math.pi, ),
                        fontfamily='NanumGothic',
                        fontsize=20,
                        fill=(1, 1, 1),
                        xy=(10, 125),
                        fontweight='bold',
                        v_align='top',
                        h_align='left'),
                gz.text('force: %d' % (force, ),
                        fontfamily='NanumGothic',
                        fontsize=20,
                        fill=(1, 0, 0),
                        xy=(10, 150),
                        fontweight='bold',
                        v_align='top',
                        h_align='left'),
            ])
            group.draw(surface)

            img = cv2.UMat(surface.get_npimage())
            img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

            cv2.imshow('result', img)
            if cv2.waitKey(1) == ord('q'):
                exit()
コード例 #26
0
"""
This generates a Yin Yang.
"""

import gizeh as gz
from math import pi

L = 200  # <- dimensions of the final picture
surface = gz.Surface(L, L, bg_color=(0, .3, .6))  # blue background
r = 70  # radius of the whole yin yang

yin_yang = gz.Group([
    gz.arc(r, pi / 2, 3 * pi / 2, fill=(1, 1, 1)),  # white half
    gz.arc(r, -pi / 2, pi / 2, fill=(0, 0, 0)),  # black half
    gz.arc(r / 2, -pi / 2, pi / 2, fill=(1, 1, 1),
           xy=[0, -r / 2]),  # white semihalf
    gz.arc(r / 2, pi / 2, 3 * pi / 2, fill=(0, 0, 0),
           xy=[0, r / 2]),  # black semihalf
    gz.circle(r / 8, xy=[0, +r / 2], fill=(1, 1, 1)),  # white dot
    gz.circle(r / 8, xy=[0, -r / 2], fill=(0, 0, 0))
])  # black dot

yin_yang.translate([L / 2, L / 2]).draw(surface)

surface.write_to_png("yin_yang.png")
コード例 #27
0
import numpy as np
import gizeh as gz
import moviepy.editor as mpy

W, H = 256, 256
R = 1.0 * W / 3
D = 4
yingyang = gz.Group([
    gz.arc(R, 0, np.pi, fill=(0, 0, 0)),
    gz.arc(R, -np.pi, 0, fill=(1, 1, 1)),
    gz.circle(R / 2, xy=(-R / 2, 0), fill=(0, 0, 0)),
    gz.circle(R / 2, xy=(R / 2, 0), fill=(1, 1, 1))
])

fractal = yingyang
for i in range(5):
    fractal = gz.Group([
        yingyang,
        fractal.rotate(np.pi).scale(0.25).translate([R / 2, 0]),
        fractal.scale(0.25).translate([-R / 2, 0]),
        gz.circle(0.26 * R, xy=(-R / 2, 0), stroke=(1, 1, 1), stroke_width=1),
        gz.circle(0.26 * R, xy=(R / 2, 0), stroke=(0, 0, 0), stroke_width=1)
    ])

# Go one level deep into the fractal
fractal = fractal.translate([(R / 2), 0]).scale(4)


def make_frame(t):
    surface = gz.Surface(W, H)
    G = 2**(2 * (t / D))  # zoom coefficient
コード例 #28
0
import gizeh as gz
from math import pi

L = 200 
surface = gz.Surface(L, L, bg_color=(0 ,.3, .6)) 
r = 80 

yin_yang = gz.Group([
     gz.arc(r, pi/2, 3*pi/2, fill = (1,1,1)), 
     gz.arc(r, -pi/2, pi/2, fill = (0,0,0)), 
     gz.arc(r/2, -pi/2, pi/2, fill = (1,1,1), xy = [0,-r/2]), 
     gz.arc(r/2, pi/2, 3*pi/2, fill = (0,0,0), xy = [0, r/2]),  
     gz.circle(r/8, xy = [0,  +r/2], fill = (1,1,1)), 
     gz.circle(r/8, xy = [0,  -r/2], fill = (0,0,0)) ]) 
    
yin_yang.translate([L/2,L/2]).draw(surface)
surface.write_to_png("yin_yang.png")
コード例 #29
0
    def make_frame(t):
        nonlocal time_steps, x_vals, x_dot_vals, theta_1_vals, theta_1_dot_vals, theta_2_vals, theta_2_dot_vals

        # Activate network and advance environment
        obs = env.get_scaled_state()
        obs = [obs[0], obs[2], obs[4]]  # Remove velocities
        action = net.forward(obs)[0]
        env.step(action)

        # Increment time step counter and store new system state
        time_steps += 1
        x, x_dot, theta_1, theta_1_dot, theta_2, theta_2_dot = env.get_state()
        x_vals.append(x)
        x_dot_vals.append(x_dot)
        theta_1_vals.append(theta_1)
        theta_1_dot_vals.append(theta_1_dot)
        theta_2_vals.append(theta_2)
        theta_2_vals.append(theta_2_dot)

        surface = gz.Surface(w, h, bg_color=(1, 1, 1))

        # Add state information
        text = gz.text(f'{time_steps} time steps',
                       fontfamily="Impact",
                       fontsize=6,
                       fill=(0, 0, 0),
                       xy=(35, 10))
        text.draw(surface)
        text = gz.text(f'x = {x:.4f}',
                       fontfamily="Impact",
                       fontsize=6,
                       fill=(0, 0, 0),
                       xy=(35, 20))
        text.draw(surface)
        text = gz.text(f'x_dot = {x_dot:.4f}',
                       fontfamily="Impact",
                       fontsize=6,
                       fill=(0, 0, 0),
                       xy=(35, 26))
        text.draw(surface)
        text = gz.text(f'theta_1 = {theta_1 * 180 / math.pi:.4f}',
                       fontfamily="Impact",
                       fontsize=6,
                       fill=(0, 0, 0),
                       xy=(35, 32))
        text.draw(surface)
        text = gz.text(f'theta_1_dot = {theta_1_dot * 180 / math.pi:.4f}',
                       fontfamily="Impact",
                       fontsize=6,
                       fill=(0, 0, 0),
                       xy=(35, 38))
        text.draw(surface)
        text = gz.text(f'theta_2 = {theta_2 * 180 / math.pi:.4f}',
                       fontfamily="Impact",
                       fontsize=6,
                       fill=(0, 0, 0),
                       xy=(35, 44))
        text.draw(surface)
        text = gz.text(f'theta_2_dot = {theta_2_dot * 180 / math.pi:.4f}',
                       fontfamily="Impact",
                       fontsize=6,
                       fill=(0, 0, 0),
                       xy=(35, 50))
        text.draw(surface)

        # Convert position to display units
        visX = x * scale

        # Draw cart
        group = gz.Group((cart, )).translate((visX, 0))
        group.draw(surface)

        # Draw long pole
        group = gz.Group((long_pole, )).translate(
            (visX, 0)).rotate(theta_1, center=(240 + visX, 80))
        group.draw(surface)

        # Draw short pole
        group = gz.Group((short_pole, )).translate(
            (visX, 0)).rotate(theta_2, center=(240 + visX, 80))
        group.draw(surface)

        return surface.get_npimage()
コード例 #30
0
        ly=12.5 * scale,
        xy=(150 * scale, 80 * scale),
        fill=(0, 1, 0)
    )

    force_direction = 1 if force > 0 else -1

    force_rect = gz.rectangle(
        lx=5,
        ly=12.5 * scale,
        xy=(150 * scale - force_direction * (25 * scale) / 2, 80 * scale),
        fill=(1, 0, 0)
    )

    cart_group = gz.Group([
        cart,
        force_rect
    ])

    star = gz.star(radius=10 * scale, fill=(1, 1, 0), xy=(150 * scale, 25 * scale), angle=-math.pi / 2)

    pole = gz.rectangle(
        lx=2.5 * scale,
        ly=50 * scale,
        xy=(150 * scale, 55 * scale),
        fill=(1, 1, 0)
    )

    pole_group = gz.Group([
        pole,
        star
    ])