Example #1
0
def update_scene1(vertical_parcent, outer_circle):
    """オブジェクトの位置とキャンバスを返します
    """

    # RGBバー
    bar_box = BarBox()
    bar_box.rates = vertical_parcent
    width1 = int(bar_box.rates[0] * 20 * GRID_UNIT)
    width2 = int(bar_box.rates[1] * 20 * GRID_UNIT)
    width3 = int(bar_box.rates[2] * 20 * GRID_UNIT)
    bar_box.left = BAR_BOX_LEFT
    bar_box.lower_x = bar_box.left + width3
    bar_box.upper_x = bar_box.lower_x + width2
    bar_box.right = bar_box.upper_x + width1
    bar_box.top = BAR_BOX_TOP
    bar_box.bottom = bar_box.top + 90
    bar_box.label_gap = int(-0.75 * GRID_UNIT)
    bar_box.font_scale = FONT_SCALE
    bar_box.line_type = 2
    bar_box.font = cv2.FONT_HERSHEY_SIMPLEX

    # レールとなる円 circle rail
    circle_rail = CircleRail()
    circle_rail.drawing_top = bar_box.bottom + GRID_UNIT
    circle_rail.drawing_bottom = CANVAS_HEIGHT - GRID_UNIT
    circle_rail.range1 = int(width2 / 2)

    circle_rail.center = (int((bar_box.lower_x + bar_box.upper_x) / 2),
                          bar_box.bottom + CIRCLE_DISTANCE + circle_rail.range1
                          )  # x, y
    circle_rail.border_rect = Rectangle(
        bar_box.lower_x, circle_rail.center[1] - circle_rail.range1,
        bar_box.upper_x, circle_rail.center[1] + circle_rail.range1)
    circle_rail.point_range = 4

    # 外環状
    outer_circle.origin = (circle_rail.center[0], circle_rail.center[1])
    outer_circle.area_size = (int(bar_box.width * 9 / 10),
                              int(bar_box.width * 9 / 10))
    outer_circle.phases = PHASE_COUNTS
    outer_circle.tickness = int(1.5 * GRID_UNIT)

    inscribed_triangle = InscribedTriangle()

    # 時計の針
    clock_hand = ClockHand()
    clock_hand.center = (circle_rail.center[0], circle_rail.center[1])
    clock_hand.unit_arc = outer_circle.unit_arc
    clock_hand.tickness = 2
    clock_hand.rng1 = circle_rail.range1  # 1st range
    rng2_expected = bar_box.width * 9 / 10
    clock_hand.rng2 = int(rng2_expected - outer_circle.tickness / 2 -
                          clock_hand.tickness)  # 2nd range
    clock_hand.rng3 = int(rng2_expected + outer_circle.tickness / 2 +
                          clock_hand.tickness)  # 3rd range

    return bar_box, circle_rail, outer_circle, inscribed_triangle, clock_hand
Example #2
0
def update_scene1(bar_rate, outer_circle):
    """オブジェクトの位置とキャンバスを返します
    """

    # RGBバー
    bar_box = BarBox()
    bar_box.rates = bar_rate
    left_box_width = bar_box.rates[0] * 20 * GRID_UNIT
    middle_box_width = bar_box.rates[1] * 20 * GRID_UNIT
    right_box_width = bar_box.rates[2] * 20 * GRID_UNIT
    bar_box.left = BAR_BOX_LEFT
    bar_box.lower_x = bar_box.left + left_box_width
    bar_box.upper_x = bar_box.lower_x + middle_box_width
    bar_box.right = bar_box.upper_x + right_box_width
    bar_box.top = BAR_BOX_TOP
    bar_box.bottom = bar_box.top + 90
    bar_box.label_gap = -0.75 * GRID_UNIT
    bar_box.font_scale = FONT_SCALE
    bar_box.line_type = 2
    bar_box.font = cv2.FONT_HERSHEY_SIMPLEX

    # レールとなる円 circle rail
    circle_rail = CircleRail()
    circle_rail.drawing_top = bar_box.bottom + GRID_UNIT
    circle_rail.drawing_bottom = CANVAS_HEIGHT - GRID_UNIT
    circle_rail.radius = middle_box_width / 2

    circle_rail.center = ((bar_box.lower_x + bar_box.upper_x) / 2,
                          bar_box.bottom + CIRCLE_DISTANCE +
                          bar_box.width * 4 / 10)
    circle_rail.border_rect = Rectangle(
        bar_box.lower_x, circle_rail.center[1] - circle_rail.radius,
        bar_box.upper_x, circle_rail.center[1] + circle_rail.radius)
    circle_rail.point_range = 4

    radius2_expected = bar_box.width * 9 / 10

    # 外環状
    outer_circle.origin = (circle_rail.center[0], circle_rail.center[1])
    outer_circle.radius = radius2_expected
    outer_circle.phases = PHASE_COUNTS
    outer_circle.tickness = 5.0 * GRID_UNIT  # 3.0*GRID_UNIT  # 1.5*GRID_UNIT

    # 長方形に内接する大きな正三角形
    large_triangle = Triangle()
    large_triangle.edge_color = GRAY
    large_triangle.nodes_color = (RED, GREEN, BLUE)
    large_triangle.node_radius = GRID_UNIT / 2
    large_triangle.center_color = GRAY

    # 時計の針
    clock_hand = ClockHand()
    clock_hand.center = (circle_rail.center[0], circle_rail.center[1])
    clock_hand.unit_arc = outer_circle.unit_arc
    clock_hand.tickness = 2
    clock_hand.radius1 = circle_rail.radius  # 1st range
    clock_hand.radius2 = radius2_expected - \
        outer_circle.tickness / 2 - clock_hand.tickness  # 2nd range
    clock_hand.radius3 = radius2_expected + \
        outer_circle.tickness / 2 + clock_hand.tickness  # 3rd range

    return bar_box, circle_rail, outer_circle, large_triangle, clock_hand