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. 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. 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. Once open, right-click the "MyWorld" rectangle and delete it. Name your scenario Lab23 or whatever you like. Run Greenfoot and then select "Scenario > New Java Scenario." 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 Write Code for each xylophone bar that sets the variables and calls the Method to play sound and change image.James Madison University, Spring 2018 Semester Write Code for "Bar" that defines a Method to change the image when Bar is clicked or Key is pressed.ĥ. Write Code for "Bar" that defines a Method to play the sound on mouse click and Key event.Ĥ. Write Code for "Bar" class that defines 4 variables that control pitch, image, image pressed, and key event.ģ. Download and unzip "XylophoneProjectBase" file and Save to your file area.Ģ. Paddle 2 must move by itself while tracking the Ball.ġ. The Paddle must move up and down with the User controlling the mouse.ĥ. Ball must move by itself and bounce off the walls and the Paddles.Ĥ. Create a Greenfoot world with a 500x400 grid with size of 1 px.ģ. When Ball reaches the edge of the Screen, the Ball must move back to the Shooter.ġ. If Ball touches the Target - the Target must disappear.ĥ. Ball must start at the shooter and move when "Space" key is pressed.Ĥ. Create a Greenfoot world with a 400x400 grid with size of 1 px.ģ. Write a method that allows the user to use the arrow keys to move the Actor around the world.ġ. Create a Greenfoot Actor and place in the center of the worldģ. More information on Greenfoot can be found at: Basic MoverĢ. Many programs we can create in Scratch we can also create in Greenfoot. Greenfoot is a Java based Integrated Development Environment (IDE) for developing two-dimensional animation and games while learning the Java language.
0 Comments
Leave a Reply. |