Results 1 to 6 of 6
  1. #1
    brandnew956 is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default Declaring a Variable for RGB swaps? Dr Java

    I created a method for my computer science class to swap the RGB values of a picture through a for loop and array. I want to make it so that I can type in picture.swapRGB(x) in the interactions pane and insert a variable (ex: 1,2,3 etc) and make the color swap that many times in the picture without having to type picture.swapRGB(); over and over but Im lost on how to do this. Can anybody help me out??

    Java Code:
    public void swapRGB(int numSwaps)
        //this method will be used to swap the RGB values of a picture
    {
        //for loop that goes through the entire array of pixels
        Pixel[] pixelArray = this.getPixels();
        Pixel pictObj = null;
        int value = 0;
        for (int index = 0; index < pixelArray.length; index++)
    {
          pictObj = pixelArray[index];
          
          //obtain the red, green and blue values of a picture
          int redVal = pictObj.getRed();
          int greenVal = pictObj.getGreen();
          int blueVal = pictObj.getBlue();
          
          //set all the red, green and blue values to the values we previously obtained to change the picture colors to those we desire
          pictObj.setRed(greenVal);
          pictObj.setGreen(blueVal);
          pictObj.setBlue(redVal);
          
        
    }
    }
    }

    thanks guys

    PS if my problem isnt clear just let me know and I'll try and explain in further detail

    thanks again

    Moderator Edit: code tags added to improve post's readability
    Last edited by Fubarable; 03-02-2010 at 05:14 AM. Reason: code tags added to improve post's readability

  2. #2
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

    Default

    Are you in CSI 201 in UAlb ?

  3. #3
    brandnew956 is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default

    yeah haha Im really lost. are you taking the course too?

  4. #4
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    so if I'm understanding you correctly, swapRGB(4) = swapRGB(1)? it seems to me that you would want to store the RGB values into a size 3 array and use some amth to swap. Like:
    int[0] = red
    int[1] = green
    int[2] = blue

    swapRGB(x)
    setRed(int[x%3]);
    setGreen(int[(1+x)%3)]);
    setBlue(int[(2+x)%3)]);

    Hope this helps
    Last edited by collin389; 03-02-2010 at 06:37 AM.

  5. #5
    brandnew956 is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by collin389 View Post
    so if I'm understanding you correctly, swapRGB(4) = swapRGB(1)? it seems to me that you would want to store the RGB values into a size 3 array and use some amth to swap. Like:
    int[0] = red
    int[1] = green
    int[2] = blue

    swapRGB(x)
    setRed(int[x%3]);
    setGreen(int[(1+x)%3)]);
    setBlue(int[(2+x)%3)]);

    Hope this helps
    Im trying to make it so that when I type in picture.swapRGB(2) in the interactions pane it does the method I created twice and swaps the colors 2 times. Or swapRGB(4) is swaps the rgb values 4 times without me having to type swaprgb in the interactions pane more than once. But i appreciate the help man.

  6. #6
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    so if r=0, g=100, b=200
    swap one makes r=100, g=200, b=0?
    therefore swap (2) means r=200, g=0, b=100
    and swap(3) gives you the original values, r=0,g=100, b=200
    Am I not understanding you? Please explain what you are trying to do better.

Similar Threads

  1. declaring classes
    By coltragon in forum New To Java
    Replies: 17
    Last Post: 12-21-2009, 07:20 PM
  2. Declaring URL object
    By TheFlying_Boy in forum New To Java
    Replies: 6
    Last Post: 08-03-2009, 08:05 PM
  3. Declaring variables
    By Flashmatix in forum New To Java
    Replies: 12
    Last Post: 01-20-2009, 04:43 PM
  4. Declaring an ArrayList
    By bugger in forum New To Java
    Replies: 3
    Last Post: 01-31-2008, 08:36 PM
  5. Declaring Vector
    By mew in forum New To Java
    Replies: 1
    Last Post: 12-05-2007, 09:14 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
  •