use of org.jwildfire.create.tina.palette.RGBColor in project JWildfire by thargor6.
the class BoldRandomGradientGenerator method generateKeyFrames.
@Override
public List<RGBColor> generateKeyFrames(int pKeyFrameCount) {
List<RGBColor> baseColors = new StrongHueRandomGradientGenerator().generateKeyFrames(128);
RGBColor black = new RGBColor();
List<RGBColor> res = new ArrayList<RGBColor>();
int stripeWidth = 12 + Tools.randomInt(24);
int blackWidth = Math.random() < 0.25 ? 8 + Tools.randomInt(16) : 0;
int stripeIdx = 0, colorIdx = 0;
while (res.size() < RGBPalette.PALETTE_SIZE) {
RGBColor stripeColor;
int width;
if (stripeIdx++ % 2 == 0 || blackWidth == 0) {
stripeColor = baseColors.get(colorIdx++);
width = stripeWidth;
} else {
stripeColor = black;
width = blackWidth;
}
for (int i = 0; i < width; i++) {
res.add(stripeColor);
}
}
while (res.size() >= RGBPalette.PALETTE_SIZE) {
res.remove(res.size() - 1);
}
return res;
}
use of org.jwildfire.create.tina.palette.RGBColor in project JWildfire by thargor6.
the class MonochromeRandomGradientGenerator method generateKeyFrames.
@Override
public List<RGBColor> generateKeyFrames(int pKeyFrameCount) {
HSLPixel hslPixel = new HSLPixel();
Pixel rgbPixel = new Pixel();
List<RGBColor> keyFrames = new ArrayList<RGBColor>();
hslPixel.saturation = Math.random() * 0.3 + 0.6999;
hslPixel.hue = Math.random() * Math.random();
for (int i = 0; i < pKeyFrameCount; i++) {
hslPixel.luminosity = Math.random() * 0.99;
HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
RGBColor col = new RGBColor(rgbPixel.r, rgbPixel.g, rgbPixel.b);
keyFrames.add(col);
}
return keyFrames;
}
use of org.jwildfire.create.tina.palette.RGBColor in project JWildfire by thargor6.
the class RandomGradientGenerator method generatePalette.
public static final RGBPalette generatePalette(List<RGBColor> pKeyFrames, boolean pFadeColors, boolean pUniformWidth) {
RGBPalette res = new RGBPalette();
if (pKeyFrames.size() == 1) {
RGBColor c = pKeyFrames.get(0);
for (int i = 0; i < RGBPalette.PALETTE_SIZE; i++) {
res.addColor(c.getRed(), c.getGreen(), c.getBlue());
}
} else {
// Compute uniform sizes for each color
int[] kfCount = new int[pKeyFrames.size()];
int sum1 = 0;
double sum2 = 0.0;
int n = pKeyFrames.size() - (pFadeColors ? 1 : 0);
double idxScl = (double) (RGBPalette.PALETTE_SIZE) / (double) (n);
for (int i = 0; i < n; i++) {
kfCount[i] = (int) idxScl;
sum1 += kfCount[i];
sum2 += idxScl;
if (sum2 - sum1 > 1) {
kfCount[i]++;
sum1++;
}
}
kfCount[n - 1] += RGBPalette.PALETTE_SIZE - sum1;
// Randomize sizes
if (!pUniformWidth && idxScl > 3) {
for (int i = 0; i < n; i++) {
int j = (int) (Math.random() * n);
int min = (kfCount[i] < kfCount[j] ? kfCount[i] : kfCount[j]);
int r = (int) (Math.random() * min - min / 2);
kfCount[i] += r;
kfCount[j] -= r;
}
}
// Allocate colors
int j = 0;
int lIdx = 0;
for (int i = 0; i < RGBPalette.PALETTE_SIZE; i++) {
RGBColor lColor = pKeyFrames.get(lIdx);
int r, g, b;
if (pFadeColors) {
double relX = (double) (j) / (double) kfCount[lIdx];
RGBColor rColor = pKeyFrames.get(lIdx + 1);
r = Tools.roundColor((double) lColor.getRed() + ((double) (rColor.getRed() - lColor.getRed())) * relX);
g = Tools.roundColor((double) lColor.getGreen() + ((double) (rColor.getGreen() - lColor.getGreen())) * relX);
b = Tools.roundColor((double) lColor.getBlue() + ((double) (rColor.getBlue() - lColor.getBlue())) * relX);
} else {
r = lColor.getRed();
g = lColor.getGreen();
b = lColor.getBlue();
}
res.addColor(r, g, b);
// System.out.println(i + ": " + r + " " + g + " " + b);
j++;
if (j >= kfCount[lIdx]) {
j = 0;
if (lIdx < n - 1)
lIdx++;
}
}
}
return res;
}
use of org.jwildfire.create.tina.palette.RGBColor in project JWildfire by thargor6.
the class StripesRandomGradientGenerator method createStripeColor.
private RGBColor createStripeColor() {
HSLPixel hslPixel = new HSLPixel();
hslPixel.saturation = Math.random() * 0.1 + 0.8999;
double rnd = Math.random() + Math.random() + Math.random() + Math.random() + Math.random();
if (rnd > 4.0)
hslPixel.hue = 0.8 + (rnd - 4.0) / 7.0;
else if (rnd > 3.0)
hslPixel.hue = 0.2 + (rnd - 3.0) / 7.0;
else if (rnd > 2.0)
hslPixel.hue = 0.0 + (rnd - 2.0) / 7.0;
else if (rnd > 1.0)
hslPixel.hue = 0.6 + (rnd - 1.0) / 7.0;
else
hslPixel.hue = 0.4 + rnd / 7.0;
hslPixel.luminosity = Math.random() * 0.1 + 0.8999;
Pixel rgbPixel = new Pixel();
HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
return new RGBColor(rgbPixel.r, rgbPixel.g, rgbPixel.b);
}
use of org.jwildfire.create.tina.palette.RGBColor in project JWildfire by thargor6.
the class StripesRandomGradientGenerator method generateKeyFrames.
@Override
public List<RGBColor> generateKeyFrames(int pKeyFrameCount) {
RGBColor stripeColor = createStripeColor();
List<RGBColor> baseColors = new StrongHueRandomGradientGenerator().generateKeyFrames(pKeyFrameCount);
List<RGBColor> res = new ArrayList<RGBColor>();
int stripeWidth = 1 + Tools.randomInt(2);
int colorWidth = 3 + Tools.randomInt(5);
int colorIdx = 0;
while (res.size() < RGBPalette.PALETTE_SIZE) {
for (int i = 0; i < stripeWidth; i++) {
res.add(stripeColor);
}
RGBColor colorLeft = baseColors.get(colorIdx++);
if (colorIdx >= baseColors.size()) {
colorIdx = 0;
}
RGBColor colorRight = baseColors.get(colorIdx++);
if (colorIdx >= baseColors.size()) {
colorIdx = 0;
}
res.add(colorLeft);
for (int i = 1; i < colorWidth; i++) {
double scl = (double) i / (double) (colorWidth - 1);
double r = colorLeft.getRed() + (colorRight.getRed() - colorLeft.getRed()) * scl;
double g = colorLeft.getGreen() + (colorRight.getGreen() - colorLeft.getGreen()) * scl;
double b = colorLeft.getBlue() + (colorRight.getBlue() - colorLeft.getBlue()) * scl;
RGBColor color = new RGBColor(Tools.roundColor(r), Tools.roundColor(g), Tools.roundColor(b));
res.add(color);
}
}
while (res.size() >= RGBPalette.PALETTE_SIZE) {
res.remove(res.size() - 1);
}
return res;
}
Aggregations