by yarg · 4y ago · 0 comments
I was messing around with something similar (before I found out about Oklab), that generated a nice pastel colour ring.
(I didn't (at the time) know how to get the colours to a fixed perceptual saturation level, so gave up intending to come back to it.)
//something like this
static final int MAX = 255;
static final float OFFSET_R = 0f;
static final float OFFSET_G = (float)(TWO_PI/3);
static final float OFFSET_B = 2 * OFFSET_G;
public int buildColour(float theta){
final int r = round(MAX * sin(theta + OFFSET_R));
final int g = round(MAX * sin(theta + OFFSET_G));
final int b = round(MAX * sin(theta + OFFSET_B));
return 0xFF000000 | (r << 0x10) | (g << 0x08) | b;
}
(If I were doing it now, I'd use Oklab for normalisation.)This tool that others have linked is pretty good if you’re fine with relaxing the constraints (just make sure to change to colour space to LCH OKlab): https://huetone.ardov.me.
//fix the sine wave amplitude and offset
static final float CHANNEL_MUL = 127.5f;
static final float OFFSET_R = 0f;
static final float OFFSET_G = (float)(TWO_PI/3);
static final float OFFSET_B = 2 * OFFSET_G;
public int buildColour(float theta){
final int r = round(CHANNEL_MUL * (1f + sin(theta + OFFSET_R)));
final int g = round(CHANNEL_MUL * (1f + sin(theta + OFFSET_G)));
final int b = round(CHANNEL_MUL * (1f + sin(theta + OFFSET_B)));
return 0xFF000000 | (r << 0x10) | (g << 0x08) | b;
}