Пример #1
0
    def draw_me(self, canvas, bar_rates, ceil_height, base_line):
        """描きます"""

        color_list = []
        for i in range(0, self.phases):
            theta = i * self.unit_arc
            color = calc_color(theta, bar_rates)
            upper_bound = max(color[0], color[1], color[2])
            # print(f"upper_bound={upper_bound}")
            color = calc_step2(color, upper_bound, 255, ceil_height, base_line)
            color_list.append(color)

        # 色相環
        for i in range(0, self.phases):
            theta = i * self.unit_arc
            color = color_list[i]
            # print(f"[{i}] color={color}")

            # 円弧
            # 楕円、描画する画像を指定、座標(x,y),xyの半径、角度,色、線の太さ(-1は塗りつぶし)
            cv2.ellipse(canvas,
                        self.origin,
                        self.area_size,
                        -90,
                        theta,
                        theta + self.unit_arc,
                        color,
                        thickness=int(GRID_INTERVAL_H * 3 / 2))
Пример #2
0
def make_circle(canvas, seq, bar_rates, tone_name):
    """色相環一周分の画像を出力"""

    outer_circle = OuterCircle()

    for phase in range(0, PHASE_COUNTS):
        theta = 360/PHASE_COUNTS*phase
        canvas = make_canvas()
        bar_box, circle_rail, outer_circle = make_scene1(
            bar_rates, outer_circle)
        outer_circle.phase = phase

        # 円周上の点の位置
        circle_rail.theta = theta

        # バーR
        bar_box.step1_rect[0].left_top = (
            bar_box.red_left, circle_rail.red_p[1])
        bar_box.step1_rect[0].right_bottom = (
            bar_box.red_left+bar_box.one_width, bar_box.top3)
        # バーG
        bar_box.step1_rect[1].left_top = (
            bar_box.green_left, circle_rail.green_p[1])
        bar_box.step1_rect[1].right_bottom = (
            bar_box.green_left+bar_box.one_width, bar_box.top3)
        # バーB
        bar_box.step1_rect[2].left_top = (
            bar_box.blue_left, circle_rail.blue_p[1])
        bar_box.step1_rect[2].right_bottom = (
            bar_box.blue_left+bar_box.one_width, bar_box.top3)
#        print(
#            f"red={bar_box.step1_rect[0].debug_string} \
# green={bar_box.step1_rect[1].debug_string} \
# blue={bar_box.step1_rect[2].debug_string}")

        bar_box.delta_3bars_height = calc_step2(
            bar_box.create_step1_3bars_height(),
            bar_box.height2
        )

        # 外環状
        theta = outer_circle.phase * outer_circle.unit_arc
        outer_color = convert_3heights_to_3bytes(
            bar_box.create_rank23d_3bars_height(), bar_box.height)
        outer_circle.color_list.append(outer_color)
        #

        draw_grid(canvas)  # 罫線
        bar_box.draw_outline(canvas)  # 箱の輪郭
        canvas = draw_canvas(canvas, bar_box, circle_rail,
                             outer_circle)
        draw_tone_name(canvas, bar_box, tone_name)  # トーン名

        # 書出し
        canvas = cv2.cvtColor(canvas, cv2.COLOR_BGR2RGB)  # BGRをRGBにする
        cv2.imwrite(f"./@share/out-cstep4-{seq}.png", canvas)
        seq += 1

    return seq, canvas
