Week 3 - PowerPoint PPT Presentation

About This Presentation
Title:

Week 3

Description:

Let's make up our own 'picture' from scratch! OMED. Where? (xpos, ypos) OMED. Last Week ... Your single function should make all of this happen--all of the ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 28
Provided by: BillL161
Category:
Tags: week

less

Transcript and Presenter's Notes

Title: Week 3


1
Week 3
2
Translating
  • Can we put a picture wherever we want it?

3
Another Useful Tool
  • makeEmptyPicture(width, height)
  • Can you guess what it does?
  • Can you guess what it returns?

4
Idea
  • Let's make up our own "picture" from scratch!

5
Where?
(xpos, ypos)
6
Last Week
  • def drawSquare(posx, posy, picture, redVal)
  • for x in range(1, 151)
  • for y in range(1, 151)
  • xdraw x posx
  • ydraw y posy
  • b x 1.7
  • g y 1.7
  • px getPixel(picture, xdraw, ydraw)
  • setColor(px, makeColor(redVal, g, b))

7
Testing It
  • blank makeEmptyPicture(750, 750)
  • drawSquare(130, 45, blank, 0)
  • drawSquare(400,400, blank, 255)
  • show(blank)

8
Today
750
750
9
The "Main" Program
  • def matrix()
  • pic makeEmptyPicture(750, 750)
  • r 0.0
  • for y in range(1, 602, 150)
  • for x in range(1, 602, 150)
  • square(pic, x, y, int(r))
  • r r 10.625
  • printNow(r)
  • return pic

10
Note!
  • The "main" program returns a picture.
  • This is useful.
  • It could be hard-coded to save the final picture
    as a file
  • As a general rule you want functions to be a
    general purpose and as reusable as possible
  • You can always "wrap" a function in another
    function to fulfill a specific purpose

11
All the Colors (Almost)
12
Scaling
  • Can we make pictures bigger or smaller?
  • Can we stretch them?

13
Scaling
  • Want a function that will take in a picture and a
    "scale factor" as parameters and will return a
    new picture scaled by "scale factor"
  • Example
  • halfsize scale(picture, 0.5)
  • doublesize scale(picture, 2.0)
  • What are halfsize and doublesize?

14
Scaling!
oldx
newx oldx scalefactor
newx
15
Recipe
  • Take in picture and scale factor
  • Determine size of new picture
  • Make a new picture (empty)
  • Go through each pixel of new picture (hint 2
    fors)
  • Determine pixel in old picture that corresponds
    to new picture and copy color over

16
Scaling!
oldx
newx oldx scalefactor
newx
17
Combining Pictures
  • Blending

18
  • def blend(pic1, pic2)
  • width getWidth(pic1)
  • height getHeight(pic2)
  • pic3 makeEmptyPicture(width, height)
  • for x in range(1, width1)
  • factor x1.0/width
  • other 1.0 - factor
  • other x 1.0/width
  • factor 1.0 - other
  • for y in range(1, height1)
  • r1 getRed(getPixel(pic1, x, y))
  • r2 getRed(getPixel(pic2, x, y))
  • newr factorr1 otherr2
  • g1 getGreen(getPixel(pic1, x, y))
  • g2 getGreen(getPixel(pic2, x, y))
  • newg factorg1 otherg2
  • b1 getBlue(getPixel(pic1, x, y))
  • b2 getBlue(getPixel(pic2, x, y))
  • newb factorb1 otherb2

19
Combining Pictures
  • Background Subtraction

-

20
Combining Pictures
  • Chromakey

21
Combining Pictures
22
Homework 3
  • Write a function named hw3 in a file named hw3.py
    to create a collage of the same image at least
    four times fit onto the 7x95in blank JPEG. This
    image "7inX95in.jpg" is in the media sources
    folder. (You are welcome to add additional
    images, too.) One of those four copies can be the
    original picture. The other three should be
    modified forms. You can do any of
  • Scaling, cropping, or rotating the image,
    shifting or altering colors on the image, and
    making it darker or lighter.

23
Homework 3
  • Each of your four images should be in different
    quadrants of the picture. One should be in the
    upper left, the next in the lower left, the next
    in the upper right, and the fourth in the lower
    right. You may use as many other images as you
    with, in any other places, but those four images
    in four different quadrants must be there.

24
Homework 3
  • Your single function should make all of this
    happen--all of the effects and compositing must
    occur from the single function hw2(). IT IS
    PERFECTLY OKAY FOR HW2() TO USE OTHER FUNCTIONS!
    When grading we will only setMediaPath() to the
    directory containing your image (or
  • images) and then execute hw2()--and will expect
    to see a collage get generated.
  • In other words hw2() must not take any arguments!

25
Homework 3
  • Turn in your code, your original image (or
    images), and your resultant image into WebWork as
    hw3
  • Note this means that you must run your code and
    generate the final image and save it to a file to
    be turned in!

26
Hints
  • Test your code before turning it in!
  • Do not make changes after testing!
  • Make sure you turn in all files required
  • Read, understand and follow the instructions!
  • NOTE Your submissions will be displayed at the
    OMED Banquet for everyone to see!

27
Sound
  • pickAFile()
  • makePicture(file)
  • getPixels(picture)
  • getPixel(picture, x, y)
  • getRed(pixel)
  • getWidth(pic)
  • writePictureTo(pic, file)
  • setRed(pixel, value)
  • pickAFile()
  • makeSound(file)
  • getSamples(sound)
  • getSampleObjectAt(sound,1)
  • getSampleValueAt(sound, index
  • getLength
  • getSamplingRate
  • writeSoundTo(sound,file.wav)
  • setSample(sample,value)
  • getSample(sample)
Write a Comment
User Comments (0)
About PowerShow.com