Solved RGB Loop

Discussion in 'Plugin Development' started by ItsOneAndTwo, Oct 14, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ItsOneAndTwo

    Hello developers, since i've never had to do this kind of a thing before, I'd like some help.
    What I want to do is to loop through every single RGB color possibilty (001,000,000|000,00,001)|000,000,002) and so on.
    What I want to do is, get LeatherArmorMeta's current color, and set the next rgb color, that it fades through all the possible combinations, with a given update rate (like go to the next color every 1 tick and so on).
    I've tried it with a "for loop", but then I couldn't set the loop time (it just goes through all the colors really fast), and also I couldn't set the next color of the armor that's supposed to be.
    If the help request seems a bit confusing, feel free to ask.
     
  2. Offline

    TheCodingCat

    what you were doing is good. But if you want it to change every tick use it in a BukkitRunnable.
     
  3. Offline

    Totom3

    ItsOneAndTwo You would have to use a repeated task for that. Just make sure it doesn't loop infinitely.
     
  4. Offline

    ItsOneAndTwo

    @TheCodingCat @Totom3 what I mean is i want to be able to control the delay before it changes, and also i would like to do it so, that it gets the current color from the player, and sets the next rgb color that sould be after that, but I dont know how.
     
  5. Offline

    Totom3

    ItsOneAndTwo Oh ok, if you want to control the delay you'd have to use a normal task and make it schedule itself for the amount of time you decide.

    For choosing the color, it depends on what you define by 'next color'. If you want increment green until it reached 255, then set it back to 0 and increment blue and repeat the process until blue reaches 255, in which case you set it back to 0 and increment red, etc etc...

    Then you just get the green value with color.getGreen(), increment it by 1, and if it is equal to 255, set it back to 0 and increment blue. Now do the same check with the blue color, and if it is equals to 255 you increment red. Finally if red is equal to 255 then I presume it iterated over all the possible colors, therefore you do not schedule an additional task and it will stop there.
     
  6. Offline

    ItsOneAndTwo

    Totom3 the problem is, to iterate through all the colors, the method you gave me wont cut it, i would have to loop through each value seperately, like 200,255, 255 | 201,000,000 | 201,000,001 and so on.
     
  7. Offline

    Totom3

    ItsOneAndTwo That's what it will do. Why is it a problem ? Could you precise what you want exactly ?
     
  8. Offline

    ItsOneAndTwo

    Totom3 whilst the red value is incrementing, the green and blue value's have to increment also, to get all the possible combinations, it cant skip a single value, for an example from (195,128,43) to (195,128,45).

    //Edit Nevermind, got it working the way I originally wanted to.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
Thread Status:
Not open for further replies.

Share This Page