# Pages CS 151 Computational Thinking Fall 2012 cs151s10proj4 (Philip Prosapio) Page History

## Key

• This line was removed.
• Formatting was changed.
Comment: Migrated to Confluence 4.0

Philip Prosapio
Spring 2010

Note- The code for this project is in the academic server under the user name pwprosap.

Summary
The overall idea of this lab was to learn the basics of manipulating pixmaps. We needed to make multiple functions that manipulated the colors and other parts of pixmaps and then manipulate a picture. We were tasked to combine these skills to make a collage of four of the same pictures that were manipulated in different ways. Then the final task was to take the blue screen photos of ourselves and manipulate the background color.

Description of my solutions to the tasks
1) The first task asked me to make a putPixmap() function. This function would receive a source pixmap and a destination and then well allocate an x and y destination for the newly formed pixmap. The key lines of code for this all important function are:

(r, g, b) = (source.getPixel(i, j))
destination.setPixel(x+i, y+j, (r, g, b))

These lines will first assign the red, green and blue values for each pixel and then assign a destination to place these colors.

2) The next task was to create three more functions like the swapRedBlue() function that we created in lab for this project. For this part I created a the functions: everythinblue(), swapRedGreen(), negatePixmap(), and tintWhitePixmap(). The first substitutes the blue value into every color slot, the second switch the red and green values, the third creates a negative of the picture, and the final function bathes the picture in white. One of the key concepts you can see by looking a some of the code is the idea of alpha blending.

(r,g,b) = pxmap.getPixel(x,y)
pxmap.setPixel(x,y,
(int(r*alpha+r1*(1-alpha)),
int(g*alpha+g1*(1-alpha)),
int(b*alpha+b1*(1-alpha))))

3) The third task was to use these four functions to make four separate pictures and then to place those photos into a collage. To do this I needed first to make a large pixmap window to place them in to.

big = graphics.Pixmap(2*pxmap.getWidth(), 2*pxmap.getHeight())

By assigning this code to the variable big, I was able to make a larger back drop for which I could place my four manipulated pixmaps. This picture can be seen and is attached and named picture1lab4.png .

4) The fourth and final task was to mess around with the blue screen in the pictures of ourselves. I was to change the blue screen to some other color, but only the blue screen and not myself. I accomplished this by using a pretty specific if statement:

if b >= 2*r and b > g:
pxmap.setPixel(j, i, (255, 8.11, 146.88))

So this made it that if the blue value was twice as big as the red value and bigger then the green value then that pixel would be changed to the newly selected color, which just happened to be pink. This picture is attached and named picture2lab4.png .

Extensions
For this lab I completed two extensions.

Extension 1- My first extension fulfilled the extension that required us to create more effects and a bigger Warhol style collage. I made a three by three collage with newly added effects. Some of those being: stripeItPink() and halfNegatePixmap(). Which in this extension I believe that the coolest effect is from the halfNegatePixmap() function, turning the photo into a cool yellow light. This picture can be viewed and is attached with the name of picture3lab4.png .

Extension 2- My second extension fulfills the extension that asks us to do something more interesting with the blue screen in our picture. For this extension I added in the random module to spice things up:

if b >= 2*r and b > g:
if random.random() < 0.6:
pxmap.setPixel(j, i, (177.99, 82.875, 220.065))
else:
pxmap.setPixel(j, i, (235.11, 233.07, 105.06))
else:
pxmap.setPixel(j, i, (r, g, b))

This way, depending on what value the random module spit out, that would decide what color the pixel would be turned, either purple or yellow. (I am still a Minnesota Vikings fan at heart) This picture is attached and named picture4lab4.png .

Finally, what I learned
In this lab I got a good introduction to the concepts of Pixmaps. I also got a little better understanding of if statements during this lab.

Attached Pictures

picture1lab4.png

picture2lab4.png

picture3lab4.png

picture4lab4.png