Пример #3
0
def update_scene1_with_rotate(phase, bar_box, circle_rail, outer_circle,
                              inscribed_triangle):
    """回転が伴うモデルを更新"""
    theta = 360 / PHASE_COUNTS * phase

    outer_circle.phase = phase

    # 円周上の点の位置
    circle_rail.theta = theta

    # バーR
    bar_box.step1_rect[0].left_top = (bar_box.red_left, circle_rail.red_p[1])
    bar_box.step1_rect[0].right_bottom = (bar_box.red_left + bar_box.one_width,
                                          bar_box.top3)
    # バーG
    bar_box.step1_rect[1].left_top = (bar_box.green_left,
                                      circle_rail.green_p[1])
    bar_box.step1_rect[1].right_bottom = (bar_box.green_left +
                                          bar_box.one_width, bar_box.top3)
    # バーB
    bar_box.step1_rect[2].left_top = (bar_box.blue_left, circle_rail.blue_p[1])
    bar_box.step1_rect[2].right_bottom = (bar_box.blue_left +
                                          bar_box.one_width, bar_box.top3)
    #        print(
    #            f"red={bar_box.step1_rect[0].debug_string} \
    # green={bar_box.step1_rect[1].debug_string} \
    # blue={bar_box.step1_rect[2].debug_string}")

    bar_box.delta_3bars_height = calc_step2(
        bar_box.create_step1_3bars_height(), bar_box.height2)

    # 外環状
    theta = outer_circle.phase * outer_circle.unit_arc
    rank23d_3bars_height = bar_box.create_rank23d_3bars_height()
    outer_color = convert_3heights_to_3bytes(rank23d_3bars_height,
                                             bar_box.height)
    outer_circle.color_list.append(outer_color)
    #

    inscribed_triangle.update(bar_box.top2, bar_box.top3, circle_rail.center,
                              theta, rank23d_3bars_height)
    gravity = inscribed_triangle.triangular_center_of_gravity()
    diff_xy = (gravity[0] - circle_rail.center[0],
               gravity[1] - circle_rail.center[1])
    inscribed_triangle.correct_horizon(diff_xy)
Пример #4
0
def make_circle(canvas, seq, bar_rates, tone_name):
    """色相環一周分の画像を出力"""

    inner_circle = OuterCircle()
    outer_circle = OuterCircle()

    for phase in range(0, PHASE_COUNTS):
        theta = 360 / PHASE_COUNTS * phase
        canvas = make_canvas()
        bar_box, circle_rail, inner_circle, outer_circle = make_scene1(
            bar_rates, inner_circle, outer_circle)
        inner_circle.phase = phase
        outer_circle.phase = phase

        # 円周上の点の位置
        circle_rail.theta = theta

        # バーR
        bar_box.step1_rect[0].left_top = (bar_box.red_left,
                                          circle_rail.red_p[1])
        bar_box.step1_rect[0].right_bottom = (bar_box.red_left +
                                              bar_box.one_width, bar_box.top3)
        # バーG
        bar_box.step1_rect[1].left_top = (bar_box.green_left,
                                          circle_rail.green_p[1])
        bar_box.step1_rect[1].right_bottom = (bar_box.green_left +
                                              bar_box.one_width, bar_box.top3)
        # バーB
        bar_box.step1_rect[2].left_top = (bar_box.blue_left,
                                          circle_rail.blue_p[1])
        bar_box.step1_rect[2].right_bottom = (bar_box.blue_left +
                                              bar_box.one_width, bar_box.top3)
        #        print(
        #            f"red={bar_box.step1_rect[0].debug_string} \
        # green={bar_box.step1_rect[1].debug_string} \
        # blue={bar_box.step1_rect[2].debug_string}")

        longest_step1_bar_height = bar_box.get_max_step1_height()
        zoom = longest_step1_bar_height / bar_box.height2
        step1_3bars_height = bar_box.create_step1_3bars_height()
        red_add_px = int(step1_3bars_height[0] / zoom) - \
            step1_3bars_height[0]
        green_add_px = int(step1_3bars_height[1] / zoom) - \
            step1_3bars_height[1]
        blue_add_px = int(step1_3bars_height[2] / zoom) - \
            step1_3bars_height[2]
        bar_box.addition_3bars_height = (red_add_px, green_add_px, blue_add_px)

        # 内環状
        theta = inner_circle.phase * inner_circle.unit_arc
        color_rate = calc_step1(theta)
        inner_step1_color_rate = append_rank3_to_color_rate(
            color_rate, bar_box.rates)
        inner_color = convert_3rates_to_3bytes(inner_step1_color_rate)
        inner_circle.color_list.append(inner_color)

        # 外環状
        theta = outer_circle.phase * outer_circle.unit_arc
        color_rate = calc_step1(theta)
        outer_step1_color_rate = append_rank3_to_color_rate(
            color_rate, bar_box.rates)
        outer_color = convert_3rates_to_3bytes(outer_step1_color_rate)
        outer_color = calc_step2(outer_color, bar_box.get_max_rank23_height(),
                                 bar_box.height, bar_box.height1,
                                 bar_box.height3)
        outer_circle.color_list.append(outer_color)
        #

        draw_grid(canvas)  # 罫線
        bar_box.draw_outline(canvas)  # 箱の輪郭
        canvas = draw_canvas(canvas, bar_box, circle_rail, inner_circle,
                             outer_circle)
        bar_box.draw_rank2_box(canvas)
        draw_tone_name(canvas, bar_box, tone_name)

        # 書出し
        canvas = cv2.cvtColor(canvas, cv2.COLOR_BGR2RGB)  # BGRをRGBにする
        cv2.imwrite(f"./@share/out-cstep4-{seq}.png", canvas)
        seq += 1

    return seq, canvas
