def setBasicPixel(self, x, y, rgb): """Sets the pixel at specified coordinates to a color based on rgb(tuple) Parameters ---------- x, y : int the coordinates of the pixel rgb : tuple of int the color the pixel will be set to """ col = Color(rgb[0], rgb[1], rgb[2]) self.getPixel(x, y).setColor(col)
def addMessage(self, message, xPos, yPos): """Adds text to the image message : str the message that will be drawn on the picture x : int the x-coordinate of the top left corner of the text y : int the y-coordinate of the top left corner of the text """ # get a graphics context to use to draw on the buffered image col = Color(0, 0, 0) self.addText(col, xPos, yPos, message)
def __init__(self, *args, **kwargs): """Initializer for Picture class """ self.filename = self.title = 'None' if len(args) == 0: # no parameters, make 100x200 picture with white background self.image = PIL.Image.new("RGB", (200, 100), (255, 255, 255)) elif len(args) == 1: if isinstance(args[0], str): self.filename = self.title = args[0] # Assume 'we've been passed a filename if not os.path.isfile(self.filename): # File not found, try prepending media path filepath = FileChooser.getMediaPath(self.filename) if os.path.isfile(filepath): self.filename = self.title = filepath try: self.image = PIL.Image.open(self.filename) except: self.image = PIL.Image.new("RGB", (600, 200)) draw = PIL.ImageDraw.Draw(self.image) draw.text((0, 100), "Couldn't load " + self.filename) elif isinstance(args[0], Picture): # We've been passed a Picture object self.image = args[0].image.copy() self.filename = args[0].filename self.title = args[0].title elif isinstance(args[0], PIL.Image.Image): # We've been passed a PIL image object self.image = args[0] try: self.filename = self.title = args[0].filename except AttributeError: pass elif len(args) == 2 or len(args) == 3: # We've been passed width and height, and possibly a color size = (int(args[0]), int(args[1])) c = Color(255, 255, 255) if len(args) == 2 else args[2] self.image = PIL.Image.new("RGB", size, c.color) else: print("Could not construct Picture object")
def makeColor(red, green=None, blue=None): return Color(red, green, blue)
def makeBrighter(color): # This is the same as makeLighter(color) if not isinstance(color, Color): print("makeBrighter(color): Input is not a color") raise ValueError return Color(color.makeLighter())
def makeLighter(color): if not isinstance(color, Color): print("makeLighter(color): Input is not a color") raise ValueError return Color(color.makeLighter())
def getColor(pixel): if not isinstance(pixel, Pixel): print("getColor(pixel): Input is not a pixel") raise ValueError return Color(pixel.getColor())
def pickAColor(): # Dorn 5/8/2009: Edited to be thread safe since this code is executed from an # interpreter JESThread and will result in an update to the main JES GUI due to # it being a modal dialog. return Color.pickAColor()
Pixel.setWrapLevels(bool(setting)) def getColorWrapAround(): return Pixel.getWrapLevels() def pickAColor(): # Dorn 5/8/2009: Edited to be thread safe since this code is executed from an # interpreter JESThread and will result in an update to the main JES GUI due to # it being a modal dialog. return Color.pickAColor() # Constants black = Color(0, 0, 0) white = Color(255, 255, 255) blue = Color(0, 0, 255) red = Color(255, 0, 0) green = Color(0, 255, 0) gray = Color(128, 128, 128) darkGray = Color(64, 64, 64) lightGray = Color(192, 192, 192) yellow = Color(255, 255, 0) orange = Color(255, 200, 0) pink = Color(255, 175, 175) magenta = Color(255, 0, 255) cyan = Color(0, 255, 255) ## # Global picture functions