Esempio n. 1
0
def example_segment(axes=None):
  axes = create_canvas_and_axes(canvas_width = 12,
                                canvas_height = 10, tick_step=1)
  set_default_line_style(linewidth=20)
  set_default_outline_style(linewidth=20)
  ln = new_layer()
  segment = draw_a_segment(ax=axes, start_x=6, start_y=3, turn=0, length=4)
  circle = draw_a_circle(ax=axes, centre_x=6, centre_y=9, radius=1)

  # return the list of the shapes that are moved by animation
  def init():
    return get_all_polygons_in_layers()

  def animate(i):
    # eyelid blink  
    if i < 20:
      if i % 10 == 0:
        shift_layer(shift=[0,  1], layer_nbs=[ln])
    if 20 <= i < 40:
      if i % 10 == 0:
        shift_layer(shift=[0, -1], layer_nbs=[ln])
    if 60 <= i < 80:
      if i % 10 == 0:
        rotate_layer(turn=1, diamond=[6, 3], layer_nbs=[ln])
    if 40 <= i < 60:
      if i % 10 == 0:
        stretch_layer(stretch_x=0.5, stretch_y=0.5, diamond=[6, 3], layer_nbs=[ln])
    if i % 10 == 0:
      print(i, segment.get_xy(), circle.diamond_coords)

    return get_all_polygons_in_layers()

  show_drawing_and_save_if_needed( # filename="line", 
   animation_func = animate,  animation_init = init, nb_of_frames = 80)
Esempio n. 2
0
def example_yellow_cat(axes=None, cat_colour = 'Yellow', background_colour = 'SeaWave'):
  #######################################################
  ## CREATING THE DRAWING!                             ##
  #######################################################
  ## Creating the canvas!                              ##  
  axes = create_canvas_and_axes(canvas_width = 120,
                                canvas_height = 120,
                                background_colour = background_colour, 
                                axes = axes,
                                make_symmetric = 'x')
  #######################################################
  # Now let's draw the shapes!                         ##

   # settings
  set_default_outline_style(linewidth=2)
  set_default_line_style(linewidth=2)
  set_default_patch_style(colour=cat_colour)#darkorange

  # the tail
  tail_length = [30, 22, 20, 12, 10]
  for i, tl in enumerate(tail_length): 
    triangle_tail = draw_a_triangle(ax=axes, tip_x=38, tip_y=30, height=tl, width=tl/2, turn=7)
    if i%2 == 1:
      triangle_tail.set_style(colour='black')


  # the body
  height_body = [60, 57, 54, 38, 35, 19, 16]
  for i, bh in enumerate(height_body):
    triangle_body = draw_a_triangle(ax=axes, tip_x=0, tip_y=60, height=bh, width=bh, turn=6)
    if i%2 == 1:
      triangle_body.set_style(colour='black')

  # the feet
  draw_a_triangle(ax=axes, tip_x=-12, tip_y=20, height=20, width=20, turn=6)
  draw_a_triangle(ax=axes, tip_x= 12, tip_y=20, height=20, width=20, turn=6)

  head_layer = new_layer()

  # the ears
  et = 4.5
  draw_a_triangle(ax=axes, tip_x=-30, tip_y=114, height=50, width=30, turn=et)
  draw_a_triangle(ax=axes, tip_x=-22, tip_y=106, height=40, width=24, colour='black', turn=et)
  draw_a_triangle(ax=axes, tip_x= 30, tip_y=114, height=50, width=30, turn=-et)
  draw_a_triangle(ax=axes, tip_x= 22, tip_y=106, height=40, width=24, colour='black', turn=-et)

  #head
  head_circle = draw_a_circle(ax=axes, centre_x=0, centre_y=85, radius=25)

  #from this line, the default colour is black
  set_default_patch_style(colour='black')

  # neck
  draw_a_circle(ax=axes, centre_x=0, centre_y=60, radius=1)
  neck_coords = [0, 60]

  # stripes on the face

  # vertical stripes
  for c, b in [[-10, 101], [-5, 100], [0, 101]]:
    draw_a_rectangle(ax=axes, centre_x=c, bottom=b, width=3, height=20, clip_outline = head_circle)

  # horizontal stripes
  for c, x in [[70, 16], [75, 15], [80, 18]]:
    draw_a_rectangle(ax=axes, right=-x, centre_y=c, width=20, height=3, clip_outline = head_circle)
    draw_a_rectangle(ax=axes, left=+x, centre_y=c, width=20, height=3, clip_outline = head_circle)
    
  # eyes
  eyes = []
  for centre_x in [-12, 12]:
    eye_white= draw_an_eye(ax=axes, centre_x=centre_x, centre_y=90, width=16, depth_1=-8, depth_2=8, colour='white')
    draw_an_ellipse(ax=axes, centre_x=centre_x, centre_y=90, width=8, height=16, colour='BrightGreen', clip_outline = eye_white)
    draw_a_circle(ax=axes, centre_x=centre_x, centre_y=90, radius=3, colour='black', clip_outline = eye_white)
    # the following line is needed for animation
    eyes.append(eye_white)

  # nose
  draw_a_triangle(ax=axes, tip_x=0, tip_y=72, height=8, width=10, colour='BubblePink')

  # smile
  draw_a_segment(ax=axes, start_x=0, start_y=72, length=7, turn=6)
  smile = draw_a_smile(ax=axes, centre_x=0, centre_y=69, depth=4, width=20)

  return head_layer, neck_coords, eyes, smile