Пример #5
0
def make_circle(canvas, seq, bar_rates, tone_name):
    """色相環一周分の画像を出力"""

    inner_circle = OuterCircle()
    outer_circle = OuterCircle()

    for phase in range(0, PHASE_COUNTS):
        theta = 360 / PHASE_COUNTS * phase
        canvas = make_canvas()
        bar_box, circle_rail, inner_circle, outer_circle = make_scene1(
            bar_rates, inner_circle, outer_circle)
        inner_circle.phase = phase
        outer_circle.phase = phase

        # 円周上の点の位置
        circle_rail.theta = theta

        # バーR
        bar_box.step1_red_bar_p1 = (bar_box.red_left, circle_rail.red_p[1])
        bar_box.step1_red_bar_p2 = (bar_box.red_left + bar_box.one_width,
                                    bar_box.top3)
        # バーG
        bar_box.step1_green_bar_p1 = (bar_box.green_left,
                                      circle_rail.green_p[1])
        bar_box.step1_green_bar_p2 = (bar_box.green_left + bar_box.one_width,
                                      bar_box.top3)
        # バーB
        bar_box.step1_blue_bar_p1 = (bar_box.blue_left, circle_rail.blue_p[1])
        bar_box.step1_blue_bar_p2 = (bar_box.blue_left + bar_box.one_width,
                                     bar_box.top3)

        upper_bound_px = bar_box.get_step1_upper_bound_y()
        longest_rank2_bar_height = bar_box.top3 - upper_bound_px
        # print(
        #    f"longest_rank2_bar_height={longest_rank2_bar_height} bar_box.height={bar_box.height}")
        zoom = longest_rank2_bar_height / bar_box.height2
        # print(f"zoom={zoom}")
        red_add = int(bar_box.red_step1_height / zoom) - \
            bar_box.red_step1_height
        green_add = int(bar_box.green_step1_height / zoom) - \
            bar_box.green_step1_height
        blue_add = int(bar_box.blue_step1_height / zoom) - \
            bar_box.blue_step1_height
        #print(f"red_add={red_add} green_add={green_add} blue_add={blue_add}")

        bar_box.red_addition = red_add
        bar_box.green_addition = green_add
        bar_box.blue_addition = blue_add

        # バーR追加部分
        bar_box.addition_red_bar_p1 = (bar_box.red_left,
                                       bar_box.step1_red_bar_p1[1] -
                                       bar_box.red_addition)  # yは逆さ
        bar_box.addition_red_bar_p2 = (bar_box.red_left + bar_box.one_width,
                                       circle_rail.red_p[1])
        # バーG追加部分
        bar_box.addition_green_bar_p1 = (bar_box.green_left,
                                         bar_box.step1_green_bar_p1[1] -
                                         bar_box.green_addition)
        bar_box.addition_green_bar_p2 = (bar_box.green_left +
                                         bar_box.one_width,
                                         circle_rail.green_p[1])
        # バーB追加部分
        bar_box.addition_blue_bar_p1 = (bar_box.blue_left,
                                        bar_box.step1_blue_bar_p1[1] -
                                        bar_box.blue_addition)
        bar_box.addition_blue_bar_p2 = (bar_box.blue_left + bar_box.one_width,
                                        circle_rail.blue_p[1])

        ceil_height = bar_box.ceil_height_rgb_value
        base_line = bar_box.base_line_rgb_value

        # 内環状
        theta = inner_circle.phase * inner_circle.unit_arc
        color = calc_step1(theta)
        inner_color = append_rank3_to_color(color, bar_box.rates)
        inner_circle.color_list.append(inner_color)

        # 外環状
        theta = outer_circle.phase * outer_circle.unit_arc
        color = calc_step1(theta)
        outer_color = append_rank3_to_color(color, bar_box.rates)
        outer_upper_bound = outer_circle.get_upper_bound_value(bar_box.rates)
        outer_color = calc_step2(outer_color, outer_upper_bound, 255,
                                 ceil_height, base_line)
        outer_circle.color_list.append(outer_color)
        #

        draw_grid(canvas)  # 罫線
        bar_box.draw_outline(canvas)  # 箱の輪郭
        canvas = draw_canvas(canvas, bar_box, circle_rail, inner_circle,
                             outer_circle)
        bar_box.draw_rank2_box(canvas)
        draw_tone_name(canvas, bar_box, tone_name)

        # 書出し
        canvas = cv2.cvtColor(canvas, cv2.COLOR_BGR2RGB)  # BGRをRGBにする
        cv2.imwrite(f"./@share/out-cstep4-{seq}.png", canvas)
        seq += 1

    return seq, canvas
