Jump to content

Basic Code for morphing

- - - - -

  • Please log in to reply
1 reply to this topic

#1
AnthonyTTaylor

AnthonyTTaylor

    Newbie

  • Members
  • Pip
  • 1 posts
I need help making a basic java code that uses Nested loops and arrays to take two pics and morphs one into the other using a formula for the pixel calculation is
colorValue = startValue = ((endValue - startValue)/(numStages + 1))*k

here is that i have so far, but i cant get it to loop through the pixels, my end picture just turns out to be all one color of whatever pixel is in (0,0) of the first image.

//MorphStage method
  public void morphStage(Picture startPicture, Picture endPicture, int numStages, int k)
  {
    Pixel[] pixelArrayStart = startPicture.getPixels();    
    Pixel[] pixelArrayEnd = endPicture.getPixels();
    Pixel pixelObjEnd = null;
    Pixel pixelObjStart = null;
  

  
    //***********************Colour Values for Start Photo *************************************
    int redValueStart = 0;
    int greenValueStart = 0;
    int blueValueStart = 0;
    //********************* Colour Values for End Photo ****************************************
    int redValueEnd = 0;
    int greenValueEnd = 0;
    int blueValueEnd = 0;
    //**********************Colour Values for intermediate photo********************************
    int redValue = 0;
    int greenValue = 0;
    int blueValue = 0;
 //////////////////////////////////////////////////////////////////////////////////////////////////   

 
    for(int i = 0; i < pixelArrayStart.length; i++)//loops colums
    {
      
        //Gets the pixel and the color of that pixel
        pixelObjStart = pixelArrayStart[i];
        redValueStart = pixelObjStart.getRed();
        greenValueStart = pixelObjStart.getGreen();
        blueValueStart = pixelObjStart.getBlue();
        pixelObjEnd = pixelArrayEnd[i];
        redValueEnd = pixelObjEnd.getRed();
        greenValueEnd = pixelObjEnd.getGreen();
        blueValueEnd = pixelObjEnd.getBlue();
        
                   
        

              redValue = redValueStart +((redValueEnd - redValueStart)/(numStages + 1))*k; 
              greenValue = greenValueStart +((greenValueEnd - greenValueStart)/(numStages + 1))*k; 
              blueValue = blueValueStart +((blueValueEnd - blueValueStart)/(numStages + 1))*k; 
    
              pixelObjStart.setRed(redValue);
              pixelObjStart.setGreen(greenValue);
              pixelObjStart.setBlue(blueValue);
              
              
             
                
                
              
             }
           
      }
    
    
    


  
}// end of class Picture, put all new methods before this

Edited by Alexander, 14 November 2010 - 08:48 PM.
(added code tags)


#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
I don't see a wrong piece of code somewhere. Are you sure the getPixels() method returns the correct ones?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users