This project was very different from my other projects. It did not really break down into simple parts, so my 5th grade essay-writing skills are now failing me. Furthermore, there are very few snippets of code that I can use to summarize my main function and its children functions. Instead, I will describe the operations, their basic foundations, and let you look through the exhaustively commented 500-line code for specifics.
In the command line, you have a lot of options, but they all begin with: warhol.py. From there you have the choice of three things: 'help' - a description of all of the possible command line prompts, the name of an image that you'd like to edit, or 'warhol' - an indicator not proceed with the normal main function but to make a collage image instead. Help is self explanatory. I will begin my explanation with the name of an image.
After typing in the name of an image (I strongly suggest my image, mypic.ppm, for insignificant reasons addressed in the code), you again have many options. You must enter the initial horizontal position of the new image, the initial vertical position of the new image, and the name of the new image that you will create (as seen left). If you fail follow the right operations, then you will receive a specialized syntax error (as seen right). There are not a lot of ways to receive python errors (I'm not challenging you) - the entire program is documented with print statements that let you know what the process is doing. Although some functions take time, the program keeps you updated.
You can stop entering things here. If you do, you're picture is drawn with a menu, as seen below (after brightenarea was used three time). The menu is just a .gif turned into an object and superimposed over the image. It will not be save on top of your picture. Mouse clicks within its y-range trigger the program
to recognize that you are in the menu, at which point it checks its x position to see which icon's function it is aligned with. From left to right:
Italian Flagish: Prompts the user for an order of colors, i.e 'rgb', 'gbr', 'bbb', 'brg'. It then replaces the 'red, green, blue' values of the original image with your new preferences. For example, if the user enters (using raw_input) 'gbr', then red values are replaced with green ones, green with blue, an blue with red. Note that this will undo (not purposefully) any other unsaved changes to the image. (11)
Smiley Sun: 'brightens' the entire image. It raises, if possible, all red, green, and blue values in each pixel by a fixed amount, making them appear brighter. (41)
Smiley Moon:'darkens' the entire image. It lowers, if possible, all red, green, and blue values in each pixel by a fixed amount, making them appear darker. Each Smiley function executes once per click. (55)
Gray-->White: waits for a mouse click, then 'brightens' the area clicked on by a fixed amount by raising the rgb values of the pixel clicked on and all the pixels within a certain radius of it. (Seen used three times at one spot in picture). This is an example of a popular tool in my coding, the getMouse() function. When set to a variable, variable.x and variable.y became very valuable resources in image manipulation. (69)
White-->Gray: waits for a mouse click, the 'darkens' the area click on by a fixed amount by lowering the rgb values of the pixel clicked on and all the pixels within a certain radius of it. For both -options, the program allows you to continue brightening or darkening until you re-click on the menu. (83)
X of doom: thank the user graciously, waits for a final mouse click, and exits the program deleting any unsaved data. This is the preferred method of ending the program (without getting a nasty error message).
Save bar: this saves your file under the filename provided in the command bar. It can be used as many times as desired, but does not prompt a new filename each time or ask to overwrite data.
Pencil Writing Poetry: prompts the user for a color in (1:255,1:255,1:255) format. When the user has provided a color, any mouse click on the image produces a dot several pixels thick of that color, like a pen-mark. The user may draw as much as they want, any click on the menu exiting the drawing-mode. Re-clicking on draw allows the user to pick a new color and continue drawing. (118) (See below)
All other functions must be called from the command line. These include invert featured in the collage which gives the 'x-ray' apperance. From help, we see that all functions can be called from the command line, usually at argv. arg is reserved for changing 'rgb' colors (if you want to keep them the same but execute a proceeding function, set them to 'rgb' - change them back to themselves). If trying to call functions without the menu, some processes execute slightly differently. Functions that require a click on the menu to stop, like drawing and brightaround, darkaround, need different triggers. The drawing function asks for an arg that tells the user how many dots to draw in between color prompts. Brightaround and darkaround make use of the time package to recognize and exit from a double-click. Brightening/darkening the whole image or inverting the image's colors are examples of functions that are not effected by using the command line.
The green screen is another function not found in the menu. The screen will simply identify high levels of blue and replace them with another set color. It is uncreative and unfun. (108)
We have so far avoided what happens if arg is warhol. (402) The warhol function draws separate pixmaps for four different executions of main, disabling the menu. It calls the (r,g,b) of each pixel of those images and places them in a larger canvas using getpixel, being cautious not to overlap images. (Note: I used a shrunken version of my image for my collage only for the purposes of fitting the collage on the screen, not due to coding restrictions). This process takes some time, but is very flexible. By my coding, the command line variable is edited in the warhol execution, so the input must be changed from the file, not the command line. This places only minor limitations on the user, and is made up for greatly by the benefit of being allowed to manipulate the command line directly throughout the coding.
This time around, I learned that, sometimes, a far greater resource than the online summaries of packages is just opening the packages and looking at them. I learned that it can be dangerous to mess with the command line variables if you aren't careful (I like to think that I generally was). I often found that raw_input was a good replacement for command line information. It doesn't always make sense that a user will know what they want when executing the code, before, for example, they see the actual image. Most importantly, I learned a about classes. I found my greatest difficulty here was navigating the difference between an Image and a Pixmap. My most familial Python error was something like Pixmap.draw(win) doesn't mean anything so stop trying it over and over. It was a relatively long time into the project before I found myself navigating without great hazard between the two. I'm sure that excess, redundant class changes are littered throughout my code.