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
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
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
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()
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
'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), 'y': (bottom is not None) + (centre_y is not None) + (top is not None)
triangles = [draw_a_triangle(tip_x=0, tip_y=distance_triangles, height=triangle_height, width=3.5, turn=6) for _ in range(4)] for t, angle in enumerate([-0.19, -0.1, 0.1, 0.19]): triangles[t].turn(turn=angle, diamond_override=[0,0]) big_triangles = [draw_a_triangle(tip_x=0, tip_y=distance_triangles, height=triangle_height, width=13, turn=6) for _ in range(2)] for t, lr in enumerate([-1, 1]): big_triangles[t].turn(turn=-lr*.1, diamond_override=[0, distance_triangles-triangle_height]) big_triangles[t].turn(turn=lr*.5, diamond_override=[0,0]) for trngl in triangles + big_triangles: trngl.turn(turn=12/8*i, diamond_override=[0,0]) layers_4 = new_layers_outline_behind() angle_one_arc = asin_hours(sin_hours(12/16) * arc_distance / init_radius_arc) arc_colours = ['royalblue', 'powderblue'] centre_arc_y = arc_distance * cos_hours(12/16) - init_radius_arc * cos_hours(angle_one_arc) for i in range(8): sectors = [draw_a_sector(angle_start=-angle_one_arc, angle_end=angle_one_arc, radius=init_radius_arc + r * arc_width, radius_2=init_radius_arc + (r+1) * arc_width, centre_x=0, centre_y=centre_arc_y, colour=arc_colours[r]) for r in range(2)] for s in sectors: s.turn(turn=12/8*i, diamond_override=[0,0]) draw_a_segment(start_x=0, start_y=0, turn=12/8*i, length=centre_arc_y+init_radius_arc) layers_5 = new_layers_outline_behind() width_2 = (distance_triangles_2 - triangle_height_2) * atan_hours(12/(24*2))