Пример #6
0
def draw_canvas(canvas, bar_box, circle_rail, brush_point, bar_window, outer_circle):
    """アニメの1コマを作成します
    """

    circle_rail.draw_me(canvas)  # 円レール

    circle_rail.draw_red_p(canvas)  # 円周上の点R
    circle_rail.draw_green_p(canvas)  # 円周上の点G
    circle_rail.draw_blue_p(canvas)  # 円周上の点B

    # 円に内接する線。三角形
    cv2.line(canvas, circle_rail.red_p,
             circle_rail.green_p, BLACK, thickness=2)
    cv2.line(canvas, circle_rail.green_p,
             circle_rail.blue_p, BLACK, thickness=2)
    cv2.line(canvas, circle_rail.blue_p,
             circle_rail.red_p, BLACK, thickness=2)

    # 水平線R
    # 線、描画する画像を指定、座標1点目、2点目、色、線の太さ
    cv2.line(canvas, circle_rail.red_p,
             (bar_window.red_bar_p1[0], circle_rail.red_p[1]), RED, thickness=2)

    # 水平線G
    cv2.line(canvas, circle_rail.green_p,
             (bar_window.green_bar_p1[0], circle_rail.green_p[1]), GREEN, thickness=2)

    # 水平線B
    cv2.line(canvas, circle_rail.blue_p,
             (bar_window.blue_bar_p1[0], circle_rail.blue_p[1]), BLUE, thickness=2)

    bar_window.draw_bars(canvas)
    upper_bound_px = bar_window.get_upper_bound_y()
    bar_window.draw_horizontal_line(canvas, upper_bound_px-4)  # 線を引くのは少し上

    # 斜線
    cv2.line(canvas, (bar_window.blue_bar_p2[0], upper_bound_px-4),  # 線を引くのは少し上
             (bar_box.left, bar_box.top2), BLACK, thickness=2)
    cv2.line(canvas, (bar_window.blue_bar_p2[0], bar_box.top3),
             (bar_box.left, bar_box.top3), BLACK, thickness=2)

    longest_bar_height = bar_window.right_bottom[1] - upper_bound_px
    # print(
    #    f"longest_bar_height={longest_bar_height} bar_box.height={bar_box.height}")
    zoom = longest_bar_height / bar_window.height
    # print(f"zoom={zoom}")
    red_add = int(bar_window.red_height / zoom) - bar_window.red_height
    green_add = int(bar_window.green_height / zoom) - bar_window.green_height
    blue_add = int(bar_window.blue_height / zoom) - bar_window.blue_height
    #print(f"red_add={red_add} green_add={green_add} blue_add={blue_add}")

    bar_box.red_addition = red_add
    bar_box.green_addition = green_add
    bar_box.blue_addition = blue_add
    bar_box.draw_bars(canvas)  # RGBバー

    # 色値
    color = bar_box.create_color()

    bar_box.draw_rgb_number(canvas, color)  # R値テキスト
    bar_box.draw_bar_rate(canvas)  # バー率テキスト

    ceil_height = bar_box.ceil_height_rgb_value
    base_line = bar_box.base_line_rgb_value
    upper_bound_value = max(color[0], color[1], color[2])
    modified_color = calc_step2(
        color, upper_bound_value, 255, ceil_height, base_line)
    brush_point.draw_me(canvas, modified_color)  # 塗り円
    outer_circle.draw_me(canvas, bar_box.rates, ceil_height, base_line)  # 外環状

    # cv2.imshow('Title', canvas)
    # cv2.imwrite('form.jpg',canvas)
    # cv2.waitKey(0)
    # cv2.destroyAllWindows()
    return canvas