示例#1
0
    def __init__(self, world):
        self.bg_color = "#FFFFFF"
        self.color = "#00000"
        self.xmin, self.xmax, self.ymin, self.ymax = world
        self.width  = self.xmax - self.xmin
        self.height = self.ymax - self.ymin

        self.colormap = ColorMap(self.bg_color)
        self.pixmap = PixMap(world, self.colormap)
示例#2
0
class Canvas(object):
    def __init__(self, world, resolution):
        self.bg_color = "#FFFFFF"
        self.color = "#00000"

        self.colormap = ColorMap(self.bg_color)
        self.pixmap = PixMap(world, resolution, self.colormap)

    def as_pixmap(self):
        return self.pixmap.as_pixmap()

    def set_color(self, color):
        self.color = color

    def convert_to_viewport(self, point):
        x, y = int(round(point.x)), int(round(point.y))
        return x, y

    def draw_pixel(self, point):
        x, y = self.convert_to_viewport(point)
        self.pixmap.set_pixel(x, y, self.color)

    def draw_line(self, line):
        points = Rasterizer.rasterize_line(line)
        for point in points:
            self.draw_pixel(point)

    def draw_polygon(self, polygon):
        for line in polygon.lines:
            self.draw_line(line)

    def fill_polygon(self, polygon):
        filler = PolygonFiller(self)
        filler.fill(polygon)

    def draw(self, primitive):
        name = primitive.name()
        fn = getattr(self, 'draw_' + name)
        fn(primitive)

    def fill(self, primitive):
        name = primitive.name()
        fn = getattr(self, 'fill_' + name)
        fn(primitive)
示例#3
0
class Canvas(object):
    def __init__(self, world):
        self.bg_color = "#FFFFFF"
        self.color = "#00000"
        self.xmin, self.xmax, self.ymin, self.ymax = world
        self.width  = self.xmax - self.xmin
        self.height = self.ymax - self.ymin

        self.colormap = ColorMap(self.bg_color)
        self.pixmap = PixMap(world, self.colormap)

    def as_pixmap(self):
        return self.pixmap.as_pixmap()

    def set_color(self, color):
        self.color = color

    def convert_to_screen(self, point):
        # Postscript makes 0,0 the bottom left // XPM makes 0,0 the top left
        x, y = int(round(point.x)), int(round(point.y))
        return x, y

    def draw_pixel(self, point):
        x, y = self.convert_to_screen(point)
        self.pixmap.set_pixel(x, y, self.color)

    def draw_line(self, line):
        points = Rasterizer.rasterize_line(line)
        for point in points:
            self.draw_pixel(point)

    def draw_polygon(self, polygon):
        for line in polygon.lines:
            self.draw_line(line)

    def draw(self, primitive):
        name = primitive.name()
        fn = getattr(self, 'draw_' + name)
        fn(primitive)
示例#4
0
    def __init__(self, world, resolution):
        self.bg_color = "#FFFFFF"
        self.color = "#00000"

        self.colormap = ColorMap(self.bg_color)
        self.pixmap = PixMap(world, resolution, self.colormap)