def example_croc(axes=None): ######################################################### ## CREATING THE DRAWING! ## ######################################################### # Creating the canvas! ## axes = create_canvas_and_axes(canvas_width = 190, canvas_height = 100, background_colour = 'PastelBlue', axes = axes) ####################################################### # Now let's draw the shapes! ## left_body = 30 bottom_body = 30 right_body = 120 right_head = 180 top_body = 50 top_head = bottom_body+15 tail_right = 35 + left_body tail_width = 10 centre_backside = 50 r_nostrils = 3 lip_y = 0.5 * (top_head + bottom_body) lip_r = 3 teeth_length = 5 nb_teeth = 7 leg_width = 10 leg_length = 15 feet_height = 5 feel_length = 20 ####################################################### # Now let's draw the shapes! ## set_default_patch_style(colour='BrightGreen') # legs leg_layer_nb = new_layer() for shift, colour in [[0, 'green'], [-17, 'BrightGreen']]: for x in [50, 100]: # draw a leg draw_a_rectangle(ax=axes, left=x+shift, top=bottom_body, height=leg_length, width=leg_width, colour=colour) # draw a feet draw_a_sector(ax=axes, centre_x=x+shift+feel_length/2, centre_y=bottom_body-leg_length, radius=feel_length/2, stretch_y=feet_height/(feel_length/2), angle_start=9, angle_end=15, colour=colour) # body body_layer_nb = new_layer() draw_a_rectangle(ax=axes, left=left_body, bottom=bottom_body, height=top_body-bottom_body, width=right_body-left_body) # backside backside_clip_contour = build_a_circle(radius=centre_backside-bottom_body) + [left_body, centre_backside] draw_a_sector( ax=axes, centre_x=left_body, centre_y=(2*centre_backside-bottom_body-tail_width+top_body)/2, radius=(2*centre_backside-bottom_body-tail_width+top_body)/2-bottom_body, radius_2=(2*centre_backside-bottom_body-tail_width-top_body)/2, angle_start=6, angle_end=12, clip_outline=backside_clip_contour) # tail draw_a_rectangle(ax=axes, left=left_body, top=2*centre_backside-bottom_body, height=tail_width, width=tail_right-left_body) draw_a_sector(ax=axes, centre_x=tail_right, centre_y=2*centre_backside-bottom_body, radius=tail_width,angle_start=3, angle_end=6) # lower teeth and jaw upper_teeth = build_a_zigzag(width=right_head - (right_body-lip_r), height=teeth_length, angle_start=3, nb_segments=2*nb_teeth) + [right_body-lip_r, lip_y] lower_teeth = upper_teeth[1:-1] + [0, teeth_length] draw_a_polygon(ax=axes, contour=lower_teeth, colour='white') draw_a_rectangle(ax=axes, left=right_body, bottom=bottom_body, height=lip_y-bottom_body, width=right_head-right_body) # upper jaw upper_jaw_layer_nb = new_layer() draw_a_rectangle(ax=axes, left=right_body, bottom=lip_y, height=top_head-lip_y, width=right_head-right_body) # ... and the eyes, white circles with black circles on top eye_y = top_body for radius, colour in [[8, 'BrightGreen'], [5, 'white'], [3, 'black']]: for eye_x in [right_body, right_body+12]: draw_a_circle(ax=axes, centre_x=eye_x, centre_y=eye_y, radius=radius, colour=colour) # ... and the eyelids. Saving them in array for future use eyelids = [] eyelid_width = 12 for eye_x in [right_body, right_body+12]: for td in [-1, 1]: mid_y = td * eyelid_width / 2 eyelid = draw_an_eye(ax=axes, centre_x=eye_x, centre_y=eye_y, width=eyelid_width, depth_1=mid_y, depth_2=mid_y, colour='green') eyelids.append(eyelid) # ... and the nostrils nostril_y = top_head for nostril_x in [right_head-r_nostrils, right_head-3*r_nostrils]: draw_a_circle(ax=axes, centre_x=nostril_x, centre_y=nostril_y, radius=r_nostrils) draw_a_circle(ax=axes, centre_x=nostril_x, centre_y=nostril_y, radius=1, colour='green') # ... and the teeth and the lip # teeth draw_a_polygon(ax=axes, contour=upper_teeth, colour='white') # upper lip lipline_arc = build_an_arc(radius=lip_r, angle_start=6, angle_end=9) + [right_body-lip_r, lip_y+lip_r] lipline = link_contours([[right_head, lip_y]], lipline_arc) draw_a_broken_line(ax=axes, contour=lipline, colour='green', linewidth=2) upper_jaw_diamond = [right_body-lip_r, lip_y+lip_r] return leg_layer_nb, body_layer_nb, upper_jaw_layer_nb, eyelids, upper_jaw_diamond
def draw_half_circle(turn, **kwargs): draw_a_sector(angle_start=turn, angle_end=turn+6, **kwargs)
def example_penguins(axes=None): def draw_half_circle(turn, **kwargs): draw_a_sector(angle_start=turn, angle_end=turn+6, **kwargs) ####################################################### # Creating the canvas! ## create_canvas_and_axes(canvas_width = 320, canvas_height = 180, title = "Penguin Conversation", #tick_step = 10, #model="https://i.pinimg.com/564x/fc/90/7d/fc907dc3638cfd64aa2c3ba56e216b92.jpg", background_colour = 'lightskyblue', axes=axes) ####################################################### # Now let's draw the shapes! ## # snowflakes for s in range(150): draw_a_star(centre_x=random_number(max = get_width(axes)), centre_y=random_number(max = get_height(axes)), radius_1=1, radius_2=3, ends_qty=8, colour='aliceblue') # ice ice_colours = ['aliceblue', 'steelblue', 'skyblue'] for s in range(1500): draw_a_triangle(tip_x=random_number(max = get_width(axes)), tip_y=0.2*random_number(max = get_height(axes)), height=random_number(30), width=random_number(15), turn=random_element(range(2, 11)), colour = random_element(ice_colours)) # penguins! # the penguin on the left # body draw_a_circle(centre_x=60, centre_y=40, radius=20, colour='white') # feet draw_half_circle(centre_x=54, centre_y=16, radius=6, colour='orangered', turn=8.5) draw_half_circle(centre_x=66, centre_y=16, radius=6, colour='orangered', turn=9.5) # wings draw_half_circle(centre_x=31, centre_y=60, radius=30, colour='black', turn=2) draw_half_circle(centre_x=89, centre_y=60, radius=30, colour='black', turn=4) # head draw_a_circle(centre_x=60, centre_y=80, radius=15, colour='black') # eyes draw_a_circle(centre_x=55, centre_y=85, radius=3, colour=None, outline_colour='white', outline_linewidth=2) draw_a_circle(centre_x=65, centre_y=85, radius=3, colour=None, outline_colour='white', outline_linewidth=2) # beck draw_a_sector(centre_x=58, centre_y=76, angle_start=0, angle_end=3, radius=6, stretch_x=1.5, turn=0.5, colour='orangered') # the penguin on the right # first foot draw_half_circle(centre_x=270, centre_y=16, radius=6, colour='orangered', turn=9) # body - white draw_half_circle(centre_x=280, centre_y=50, radius=30, colour='white', turn=5) # second foot draw_half_circle(centre_x=280, centre_y=15, radius=6, colour='orangered', turn=8) # body - black draw_half_circle(centre_x=290, centre_y=50, radius=30, colour='black', turn=5) # beck draw_half_circle(centre_x=255, centre_y=75, radius=6, colour='orangered', turn=8 + 1/2) # head draw_a_circle(centre_x=270, centre_y=80, radius=15, colour='black') # an eye draw_a_circle(centre_x=263, centre_y=85, radius=3, colour=None, outline_colour='white', outline_linewidth=2) show_drawing_and_save_if_needed()
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)) print(width_2) for i in range(24): trngl = draw_a_triangle(tip_x=0, tip_y=distance_triangles_2, height=triangle_height_2, width=width_2, turn=6, colour='deepskyblue') trngl.turn(turn=12/24*i, diamond_override=[0,0])
axes_label_font_size=figure_params['font_size'], axes_tick_font_size=figure_params['font_size'], axes=ax) colour = {'angle' : 'violet', 'sinus' : 'dodgerblue', 'cosinus' : 'blueviolet', 'hypothenuse' : 'crimson'} start_trigo = 1.5 wave_factor = 6 set_default_outline_style(linewidth=3) set_default_line_style(linewidth=3) segments = [None for _ in range(7)] draw_a_circle(centre_x=0, centre_y=0, radius=1) sector = draw_a_sector(centre_x=0, centre_y=0, radius=.2, angle_start=0, angle_end=0, colour=colour['angle']) segments[0] = draw_a_broken_line(contour=[[0, 0]], colour=colour['hypothenuse']) set_default_outline_style(linewidth=0) # sin segments[1] = draw_a_broken_line(contour=[[0, 0]], colour=colour['cosinus']) segments[2] = draw_a_broken_line(contour=[[0, 0]], colour=colour['sinus']) segments[3] = draw_a_broken_line(contour=[[0, 0]], colour='black') wave_sinus = draw_a_wave(start_x=start_trigo, start_y=1, width=1, height=2, angle_start=0, nb_waves=1, colour=colour['sinus'], turn=3) dot_sinus = draw_a_circle(centre_x=0, centre_y=0, radius=.1, colour=colour['sinus']) square_sinus = draw_a_square(centre_x=0, centre_y=0, side=.2, colour=colour['sinus']) # cos segments[4] = draw_a_broken_line(contour=[[0, 0]], colour=colour['sinus'])
radius=.3, colour='black', outline_linewidth=0) # an egg an_egg = draw_an_egg(power=3, height_widest_point=3, width=4, height=5, tip_x=30, tip_y=height_ground, colour='crimson') draw_a_sector(centre_x=30, centre_y=stripe_radius + (3 + height_ground), angle_start=3, angle_end=9, radius=stripe_radius, radius_2=stripe_radius + 1, colour='Yellow', clip_outline=an_egg) # an apple = two eggs, a smile and an eye for x in [40 - 0.75, 40 + 0.75]: draw_an_egg(power=3, height_widest_point=3, width=4, height=5, tip_x=x, tip_y=height_ground, colour='greenyellow', outline_linewidth=4, layer_nb=2)