📄 oodinnabox.java
字号:
package ergo.ui;
// $Id: OodInnaBox.java,v 1.4 1999/08/27 03:07:56 sigue Exp $
/*
* Copyright (C) 1999 Carl L. Gay and Antranig M. Basman.
* See the file copyright.txt, distributed with this software,
* for further information.
*/
import ergo.util.Debug;
/**
* These classes generate the true-color board and stones.
* The color values for the board are the six static ints
* near the head of OodInnaBox - the "base" values are
* the RGB values for the darkest color on the pattern,
* and the lightest color is given by adding the "move"
* values to these. Please fiddle with them - I've
* wasted too much time on them, and have no artisitic
* sensibilities! - AMB.
*/
public class OodInnaBox {
public static int esteps = 250;
public static double esize = 10;
public static double [] ramp;
public static int ramplf = 4;
public static int rampbf = ramplf + 1;
public static double freq = 0.03;
static {
ramp = new double[esteps];
for (int i = 0; i < esteps * ramplf / rampbf; ++i) {
ramp[i] = i;
}
for (int i = esteps * ramplf / rampbf; i < esteps; ++i) {
ramp[i] = (esteps - i) * ramplf;
}
}
// 229 188 102 "light wood"
// base values for darkest color on board.
public static int baser = 170; // lightest 180 130 80 darkest
public static int baseg = 130; // 140 100 50
public static int baseb = 70; // 70 80 30
// added to base to get lightest color.
public static int mover = 60; // 60 // 115 // 55
public static int moveg = 40; // 40 // 45 // 40
public static int moveb = 20; // 20 // 20 // 0
public static int getAverageColor () {
return (((baser + mover / 2) << 16)
+ ((baseg + moveg / 2) << 8)
+ (baseb + moveb / 2)
& 0xff000000);
}
public static int getDarkColor () {
return (baser << 16) + (baseg << 8) + baseb;
}
public static int getLightColor () {
return ((baser + mover) << 16) + ((baseg + moveg) << 8) + (baseb + moveb);
}
public static RawImage Ood (int side, int bevel_width) {
RawImage br = new RawImage(side, side);
int addr = 0;
int[] data = br.data;
double fac = 640.0 / side;
//long time = System.currentTimeMillis();
for (int y = 0; y < side; ++y) {
for (int x = 0; x < side; ++x) {
double val = (ramp[ (int) (200 * (4 + 1.5 * Math.sin(y * fac / 1500 + x * fac / 100)
+ Math.sin(x * fac / 35) / 1.2) * esteps * freq) % esteps]
/ esteps);
data[addr] = (int)(baser + mover * val) << 16 |
(int)(baseg + moveg * val) << 8 |
(int)(baseb + moveb * val) | 0xff000000;
++addr;
}
}
//Debug.println("Ood time: " + (System.currentTimeMillis() - time));
int maxcol = Math.max(baser + mover, baseg + moveg);
maxcol = Math.max(maxcol, baseb + moveg);
int maxfactor = ((255 / maxcol) << 8) - 256;
// System.out.println("Max: "+maxfactor);
for (int longc = 0; longc < side; ++longc) {
for (int shortc = 0; shortc < bevel_width; ++shortc) {
if (longc >= shortc && (side - longc) > shortc) {
plotbevel(longc, shortc, side, data, maxfactor / 2 + 256); // top, quite bright
plotbevel((side - shortc - 1), longc, side, data, 256 - 85); // right, dark
plotbevel((side - longc - 1), (side - shortc - 1), side, data, 256 - 110); // bottom, q.dark.
plotbevel(shortc, (side - longc - 1), side, data, 2 * maxfactor / 5 + 256); // left, quite bright.
}
}
}
return br;
}
private static void plotbevel (int x, int y, int side, int[] data, int factor) {
int address = x + y * side;
int value = data[address];
data[address] = (((((value & 0xff0000) * factor) & 0xff000000) |
(((value & 0xff00) * factor) & 0xff0000) |
(((value & 0xff) * factor) & 0xff00)) >> 8) | 0xff000000;
}
} // end class OodInnaBox
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -