Exemplo n.º 1
0
def _build_an_arc(angle_start, angle_end):
    if angle_start > angle_end:
        angle_start, angle_end = angle_end, angle_start

    angle_start_normalized = angle_start / full_turn_angle
    angle_end_normalized = angle_end / full_turn_angle

    turn_nb_start = floor(angle_start_normalized)
    turn_nb_end = floor(angle_end_normalized)

    residual_start = ceil((angle_start_normalized - turn_nb_start) *
                          my_default_vertices_qty_in_circle)
    residual_end = floor((angle_end_normalized - turn_nb_end) *
                         my_default_vertices_qty_in_circle)

    if is_the_same_point(turn_nb_start, turn_nb_end):
        contour = sin_cos_std[residual_start:(residual_end + 1)]
    else:
        contour = sin_cos_std[residual_start:] + sin_cos_std * int(
            turn_nb_end - turn_nb_start - 1) + sin_cos_std[:(residual_end + 1)]

    contour = np.array(contour, np.float64)

    c_len = contour.size
    contour = link_contours([[sin_hours(angle_start),
                              cos_hours(angle_start)]], contour)
    if c_len == contour.size:
        added_start = None
    else:
        added_start = residual_start - (angle_start_normalized %
                                        1) * my_default_vertices_qty_in_circle

    c_len = contour.size
    contour = link_contours(
        contour,
        [[sin_hours(angle_end), cos_hours(angle_end)]])
    if c_len == contour.size:
        added_end = None
    else:
        added_end = -residual_end + (angle_end_normalized %
                                     1) * my_default_vertices_qty_in_circle

    return contour, added_start, added_end
Exemplo n.º 2
0
def build_a_squiggle(angle_start, angle_end, speed_x, width, height):
    if angle_start > angle_end:
        angle_start, angle_end = angle_end, angle_start

    step = full_turn_angle / (max(abs(speed_x), 1) *
                              my_default_vertices_qty_in_circle)
    angles = link_contours(np.arange(angle_start, angle_end, step),
                           [angle_end])

    contour = np.array([[sin_hours(a * speed_x),
                         cos_hours(a)]
                        for a in angles]) * [width / 2, height / 2]
    return contour
Exemplo n.º 3
0
def build_a_star(ends_qty, radius_1, radius_2):
    angles = [
        i * full_turn_angle / (2 * ends_qty) for i in range(2 * ends_qty)
    ]
    radii = [
        radius_1 * (i % 2 == 0) + radius_2 * (i % 2 == 1)
        for i in range(2 * ends_qty)
    ]

    contour = np.array(
        [[radii[i] * sin_hours(angles[i]), radii[i] * cos_hours(angles[i])]
         for i in range(2 * ends_qty)])

    return contour
Exemplo n.º 4
0
def change_angle(angle):

  sin_angle, cos_angle = sin_hours(angle), cos_hours(angle)

  segment_coords = [[[0, 0], [sin_angle, cos_angle]],
                    [[0, 0], [0, cos_angle]],
                    [[0, cos_angle], [sin_angle, cos_angle]],
                    [[max(0, sin_angle), cos_angle], [start_trigo, cos_angle]],
                    [[0, 0], [sin_angle, 0]],
                    [[sin_angle, 0], [sin_angle, cos_angle]],
                    [[sin_angle, max(0, cos_angle)], [sin_angle, start_trigo]]]
  for i in range(7):
    segments[i].update_xy_by_shapename(shapename=segment_coords[i])

  sector.update_shape_parameters(angle_end=angle)
  dot.shift_to([sin_angle, cos_angle])

  dot_sinus.shift_to( [sin_angle, start_trigo])
  square_sinus.shift_to( [0, start_trigo+angle/wave_factor])
  wave_sinus.update_shape_parameters(angle_start=0, width=angle/wave_factor, nb_waves=angle/full_turn_angle)
  wave_sinus.shift_to([0, start_trigo+angle/wave_factor])

  dot_cosinus.shift_to( [start_trigo, cos_angle])
  square_cosinus.shift_to( [start_trigo+angle/wave_factor, 1])
  wave_cosinus.update_shape_parameters(angle_start=3-angle, width=angle/wave_factor, nb_waves=angle/full_turn_angle)
  wave_cosinus.shift_to([start_trigo, cos_angle])

  # a legend
  values =  {'angle' : angle, 'sinus' : sin_hours(angle), 'cosinus' : cos_hours(angle)}
  colors = colour.values()
  lines = [Line2D([0], [0], color=c, linewidth=3) for c in colors]
  labels = [k + ('(' + str(round(angle, 1)) + 'h)' if k!= 'angle' else '') + '=' + str(round(values[k], 3)) + ('' if k!= 'angle' else 'h') for k in colour.keys() if k!='hypothenuse'] + ['hypothenuse']

  nb_legend_lines = 4 if 0 <= angle <= 3 else 3
  ax.legend(lines[:nb_legend_lines], labels[:nb_legend_lines], loc='upper right') 

  plt.gcf().canvas.draw_idle()
Exemplo n.º 5
0
def build_a_heart(angle_top_middle, tip_addon):
    radius = 1 / (1 + sin_hours(angle_top_middle)
                  )  # this ensures that the width = 2

    a = sin_hours(angle_top_middle) * radius
    b = (1 + tip_addon) * radius
    c = sqrt(a * a + b * b)

    angle_bottom = atan_hours(a / b) + asin_hours(radius / c)

    # adding the right half-circle
    right_arc = build_an_arc(
        angle_start=full_turn_angle - angle_top_middle,
        angle_end=full_turn_angle * 1.25 + angle_bottom) * radius
    # moving the mid-point's x to 0
    right_arc -= [right_arc[0, 0], 0]
    # adding the tip
    right_side = link_contours(right_arc, [[0, -radius * (1 + tip_addon)]])
    # moving up so that the tip is in [0, 0]
    right_side += [0, +radius * (1 + tip_addon)]
    # adding up a left side
    contour = add_a_left_mirror(right_side)

    return contour
Exemplo n.º 6
0
def build_a_regular_polygon(vertices_qty, radius):
    angles = [(i * full_turn_angle / vertices_qty)
              for i in range(vertices_qty)]
    contour = np.array([[sin_hours(a), cos_hours(a)] for a in angles]) * radius
    return contour
Exemplo n.º 7
0
        'speed_x': 'stretch',
        'speed_out': ['stretch', 1.2]
    },
    'a_squiggle': {
        'angle_start': ['turn', 0],
        'angle_end': ['double_turn', 24],
        'speed_x': ['stretch', 3],
        'width': ['half_width', 2],
        'height': 'half_height'
    }
}

########################################################################

sin_cos_std = [[
    sin_hours(a / my_default_vertices_qty_in_circle * full_turn_angle),
    cos_hours(a / my_default_vertices_qty_in_circle * full_turn_angle)
] for a in range(my_default_vertices_qty_in_circle)]


############################################################################################################
def init_shift(contour,
               left=None,
               centre_x=None,
               right=None,
               bottom=None,
               centre_y=None,
               top=None):
    # checking that we the right number of inputs
    how_many_are_defined = {
        'x': (left is not None) + (centre_x is not None) + (right is not None),
Exemplo n.º 8
0
                       model = 'https://i.pinimg.com/564x/24/be/7a/24be7a90f25924c924733e51660b5cfe.jpg',
                       model_zoom = 1.3 * 1.5,
                       background_colour='white')

#######################################################
# Now let's draw the shapes!                         ##

distance_crescents = 38
distance_circles = 30
distance_triangles = 27
triangle_height = 8
crescents_qty = 40
arc_distance = 16
arc_width = 1
init_radius_arc = 6.5
assert sin_hours(12/16) * arc_distance < init_radius_arc
distance_triangles_2 = 13
triangle_height_2 = 7

outline_linewidth = 1.5

set_default_outline_style(linewidth=2*outline_linewidth) # because outline is usually behind

layers_1 = new_layers_outline_behind()
crescent_colours = ['deepskyblue', 'royalblue']
for i in range(crescents_qty):
  crsc = draw_a_crescent(centre_x=0, centre_y=distance_crescents, width=2*tan_hours(12/(2*crescents_qty))*distance_crescents, depth_1=1.2, depth_2=2, colour=crescent_colours[i%2], stretch_y=3)
  crsc.turn(turn=12/crescents_qty*i, diamond_override=[0,0])

layers_2 = new_layers_outline_behind()