コード例 #1
0
class ImagePainter():
    #create the window and image then display the image
    def __init__(self, size):
        self.window = Tk()
        self.size = size
        self.img = PhotoImage(width=size, height=size)
    def display(self,gradient, name, type):
        canvas = Canvas(self.window, width=self.size, height=self.size, bg=gradient[0])
        canvas.pack()
        canvas.create_image(((self.size / 2), (self.size/ 2)), image=self.img, state="normal")
        self.img.write(name + type)
        mainloop()
コード例 #2
0
ファイル: ArrayPainter.py プロジェクト: MHogan17/LeafModel
def paint_array(array, time):
    window = Tk()
    photo = PhotoImage(width=len(array), height=len(array))
    canvas = Canvas(window, width=len(array), height=len(array), bg='#ffffff')
    canvas.create_image((len(array) / 2, len(array) / 2),
                        image=photo,
                        state='normal')
    canvas.pack()

    for i in range(len(array)):
        for j in range(len(array[i])):
            color = array.find_color(i, j)
            photo.put(color, (i, j))

    window.update()
    photo.write('data/Minute ' + time + '.png', 'png')
    print(time)
    window.destroy()
    return
コード例 #3
0
class Image:
    def __init__(self, xres, yres):
        self.xres = xres
        self.yres = yres

        self.img_buf = []
        for y in range(yres):
            Row = []
            for x in range(xres):
                Row.append("#000000")
            self.img_buf.append(Row)

        self.window = Tk()

        self.canvas = Canvas(self.window,
                             width=xres,
                             height=yres,
                             bg="#000000")
        self.canvas.pack()

        self.tk_img = PhotoImage(width=xres, height=yres)

        self.canvas.create_image((xres / 2, yres / 2),
                                 image=self.tk_img,
                                 state="normal")

    def Write(self, filename):
        self.tk_img.write(filename)

    def Display(self):
        display_str = ""
        for y in reversed(range(self.yres)):
            display_str += "{" + " ".join(self.img_buf[y]) + "} "

        self.tk_img.put(display_str, (0, 0))

    def SetPixel(self, x, y, c):
        color = "#%02x%02x%02x" % (int(
            Saturate(c[0]) * 255.0), int(
                Saturate(c[1]) * 255.0), int(Saturate(c[2]) * 255.0))

        self.img_buf[int(y)][int(x)] = color
コード例 #4
0
def paint(fractal, imagename='branches.png'):
    """Paint a Fractal image into the TKinter PhotoImage canvas.
    This code creates an image which is 512x512 pixels in size."""
    SIZE = fractal.config['pixels']
    SIZE = int(SIZE)

    GradScheme = GradientFactory.makeGradient(fractal)

    # Figure out how the boundaries of the PhotoImage relate to coordinates on
    # the imaginary plane.
    minx = fractal.config['centerx'] - (fractal.config['axislength'] / 2.0)
    maxx = fractal.config['centerx'] + (fractal.config['axislength'] / 2.0)
    miny = fractal.config['centery'] - (fractal.config['axislength'] / 2.0)

    # Display the image on the screen
    window = Tk()
    img = PhotoImage(width=SIZE, height=SIZE)
    canvas = Canvas(window, width=SIZE, height=SIZE, bg=GradScheme.getColor(0))
    canvas.pack()
    canvas.create_image((SIZE / 2, SIZE / 2), image=img, state="normal")

    # At this scale, how much length and height on the imaginary plane does one
    # pixel take?
    pixelsize = abs(maxx - minx) / SIZE

    for row in range(SIZE, 0, -1):
        for col in range(SIZE):
            x = minx + col * pixelsize
            y = miny + row * pixelsize

            i = fractal.count(complex(x, y))

            color = GradScheme.getColor(i)
            img.put(color, (col, SIZE - row))
        window.update()  # display a row of pixels

    # Output the Fractal into a .png image
    img.write(imagename + ".png")
    print("Wrote picture " + imagename + ".png")

    # Call tkinter.mainloop so the GUI remains open
    mainloop()
コード例 #5
0
	def display(self):
		window = Tk()
		pixel_size = abs(self.max[0] - self.min[0]) / self.fractal.pixels
		photo = PhotoImage(self.fractal.name, width=self.fractal.pixels, height=self.fractal.pixels)
		canvas = Canvas(window, width=self.fractal.pixels, height=self.fractal.pixels, bg=self.gradient.getColor(0))
		canvas.pack()
		canvas.create_image((self.fractal.pixels / 2, self.fractal.pixels / 2), image=photo, state="normal")
	
		for row in range(self.fractal.pixels, 0, -1):
			for column in range(self.fractal.pixels):
				x = self.min[0] + (column * pixel_size)
				y = self.min[1] + (row * pixel_size)
				color = self.gradient.getColor(self.fractal.count(complex(x,y)))
				photo.put(color, (column, self.fractal.pixels - row))

			window.update()  # display a row of pixels
		photo.write(f"{photo}.png")
		print(f"Wrote image {photo}.png")

		mainloop()
コード例 #6
0
    def displayImage(self, config, grad):
        window = Tk()
        img = PhotoImage(width=config.pixels, height=config.pixels)
        gradient = GradientFactory.makeGradient(grad, config)
        self.paint(config, img, gradient)

        # Display the image on the screen
        canvas = Canvas(window,
                        width=config.pixels,
                        height=config.pixels,
                        bg=Color.Color(255, 225, 225))
        canvas.pack()
        canvas.create_image((config.pixels / 2, config.pixels / 2),
                            image=img,
                            state="normal")

        # Save the image as a PNG
        img.write(config.name + ".png")
        print(f"Wrote image {config.name}.png")
        mainloop()
コード例 #7
0
def MapPicture(pixel_frequency, raster=(1000, 1000)):
    root = Tk()
    img = PhotoImage(width=raster[0], height=raster[1])

    for i in range(1, raster[0]):
        x = i
        for j in range(1, raster[0]):
            y = j
            img.put('#000000', (x, y))

    pixel_values = []
    for item in pixel_frequency.values():
        pixel_values.append(item)
    freqstats = np.percentile(pixel_values, [25, 50, 75])

    for coordinate in pixel_frequency:
        color = GetColor(pixel_frequency[coordinate], freqstats)
        img.put(color, coordinate)

    filename = 'heat.png'
    img.write(filename, format='png')
コード例 #8
0
    if len(sys.argv) < 2:
        print("Please provide the name of a fractal as an argument")
        for i in juliaConfigDict:
            print(f"\t{i}")
        sys.exit(1)

    elif sys.argv[1] not in juliaConfigDict:
        print(f"ERROR: {sys.argv[1]} is not a valid fractal")
        print("Please choose one of the following:")
        for i in juliaConfigDict:
            print(f"\t{i}")
        sys.exit(1)

    else:
        i = getFractalConfigurationDataFromFractalRepositoryDictionary(
            juliaConfigDict, sys.argv[1])

    # Set up the GUI so that we can display the fractal image on the screen
    win = Tk()

    photo = PhotoImage(width=512, height=512)
    makePicture(juliaConfigDict[i])

    # Output the Fractal into a .png image
    photo.write(i + ".png")
    print("Wrote picture " + i + ".png")
    photo.write(i + ".png")

    # Call tkinter.mainloop so the GUI remains open
    mainloop()
コード例 #9
0
class Image(object):

    def __init__(self, name):
        filepath = "images" + os.sep + name + ".gif"
        self.image = PhotoImage(file = filepath)
        self.copy  = PhotoImage(file = filepath)

    def applyImageFilter(self, newFilename, filterFunction):
        image = self.image # Go through each pixel in the original
        for row in range(image.height()):
            for col in range(image.width()):
                (red, green, blue) = self.getRGB(col, row) # getRGB takes x and then y

                (newRed, newGreen, newBlue) = filterFunction(col, row, red, green, blue)

                self.setRGB(col, row, newRed, newGreen, newBlue)

        self.saveCopyToFolder(newFilename)

    def saveCopyToFolder(self, newFilename):
        filename = "output" + os.sep + newFilename + ".gif"
        self.copy.write(filename, format="gif")


    def getRGB(self, x, y):
        image = self.image
        value = image.get(x, y)
        return value

    def setRGB(self, x, y, red, green, blue):
        image = self.copy
        color = hexColor(red, green, blue)
        image.put(color, to=(x,y))

    def greyScaleFilter(self, x, y, red, green, blue):
        grey = ( red + green + blue ) // 3
        return (grey, grey, grey)

    def sephiaFilter(self, x, y, red, green, blue):
        sred = 236
        sgreen = 207
        sblue = 113
        newRed = (2*sred + red) // 3
        newGreen = (2*sgreen + green) // 3
        newBlue = (2*sblue + blue) // 3
        return (newRed, newGreen, newBlue)

    def invertFilter(self, x, y, red, green, blue):
        return (255-red, 255-green, 255-blue)

    def sephia(self, newFilename):
        print("Applying sephia filter...")
        self.applyImageFilter(newFilename, self.sephiaFilter)
        print("Finished!")

    def greyScale(self, newFilename):
        print("Applying grey scale filter...")
        self.applyImageFilter(newFilename, self.greyScaleFilter)
        print("Finished!")

    def invert(self, newFilename):
        print("Applying invert filter...")
        self.applyImageFilter(newFilename, self.invertFilter)
        print("Finished!")
コード例 #10
0
if __name__ == '__main__':
    if len(sys.argv) < 2:
        print("Please provide the name of a fractal as an argument")
        for i in images:
            print(f"\t{i}")
        sys.exit(1)

    elif sys.argv[1] not in images:
        print(f"ERROR: {sys.argv[1]} is not a valid fractal")
        print("Please choose one of the following:")
        for i in images:
            print(f"\t{i}")
        sys.exit(1)

    else:
        image = sys.argv[1]


    # Set up the GUI so that we can paint the fractal image on the screen
    window = Tk()
    img = PhotoImage(width=512, height=512)
    paint(images, image)

    # Save the image as a PNG
    img.write(f"{image}.png")
    print(f"Wrote image {image}.png")

    # Call tkinter.mainloop so the GUI remains open
    mainloop()