static RGB probeRandomPixel(RGBImage image) {
int x = (int) (random()*(image.getWidth()-1));
int y = (int) (random()*(image.getHeight()-1));
return image.getPixel(x, y);
}
static float probeRandomPixel(BWImage image) {
int x = (int) (random()*(image.getWidth()-1));
int y = (int) (random()*(image.getHeight()-1));
return image.getPixel(x, y);
}
static RGB randomColor() {
return new RGB(random(), random(), random());
}
static float randomBrightness() {
ret (float) random();
}
static RGBImage resizeToWidth(RGBImage image, int w) {
return resize(image, w, (int) ((image.getHeight()*(double) w)/image.getWidth()));
}
public static RGBImage resize(RGBImage image, int w, int h) {
if (w == image.getWidth() && h == image.getHeight()) return image;
int[] pixels = new int[w*h];
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
pixels[y*w+x] = image.getInt(x*image.getWidth()/w, y*image.getHeight()/h);
return new RGBImage(w, h, pixels);
}
static Random _random = new Random();
static double random() {
return _random.nextInt(100001)/100000.0;
}
static int random(int max) {
return _random.nextInt(max);
}
static double random(double min, double max) {
return min+random()*(max-min);
}
static double normalize(double d) {
return Math.max(0, Math.min(1, d));
}
static int round(double d) {
return (int) Math.round(d);
}
static double mix(double a, double b, double bishness) {
return a+(b-a)*bishness;
}
public static double pixelDiff(RGB a, RGB b) {
return (Math.abs(a.r-b.r) + Math.abs(a.g-b.g) + Math.abs(a.b-b.b))/3;
}
public static double diff(RGBImage image, RGBImage image2) {
int w = image.getWidth(), h = image.getHeight();
double sum = 0;
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
sum += pixelDiff(image.getRGB(x, y), image2.getRGB(x, y));
return sum/(w*h);
}
static double diff(BWImage image, BWImage image2) {
int w = image.getWidth(), h = image.getHeight();
double sum = 0;
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
sum += Math.abs(image.getPixel(x, y) - image2.getPixel(x, y));
return sum/(w*h);
}
public static void copy(RGBImage src, int srcX, int srcY, RGBImage dst, int dstX, int dstY, int w, int h) {
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
dst.setPixel(dstX+x, dstY+y, src.getPixel(srcX+x, srcY+y));
}
public static void copy(BWImage src, int srcX, int srcY, BWImage dst, int dstX, int dstY, int w, int h) {
w = min(w, dst.getWidth()-dstX);
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
dst.setByte(dstX+x, dstY+y, src.getByte(srcX+x, srcY+y));
}
static float varyChannel(float x) {
return Math.max(0f, Math.min(1f, (float) (x+random(-0.1, 0.1))));
}
static double vary01(double x) {
return Math.max(0, Math.min(1, x+random(-0.1, 0.1)));
}
static RGB varyColor(RGB rgb) {
int s = random(3);
if (s == 0)
return new RGB(varyChannel(rgb.r), rgb.g, rgb.b);
else if (s == 1)
return new RGB(rgb.r, varyChannel(rgb.g), rgb.b);
else
return new RGB(rgb.r, rgb.g, varyChannel(rgb.b));
}
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment