コード例 #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)
コード例 #2
0
def example_Zyxxy_the_mouse(axes=None, model="https://i.pinimg.com/564x/35/4c/5c/354c5c04a1f72100ca1b110007730257.jpg",
                           block=False):
  create_canvas_and_axes(canvas_width = 36,
                                canvas_height = 36, 
                                title = "Hello, I am Zyxxy!", 
                                model=model,
                                axes = axes)

  set_default_line_style(linewidth=2)
  #######################################################
  # Now let's draw the shapes!                         ##

  # Let's start with the whiskers! They need to be behind the head, 
  # so we will need to move these lines before the line
  # that draws the head of the mouse!
  draw_a_segment(start_x=18, start_y=12, turn=3, length=6)
  draw_a_segment(start_x=18, start_y=12, turn=4, length=6)
  draw_a_segment(start_x=18, start_y=12, turn=9, length=6)
  draw_a_segment(start_x=18, start_y=12, turn=8, length=6)

  # let's draw the head of the mouse
  draw_a_triangle(tip_x=18, tip_y=6, height=18, width=18, colour='plum')
  # ... and the nose, using a triangle with the same tip
  draw_a_triangle(tip_x=18, tip_y=6, height=3, width=3, colour='black')
  # ... and the ears
  draw_a_circle(centre_x=9, centre_y=24, radius=6, colour='plum')
  draw_a_circle(centre_x=27, centre_y=24, radius=6, colour='plum')
  # ... and the eyes, white circles with black circles on top
  left_eye_white = draw_a_circle(centre_x=15, centre_y=18, radius=2, colour='white')
  right_eye_white= draw_a_circle(centre_x=21, centre_y=18, radius=2, colour='white')
  left_eye_black = draw_a_circle(centre_x=15, centre_y=18, radius=1, colour='black')
  right_eye_black= draw_a_circle(centre_x=21, centre_y=18, radius=1, colour='black')

  show_drawing_and_save_if_needed(block=block)

  eyes = {'left'  : {'black':left_eye_black,  'white':left_eye_white}, 
          'right' : {'black':right_eye_black, 'white':right_eye_white}}

  return eyes
コード例 #3
0
def example_Zyxxy_the_mouse(axes=None):
  #########################################################
  ## CREATING THE DRAWING!                               ##
  #########################################################
  # Creating the canvas!                                 ##
  axes = create_canvas_and_axes(canvas_width = 12,
                                canvas_height = 10, 
                                title = "Hello, I am Zyxxy!", 
                                axes = axes)

  set_default_line_style(linewidth=2)
  #######################################################
  # Now let's draw the shapes!                         ##

  # Let's start with the whiskers! They need to be behind the head, 
  # so we will need to move these lines before the line
  # that draws the head of the mouse!
  draw_a_segment(axes, start_x=6, start_y=3, turn=3, length=2)
  draw_a_segment(axes, start_x=6, start_y=3, turn=4, length=2)
  draw_a_segment(axes, start_x=6, start_y=3, turn=9, length=2)
  draw_a_segment(axes, start_x=6, start_y=3, turn=8, length=2)

  # let's draw the head of the mouse
  draw_a_triangle(ax=axes, tip_x=6, tip_y=1, height=6, width=6, colour='plum')
  # ... and the nose, using a triangle with the same tip
  draw_a_triangle(ax=axes, tip_x=6, tip_y=1, height=1, width=1, colour='black')
  # ... and the ears
  draw_a_circle(ax=axes, centre_x=3, centre_y=7, radius=2, colour='plum')
  draw_a_circle(ax=axes, centre_x=9, centre_y=7, radius=2, colour='plum')
  # ... and the eyes, white circles with black circles on top
  left_eye_white = draw_a_circle(ax=axes, centre_x=5, centre_y=5, radius=0.8, colour='white')
  right_eye_white= draw_a_circle(ax=axes, centre_x=7, centre_y=5, radius=0.8, colour='white')
  left_eye_black = draw_a_circle(ax=axes, centre_x=5, centre_y=5, radius=0.5, colour='black')
  right_eye_black= draw_a_circle(ax=axes, centre_x=7, centre_y=5, radius=0.5, colour='black')

  return left_eye_white, right_eye_white, left_eye_black, right_eye_black
コード例 #4
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
コード例 #5
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])

  if i%3 == 0:
    continue

  for colour, radius in [['royalblue', 1.4], ['white', .5]]:
    circle = draw_a_circle(centre_x=0, centre_y=distance_triangles_2+1.4, radius=radius, colour=colour)
    circle.set_style(outline_layer_nb=layers_5[1], outline_linewidth=outline_linewidth)
    circle.turn(turn=12/24*i, diamond_override=[0,0])
コード例 #6
0
draw_a_crescent(ax=ax, width=6, depth_1=1, depth_2=3, centre_x=-4, centre_y=16, turn=9)
draw_a_crescent(ax=ax, width=6, depth_1=1, depth_2=3, centre_x=4, centre_y=16, turn=3)

new_layer()

# the stripes
for y in [10.5, 15]:  
  draw_a_rectangle(ax=ax, width=16, height=2, centre_x=0, centre_y=y, opacity=0.3, clip_outline=head, colour='orange', outline_linewidth=0)

# change outlines style
set_default_outline_style(linewidth=2)

# the eyes
eye_height = 15
for centre_x in [-2, 2]:
  draw_a_crescent(ax=ax, centre_x=centre_x, centre_y=eye_height, width=2, depth_1=-1, depth_2=1, colour='white')
  draw_an_ellipse(ax=ax, centre_x=centre_x, centre_y=eye_height, width=1, height=2, colour='red')
  draw_a_circle(ax=ax, centre_x=centre_x, centre_y=eye_height, radius=0.5, colour='black')

draw_a_triangle(ax=ax, width=2, height=1, tip_x=0, tip_y=eye_height-2.5, colour='black')
draw_a_segment(ax=ax, start_x= 2, start_y=eye_height-2, turn=3, length=3.5)
draw_a_segment(ax=ax, start_x= 2, start_y=eye_height-3, turn=4, length=3.5)
draw_a_segment(ax=ax, start_x=-2, start_y=eye_height-2, turn=9, length=3.5)
draw_a_segment(ax=ax, start_x=-2, start_y=eye_height-3, turn=8, length=3.5)

# the mouth
draw_a_crescent(ax=ax, width=2, depth_1=1, depth_2=1.5, centre_x=0, centre_y=12.5, colour='pink')

draw_a_star(ax=ax, centre_x=-8, centre_y=18, radius_1=3, radius_2=1, ends_qty=8, colour='red')

show_drawing_and_save_if_needed()
コード例 #7
0
                     centre_y=gradient_bottom + i * grh,
                     opacity=1,
                     clip_outline=body,
                     colour=gc,
                     outline_linewidth=0)
    draw_a_rectangle(width=30,
                     height=grh,
                     centre_x=0,
                     centre_y=gradient_bottom + i * grh,
                     opacity=1,
                     clip_outline=tail_shape,
                     colour=gc,
                     outline_linewidth=0)

# a vertical line
draw_a_segment(start_x=0, start_y=eye_y, turn=6, length=1.5)

for lr in [-1, 1]:
    # an eye
    draw_a_circle(centre_x=lr * 3, centre_y=eye_y, radius=1, colour='black')

    # mouth
    draw_a_smile(centre_x=lr * aw / 2,
                 centre_y=eye_y - 1.5,
                 width=aw,
                 depth=0.5)

    # whiskers
    draw_a_smile(centre_x=lr * (6 + whiskers_length / 2),
                 centre_y=eye_y - 0.5,
                 width=whiskers_length,