Example #1
0
    def __init__(self,
                 path_string,
                 group_transform,
                 style_attributes=None,
                 ellipse_approx_lvl=5,
                 bezier_3_approx_lvl=8,
                 bezier_2_approx_lvl=8):
        if style_attributes is None:
            style_attributes = ['fill', 'stroke']
        self.points = []
        self.ended_on = Point()
        self.return_after_z = Point()
        self.max_y = None
        self.max_x = None
        self.not_implemented = False
        self.path_id = get_info_part(path_string, 'id')
        self.style = self.parse_style(get_info_part(path_string, 'style'),
                                      style_attributes)
        {
            path_string.startswith('rect'):
            lambda: self.process_rect(path_string),
            path_string.startswith('path'):
            lambda: self.process_path(path_string, bezier_3_approx_lvl,
                                      bezier_2_approx_lvl),
            path_string.startswith('ellipse'):
            lambda: self.process_ellipse(path_string, ellipse_approx_lvl)
        }[True]()

        full_transform = ''

        transform_str = get_info_part(path_string, 'transform')
        if transform_str is not None:
            full_transform += transform_str

        if group_transform is not None:
            full_transform += f', {group_transform}'

        print(full_transform)
        full_transform_obj = Transform(full_transform)

        for pt_idx in range(len(self.points)):
            pt = self.points[pt_idx]
            if pt is not None:
                transformed_pt = full_transform_obj.apply(pt)

                if type(transformed_pt) == str:
                    self.oops(transformed_pt)
                    break

                self.points[pt_idx] = transformed_pt

                if self.max_y is None or self.max_y < transformed_pt.y:
                    self.max_y = transformed_pt.y

                if self.max_x is None or self.max_x < transformed_pt.x:
                    self.max_x = transformed_pt.x
Example #2
0
    def update(self, delta):
        """Updates the game object. Delta time is in ms."""
        super().update()
        self.transform()
        for attachment in self.attachments:
            if attachment.parent_transform:
                t = Transform(self.__pos, self.heading)

                attachment_pos = t.apply(attachment.offset)
                attachment.game_object.position = attachment_pos
                attachment.game_object.set_heading(self.heading)
Example #3
0
 def apply(self, fn):
   if all(isinstance(t, ScalarT) for t in fn.type_env.itervalues()):
     return fn
   else:
     return Transform.apply(self, fn)
Example #4
0
 def apply(self, fn):
   if contains_calls(fn):
     return Transform.apply(self, fn)
   else:
     return fn
Example #5
0
 def apply(self, fn):
     if all(isinstance(t, ScalarT) for t in fn.type_env.itervalues()):
         return fn
     else:
         return Transform.apply(self, fn)
Example #6
0
 def apply(self, fn):
     if contains_calls(fn):
         return Transform.apply(self, fn)
     else:
         return fn