-1

So, I have two colors:

public final static Color FAR = new Color(255, 255, 60);
public final static Color CLOSE = new Color(0, 255, 255);

Three arrays:

private int R[]=new int[100];
private int G[]=new int[100];
private int B[]=new int[100];

And I try to set there different values:

double ratio;
        for(int i=0;i<100;i++) {
        ratio = i / 100;
        R[i] = (int)Math.abs((ratio * FAR.getRed()) + ((1 - ratio) * CLOSE.getRed()));
        G[i] = (int)Math.abs((ratio * FAR.getGreen()) + ((1 - ratio) * CLOSE.getGreen()));
        B[i] = (int)Math.abs((ratio * FAR.getBlue()) + ((1 - ratio) * CLOSE.getBlue()));
        }

But all values are the same, R always 0, G - 255 and B - 255. Can someone please explain me why?

Kyoko
  • 1
  • 1
  • 3
    integer divided by integer is integer, need to cast to double or ratio will always be a whole number. – Compass May 02 '18 at 20:52
  • 1
    To add to @Compass comment, divide by 100.0 instead – bdkosher May 02 '18 at 20:54
  • Tbh I have there one variable that I changed to 100, but yeah, I should just put there (double)(this int variable), I just didn't notice, thanks guys xD – Kyoko May 02 '18 at 21:01

1 Answers1

0

Division between integers returns another integer, them i/100 will return always 0.

Try this:

ratio = i / 100.0;

David

David
  • 123
  • 4