Results 1 to 2 of 2
  1. #1
    switch09 is offline Member
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Default 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);
    }
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Where is your data that represents p1, p2 and p3? Where you change your colour values, you'll want to have a for loop that loops on k from 1 to 3, calculates a pixel with the appropriate colors and sets the pixel into the appropriate p1 or p2 or p3 image.

Similar Threads

  1. confused
    By updev in forum AWT / Swing
    Replies: 6
    Last Post: 11-14-2008, 04:33 PM
  2. a lot confused
    By vineethraj in forum New To Java
    Replies: 4
    Last Post: 01-18-2008, 01:36 AM
  3. what does it mean:confused:
    By sivasayanth in forum New To Java
    Replies: 2
    Last Post: 01-12-2008, 05:52 AM
  4. bit confused on this question
    By money123 in forum New To Java
    Replies: 2
    Last Post: 07-27-2007, 01:14 PM
  5. confused code
    By creativehacker in forum New To Java
    Replies: 6
    Last Post: 07-02-2007, 09:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •