Code cleaning and warning removal
This commit is contained in:
@@ -7,7 +7,7 @@ class Color {
|
||||
final byte g;
|
||||
final byte b;
|
||||
|
||||
Color(byte r, byte g, byte b) {
|
||||
private Color(byte r, byte g, byte b) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
@@ -30,18 +30,6 @@ class Color {
|
||||
Utils.randomByte(rand));
|
||||
}
|
||||
|
||||
Color plus(Color other) {
|
||||
return new Color(Utils.bound((short) r + other.r),
|
||||
Utils.bound((short) g + other.g),
|
||||
Utils.bound((short) b + other.b));
|
||||
}
|
||||
|
||||
Color times(float factor) {
|
||||
return new Color((byte) (r * factor),
|
||||
(byte) (g * factor),
|
||||
(byte) (b * factor));
|
||||
}
|
||||
|
||||
static Color add(float[] factors, Color[] colors) {
|
||||
float r = 0f;
|
||||
float g = 0f;
|
||||
|
||||
@@ -11,9 +11,9 @@ class Generator {
|
||||
private final int height2;
|
||||
private final int size;
|
||||
|
||||
private float slope;
|
||||
private Color source;
|
||||
private Color divergence;
|
||||
private final float slope;
|
||||
private final Color source;
|
||||
private final Color divergence;
|
||||
|
||||
private long seed = 0L;
|
||||
|
||||
@@ -88,17 +88,6 @@ class Generator {
|
||||
generateLine(y);
|
||||
}
|
||||
|
||||
private static Color getDivergence(int width, int height, int size) {
|
||||
int size2 = (int) Math.min(Math.max(width / size, height / size), Byte.MAX_VALUE * 1.5f);
|
||||
Color c;
|
||||
do {
|
||||
c = new Color(Utils.randInt(0, Byte.MAX_VALUE),
|
||||
Utils.randInt(0, Byte.MAX_VALUE),
|
||||
Utils.randInt(0, Byte.MAX_VALUE));
|
||||
} while (c.sum() * 2 < size2 || c.sum() > Byte.MAX_VALUE * 2);
|
||||
return c;
|
||||
}
|
||||
|
||||
private void generateLine(int y) {
|
||||
for (int x = 0; x < width2; x++) {
|
||||
Color div = divergence.diverge(rand);
|
||||
@@ -112,56 +101,6 @@ class Generator {
|
||||
}
|
||||
}
|
||||
|
||||
void inspect(int x, int y, int size, boolean unsigned) {
|
||||
|
||||
System.out.println(String.format("Inspect area : %d-%d x %d-%d", x, x + size, y, y + size));
|
||||
|
||||
int sumr = 0;
|
||||
int sumg = 0;
|
||||
int sumb = 0;
|
||||
for (int i = x; i < x + size; i++) {
|
||||
for (int j = y; j < y + size; j++) {
|
||||
System.out.print(String.format("%1$-12s %2$-4d ", table[i][j].toString(unsigned), table[i][j].sum()));
|
||||
sumr += unsigned ? table[i][j].r - Byte.MIN_VALUE : table[i][j].r;
|
||||
sumg += unsigned ? table[i][j].g - Byte.MIN_VALUE : table[i][j].g;
|
||||
sumb += unsigned ? table[i][j].b - Byte.MIN_VALUE : table[i][j].b;
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
System.out.println(String.format("mean : (%d,%d,%d) %d", sumr / (size * size), sumg / (size * size), sumb / (size * size), (sumr + sumg + sumb) / (size * size)));
|
||||
}
|
||||
|
||||
void inspectDivergence(int x0, int y0, int size) {
|
||||
System.out.println(String.format("Inspect divergence in area : %d-%d x %d-%d", x0, x0 + size, y0, y0 + size));
|
||||
|
||||
int sumr = 0;
|
||||
int sumg = 0;
|
||||
int sumb = 0;
|
||||
for (int x = x0; x < x0 + size; x++) {
|
||||
for (int y = y0; y < y0 + size; y++) {
|
||||
|
||||
Color div = table[x][y];
|
||||
|
||||
if (x > 0 && y == 0) {
|
||||
div = Color.add(new float[]{1f,-1f},new Color[]{table[x][y], table[x - 1][y]});
|
||||
} else if (x == 0 && y > 0) {
|
||||
div = Color.add(new float[]{1f,-1f},new Color[]{table[x][y], table[x][y-1]});
|
||||
} else if (x > 0 && y > 0) {
|
||||
div = Color.add(new float[]{1f,-slope,slope-1f},new Color[]{table[x][y], table[x][y - 1], table[x - 1][y]});
|
||||
}
|
||||
|
||||
System.out.print(String.format("%1$-12s %2$-4d ", div, div.sum()));
|
||||
|
||||
sumr += div.r;
|
||||
sumg += div.g;
|
||||
sumb += div.b;
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println(String.format("mean : (%d,%d,%d) %d", sumr / (size * size), sumg / (size * size), sumb / (size * size), (sumr + sumg + sumb) / (size * size)));
|
||||
}
|
||||
|
||||
byte[] getData() {
|
||||
byte[] data = new byte[width * height * 3];
|
||||
int k = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.klemek.marble;
|
||||
|
||||
public class LocalTests {
|
||||
class LocalTests {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Generator gen = new Generator(800, 800, 2);
|
||||
|
||||
@@ -3,7 +3,7 @@ package fr.klemek.marble;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MarbleViewer extends JFrame {
|
||||
class MarbleViewer extends JFrame {
|
||||
|
||||
public MarbleViewer(Generator generator) {
|
||||
this.setLocation(0, 0);
|
||||
@@ -16,7 +16,7 @@ public class MarbleViewer extends JFrame {
|
||||
|
||||
private class Panel extends JPanel {
|
||||
|
||||
private Generator generator;
|
||||
private final Generator generator;
|
||||
|
||||
Panel(Generator generator) {
|
||||
this.generator = generator;
|
||||
|
||||
@@ -29,7 +29,7 @@ class WallpaperGenerator {
|
||||
makeWallpaper(file, width, height, size);
|
||||
}
|
||||
|
||||
static Dimension getScreenSizes() {
|
||||
private static Dimension getScreenSizes() {
|
||||
Dimension dim = new Dimension(0, 0);
|
||||
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
|
||||
dim.width = Math.max(dim.width, gd.getDisplayMode().getWidth());
|
||||
@@ -38,7 +38,7 @@ class WallpaperGenerator {
|
||||
return dim;
|
||||
}
|
||||
|
||||
static void makeWallpaper(String name, int width, int height, int size) {
|
||||
private static void makeWallpaper(String name, int width, int height, int size) {
|
||||
System.out.println("Making wallpaper '" + name + "' " + width + "x" + height + "px");
|
||||
|
||||
File bmpFile = new File(name + ".bmp");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fr.klemek.marble;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class UtilsTest {
|
||||
|
||||
@@ -61,12 +62,4 @@ public class UtilsTest {
|
||||
assertArrayEquals(new byte[]{0, 0, 0, 1, 2, 3, 4, 5, 6, 7}, array0);
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void num2bytes() {
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void num2bytes1() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user