![]() If any of those color values is greater than 255, you should replace it with 255. In other words, you need to create a new Color(r2, g2, b2) for each pixel. Here is the formula for sepia transformation, given the original color's red, green, and blue values: * Replaces the bottom half of an image with a reflection of its top half. ![]() * Replaces the right half of an image with a reflection of its left half. * Applies a sepia transformation to all pixels. If you get stuck, try working through examples on paper.Īdd the following method stubs to your source file: Their solutions are simple, but they can be challenging to figure out. All four of today's methods are very similar in structure. Once you figure out how to do grayScale, you can implement all sorts of other features. Press the reset button (on the bottom) before trying other methods. A menu will appear with all the methods that you write today. To test your method, compile the project and then right-click the world image in the main Greenfoot window. Finally, store the new Color at the current x and y. Implement the following algorithm: for each x and y value in the range (0.width, 0.height), get the Color object at that x and y, calculate the average of its red, green, and blue values, and then create a new Color object using the average for all three of its RGB values. * Updates all pixels to the closest gray equivalent. You will need to use the getBlue, getGreen, and getRed methods.Īdd the following method stub below your constructor: Then skim through the Color Javadoc to become familiar with that class. In particular, you will need to use the following methods: getWidth, getHeight, getColorAt, and setColorAt.Īdd the line import to the top of your source file. Skim through the GreenfootImage Javadoc to become familiar with that class. Each object represents the red, green, and blue value of a single pixel. Images in Greenfoot are essentially 2D arrays of Color objects. After you complete the exercises below, you will submit the Image.java file via Canvas. Write your name, today's date, and a short description of this lab in the Javadoc comment of the Image class. Then press "Compile" in the main Greenfoot window. Open the editor for Image.java (by double clicking on the Image rectangle on the right) and modify the constructor to use the dimensions 640x426 (the actual size of football.jpg). ![]() Then in Greenfoot, right-click the "World" rectangle on the right and select "New subclass." Name the subclass Image and select football.jpg (it should be listed below). Right-click the football stadium photo above, and save it to the "images" folder in your Greenfoot project. (When you start the program, it opens whatever project you were working on previously.) You may want to close any Greenfoot windows from last time. Name your scenario Lab16 or whatever you like. Run Greenfoot and then select "Scenario > New." from the menu. In the previous Greenfoot lab, we dealt with Actor objects. In today's lab, you will use Greenfoot to implement several features of programs like Photoshop. Media Computation is an approach to learning programming that focuses on manipulating digital media like images and sounds. Image courtesy of JMU Creative Services Background James Madison University, Fall 2016 Semester
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |