Results 1 to 2 of 2
- 11-17-2008, 09:00 PM #1Member
- Join Date
- Nov 2008
- Rep Power
I am sooo confused... Please help!
So as a last ditch attempt to try to complete my Java assignment, I turn to you guys...
The directions are:
"Part A: First, we will look at one approach to creating a sequence of morphed pictures. Consider the sequence of pictures startingPicture, p1, p2, p3, endingPicture. The intermediate pictures p1, p2, p3 are formed pixel by pixel. For each pixel of an intermediate picture we compute its red, green and blue value using the following formula for each colour:
colourValue = startValue + ( (endValue – startValue) / 4 ) * k
where k is the kth intermediate picture, i.e. k = 1, 2 or 3. Note the effect that this formula has: if, for example, the starting red value is 100 and the ending red value is 200, the intermediate red value is 125 when k is 1, 150 when k is 2, and 175 when k is 3. (Indeed, if we let k be 4 in the formula, note that the red value becomes the ending red value.)
If we had wanted 7 intermediate pictures instead of 3, then k would range from 1 to 7, and we would have divided by 8 in the formula, rather than by 4.
So, in general the formula for each colour becomes
colourValue = startValue + ( (endValue – startValue) / (numStages + 1) ) * k
where numStages is the total number of intermediate stages in the morphing.
For Part A of this assignment, you will write a method for the Picture class that forms an intermediate picture in the morphing sequence, as specified below. This method would be called once for each intermediate picture."
For Part A I wrote the following code but it doesn't do anything... I think I'm putting in the wrong value for the "endValue" but I'm not sure what's supposed to go there... If anyone can give me some insight, I would appreciate it... :confused:
* Method to morph a picture
public void morphStage(Picture startPicture, Picture endPicture, int numStages, int k)
Pixel pixelObj = null;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
//loop through the columns
for (int x = 0; x < this.getWidth(); x++)
//loop through the rows
for (int y = 0; y < this.getHeight(); y++)
//get the current pixel and its color values
pixelObj = this.getPixel(x,y);
redValue = pixelObj.getRed();
greenValue = pixelObj.getGreen();
blueValue = pixelObj.getBlue();
//change the colour values
pixelObj.setRed(redValue + ((255 - redValue) / (numStages + 1)) * k);
pixelObj.setGreen(greenValue + ((255 - greenValue) / (numStages + 1)) * k);
pixelObj.setBlue(blueValue + ((255 - blueValue) / (numStages + 1)) * k);
- By updev in forum AWT / SwingReplies: 6Last Post: 11-14-2008, 04:33 PM
- By vineethraj in forum New To JavaReplies: 4Last Post: 01-18-2008, 01:36 AM
- By sivasayanth in forum New To JavaReplies: 2Last Post: 01-12-2008, 05:52 AM
- By money123 in forum New To JavaReplies: 2Last Post: 07-27-2007, 01:14 PM
- By creativehacker in forum New To JavaReplies: 6Last Post: 07-02-2007, 09:10 PM