1 / 33

Computer Science 101

Computer Science 101. Introduction to Programming with Pictures. setMediaPath. Invoking this function allows the user to choose a folder that will be the “default” location where searches for media files will start. This just makes it easier to pick files, etc. JES Picture Layout.

Télécharger la présentation

Computer Science 101

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science 101 Introduction to Programming with Pictures

  2. setMediaPath • Invoking this function allows the user to choose a folder that will be the “default” location where searches for media files will start. This just makes it easier to pick files, etc.

  3. JES Picture Layout • With JES, pictures are laid out in an x,y coordinate system starting in upper left corner, with x increasing to the right and y increasing downward.

  4. Working with Pixels – get values • getPixel(picture,x,y) – obtains the pixel at the given coordinates in the given picture. • getColor(pixel) – obtains the color object of the pixel. • getRed(pixel) – obtains the red value of the pixel, etc. • getX(pixel) – obtains the X coordinate of the pixel, etc.

  5. Working with Pixels – changing values • setColor(pixel, color) – changes the pixel’s color to be the given color. • setRed(pixel, redAmt) – changes the pixel’s red value to the given amount, etc. • pickAColor() – lets the user choose a color with slide bars, etc.

  6. ZOOM

  7. List of Pixels Note that the pixel in position (x,y) has list index equal to width * y + xFor example, the pixel at (3,2) has index 2*4 + 3 • getPixels(myPicture) - returns a list of all the pixels from the picture. • The pixels will be in the list in row order – first row followed by second row, etc.

  8. Changing Individual Pixels • Get the pixel into a variable:myPixel = getPixel(myPicture,10,6) • If the change does not depend on current values in the pixel, make change:setRed(myPixel, 128) • If change depends on current values, get the needed values first:myRed = getRed(myPixel)setRed(myPixel, myRed * 0.5)

  9. Processing all the Pixels • The general strategy is to use a for-loop on the list of pixels:thePixels = getPixels(thePicture) for aPixel in thePixels : <process aPixel>orfor aPixel in getPixels(thePicture) : <process aPixel>

  10. Choosing Pixels to Process • Sometimes we decide which pixels to process or which process to apply depending on conditions on the pixelsthePixels = getPixels(thePicture) for aPixel in thePixels: if <condition about aPixel> <process aPixel>

  11. Working with Pixels within a Region • Often we can restrict our processing to pixels within some rectangular region of the picture. This can be much, much more efficient than iterating over all of the multitude of pixels. for x in range(a,b) : for y in range(c,d) : <process pixel at x,y>

  12. Parameter for Color

  13. Add Parameters for Width, Height, and Starting Point

  14. Negative

  15. Lighten

  16. GrayScale

  17. Sepia Tint

  18. Rotate 90

  19. Copy Rectangle

  20. Edge Detection

  21. Blend

  22. Frame

More Related