Esempio n. 3
0
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()

for i in range(crescents_qty):
  circle = draw_a_circle(centre_x=0, centre_y=distance_circles, radius=1, colour='palegreen')
  circle.turn(turn=12/crescents_qty*(i+0.5), diamond_override=[0,0])

layers_3 = new_layers_outline_behind()
set_default_patch_style(colour="yellow")
Esempio n. 4
0
ax = create_canvas_and_axes(canvas_width=canvas_width,
                            canvas_height=canvas_height, 
                            tick_step=figure_params['tick_step'],
                            title="Try Out Shapes",
                            make_symmetric = True,
                            title_font_size=figure_params['font_size']*1.5,
                            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')
    # tick_step = 2,
    title="Happy Nowruz 1400!")

#######################################################
# Now let's draw the shapes!                         ##
# grass
for i in range(25):
    draw_a_triangle(tip_x=aquarium_side + 2 + i / 3,
                    tip_y=height_ground + height_grass,
                    width=0.5,
                    height=height_grass,
                    colour='springgreen',
                    turn=6,
                    opacity=0.7)

set_default_outline_style(linewidth=2)

# a table
draw_a_rectangle(left=0,
                 bottom=0,
                 width=width,
                 height=height_ground,
                 colour='MidBrown')

# an aquarium
draw_a_square(left=0,
              bottom=height_ground,
              side=aquarium_side,
              colour='PastelBlue')

# fish
Esempio n. 6
0
# Creating the canvas!                               ##
ax = create_canvas_and_axes(  canvas_width = 30,
                              canvas_height = 20,
                              make_symmetric = 'x',
                              #tick_step = 2,
                              title = "Excited Cat",
                              model = 'https://i.pinimg.com/564x/de/21/fd/de21fdb9fa70d9d54ce7e4c0f07910d5.jpg',
                              model_zoom = 1.3,
                              background_colour='aliceblue')

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

# the body
set_default_patch_style(colour="yellow", layer_nb=2)
set_default_outline_style(linewidth=4,   layer_nb=1)

body = draw_an_egg(ax=ax, power=3, height_widest_point=3, width=4, height=5, tip_x=0, tip_y=14, stretch_x=3, stretch_y=-3)

for y in [1.5, 6, 10.5]:  
  draw_a_rectangle(ax=ax, width=16, height=2, centre_x=0, centre_y=y, opacity=0.3, clip_outline=body, colour='orange', outline_linewidth=0)

# the head

set_default_patch_style(  layer_nb=4)
set_default_outline_style(layer_nb=3)

head = draw_a_circle(ax=ax, centre_x=0, centre_y=14, radius=4.2)

# the ears, using the "eye" shape
draw_a_crescent(ax=ax, width=6, depth_1=1, depth_2=3, centre_x=-4, centre_y=16, turn=9)