Getting a diverse set of three numbers from two numbers

77 Views Asked by At

I'm using this information to build an interface to pick a color, but I feel that this question is purely math-related. Please correct me if this is the wrong StackExchange site for this.

I am making a function that accepts two numbers, n and m. n is a number between 0 and 200 and m is a number between 0 and 100. I want this function to return a set of three numbers (x, y, z), each number between 0 and 255.

There are n*m (20,000) possible unique inputs to this function, but the output could be one of 255^3 (16,581,375) combinations of the three numbers. Because I am using these numbers to generate color, I want to ensure that there is as diverse a set of results as possible based on the input.

Basically, I want f(n, m) to represent a diverse range of the 255^3 three number outputs.

Does anyone have any ideas as to how I could construct a function that outputs three numbers based on the input of two numbers in this way?

2

There are 2 best solutions below

4
On BEST ANSWER

(n + m x 200) x 838.8608 will give you 20000 numbers well spread out in the RGB space. Incrementing n will increase the green by two units and the blue by 71; incrementing m will increase the red by two or three units and green/blue by larger increments. In practice, you will see no correlation between (n, m) and the color.

0
On

We have 20000 possible inputs, if we want to distribute these into the 3 channels we get $\sqrt[3]{20000} = 27.14...$ different values per channel. Now we just need a function

$$ f: \mathbb R^2 \to \mathbb R^3 \text{ with } f([1,100],[1,200]) = [1,27]^3 $$

But you cannot find a function that maps these two sets really smoothly into eachother.

I'd try for example $$f(x,y) = 256 \cdot \left (\frac{\left \lfloor \frac{x}{\sqrt{200}} \right\rfloor}{\sqrt{200}}, \frac{x-\sqrt{200}\left \lfloor \frac{x}{\sqrt{200}} \right\rfloor}{200},\frac{y}{100} \right)$$ (The three values should be rounded to integers after multiplication with 256. This function maps of course $[0,200] \times [0,100]$ to $[0,255]^3$)