コード例 #1
0
ファイル: polygon.py プロジェクト: kujbol/graficzne
    def draw_texture(self, widget):
        clean_polygon_inside(self)

        max_x = max(point.x for point in self.points)
        max_y = max(point.y for point in self.points)
        min_x = min(point.x for point in self.points)
        min_y = min(point.y for point in self.points)

        im = Image.open('files/wall.png')
        im.load()

        if self.settings.bump_mapping:
            bump_map = Image.open('files/normal_wall.png')
            bump_map.load()
            bump_map = bump_map.resize((max_x - min_x, max_y - min_y))
        else:
            bump_map = None

        if self.settings.cut_colors:
            pallet = cut_pallet(im, self.settings.color_count)
            array = list(im.getdata())
            new_array = [
                closest_color_from_pallet(pallet, color)
                for color in array
            ]
            im = Image.new(im.mode, im.size)
            im.putdata(new_array)
        im = im.rotate(180)

        resided = im.resize((max_x - min_x, max_y - min_y))

        rgb_im = resided.convert('RGB')
        if self.settings.shadows:
            lights = [
                obj for obj in self.widget.object_set if isinstance(obj, Light)
            ]
            viewer = [
                obj for obj in self.widget.object_set
                if isinstance(obj, Viewer) and not isinstance(obj, Light)
            ]
            if len(viewer) == 1:
                re_draw_polygon_inside(
                    self, texture=rgb_im, min_x=min_x, min_y=min_y,
                    viewer=viewer[0], lights=lights, bump_map=bump_map
                )
        else:
            re_draw_polygon_inside(
                self, texture=rgb_im, min_x=min_x, min_y=min_y
            )
コード例 #2
0
ファイル: polygon.py プロジェクト: kujbol/graficzne
 def change_fill(self, widget):
     # TODO ugly again, jezus do something
     if self.settings.shadows:
         lights = [
             obj for obj in self.widget.object_set if isinstance(obj, Light)
         ]
         viewer = [
             obj for obj in self.widget.object_set
             if isinstance(obj, Viewer) and not isinstance(obj, Light)
         ]
         if len(viewer) == 1:
             re_draw_polygon_inside(
                 self, viewer=viewer[0], lights=lights
             )
     else:
         re_draw_polygon_inside(self)