def test_mirror_end_slant(): paper = Paper() p = Pen() p.stroke_mode(sqrt2) p.move_to((0, 0)) p.turn_to(-45) p.line_forward(5 * sqrt2, end_slant=45) p.paper.mirror_x(0) paper.merge(p.paper) p = Pen() p.stroke_mode(sqrt2) p.move_to((0, 0)) p.turn_to(45) p.line_forward(5 * sqrt2) paper.merge(p.paper) paper.join_paths() paper.fuse_paths() assert_path_data( paper, 1, 'M-5.5,4.5 L-4.5,5.5 L5.5,-4.5 L4.5,-5.5 L-5.5,4.5 z' )
def test_mirror_end_slant(): paper = Paper() p = Pen() p.stroke_mode(sqrt2) p.move_to((0, 0)) p.turn_to(-45) p.line_forward(5 * sqrt2, end_slant=45) p.paper.mirror_x(0) paper.merge(p.paper) p = Pen() p.stroke_mode(sqrt2) p.move_to((0, 0)) p.turn_to(45) p.line_forward(5 * sqrt2) paper.merge(p.paper) paper.join_paths() paper.fuse_paths() assert_path_data(paper, 1, 'M-5.5,4.5 L-4.5,5.5 L5.5,-4.5 L4.5,-5.5 L-5.5,4.5 z')
def draw_character(self, mode, fuse=True): paper = Paper() top_ending = self.top_ending_class( self, self.top_straight, self.top_flipped, ) bottom_ending = self.bottom_ending_class( self, self.bottom_straight, self.bottom_flipped, ) # While drawing the body of the primary character, two copies of the # pen are created, one ready to draw each of the endings. pen = Pen() pen.set_mode(mode) top_pen, bottom_pen = self.draw(pen) top_start_position = top_pen.position bottom_start_position = bottom_pen.position # Draw the endings. # If the ending orientations are to the left, then we have to flip them # horizontally. # The top ending is drawn as if it were a bottom ending, so # mirror it to the top. if self.top_flipped: top_pen.turn_to(top_pen.heading.flipped_x()) top_pen.move_to(top_pen.position.flipped_y(MIDDLE)) top_pen.turn_to(top_pen.heading.flipped_y()) top_ending.draw(top_pen) top_pen.paper.mirror_y(MIDDLE) if self.top_flipped: top_pen.paper.mirror_x(top_start_position.x) if self.bottom_flipped: bottom_pen.turn_to(bottom_pen.heading.flipped_x()) bottom_ending.draw(bottom_pen) if self.bottom_flipped: bottom_pen.paper.mirror_x(bottom_start_position.x) paper.merge(pen.paper) paper.merge(top_pen.paper) paper.merge(bottom_pen.paper) if fuse: paper.join_paths() paper.fuse_paths() # Override the bounds so that the letter reaches the full line height. bounds = paper.bounds() bounds.bottom = UNDER bounds.top = OVER paper.override_bounds(bounds) # We need to center on x=0 here because otherwise flipped # consonants wouldn't flip at the right x value. paper.center_on_x(0) return paper
def draw_character(self, mode, fuse=True): side_ending = self.side_ending_class(self, self.side_flipped) bottom_ending = self.bottom_ending_class( self, self.bottom_straight, self.bottom_flipped, ) paper = Paper() # When drawing the body of the consonant, subclasses will start # where the side ending is, and end where the bottom ending is. pen = Pen() pen.set_mode(mode) pen.move_to((0, TOP - pen.mode.width / 2)) side_ending_position = pen.position self.draw(pen) bottom_ending_position = pen.position bottom_ending_heading = pen.heading paper.merge(pen.paper) # Draw the side ending. pen = Pen() pen.set_mode(mode) pen.move_to(side_ending_position) pen.turn_to(0) side_ending.draw(pen) paper.merge(pen.paper) # Draw the bottom ending. pen = Pen() pen.set_mode(mode) pen.move_to(bottom_ending_position) # If the bottom orientation is slanted left, then we have to # start the bottom ending from a flipped heading so when it flips # again later it will be correct. if not self.bottom_straight and self.bottom_flipped: bottom_ending_heading = bottom_ending_heading.flipped_x() pen.turn_to(bottom_ending_heading) # Draw the ending, and maybe flip it horizontally. bottom_ending.draw(pen) if not self.bottom_straight and self.bottom_flipped: pen.paper.mirror_x(bottom_ending_position.x) paper.merge(pen.paper) if fuse: paper.join_paths() paper.fuse_paths() # Override the bounds so that the letter reaches the full line height. bounds = paper.bounds() bounds.bottom = UNDER bounds.top = OVER paper.override_bounds(bounds) # We need to center on x=0 here because otherwise flipped # consonants wouldn't flip at the right x value. paper.center_on_x(0) return paper