Initial
This commit is contained in:
commit
501aabd228
384
src/Engine.java
Normal file
384
src/Engine.java
Normal file
@ -0,0 +1,384 @@
|
||||
|
||||
//import com.nokia.mid.ui.DeviceControl;
|
||||
import java.util.Calendar;
|
||||
import java.util.Random;
|
||||
import javax.microedition.lcdui.Canvas;
|
||||
import javax.microedition.lcdui.Graphics;
|
||||
import javax.microedition.lcdui.Image;
|
||||
|
||||
public class Engine extends Canvas implements Runnable {
|
||||
|
||||
Graphics G;
|
||||
Image I, img;
|
||||
private int S = Math.abs(VisualME.midlet.Sw);
|
||||
private int N = Math.abs(VisualME.midlet.Nw);
|
||||
private int K = Math.abs(VisualME.midlet.Kw);
|
||||
private float L = (float) 1/VisualME.midlet.Lw;
|
||||
private int T = Math.abs(VisualME.midlet.Tw);
|
||||
private int U = Math.abs(10-VisualME.midlet.Uw);
|
||||
|
||||
private boolean bl = VisualME.midlet.bl;
|
||||
private boolean dl = VisualME.midlet.dl;
|
||||
private boolean vl = VisualME.midlet.vl;
|
||||
private boolean fl = VisualME.midlet.fl;
|
||||
private boolean vbl = VisualME.midlet.vbl;
|
||||
public boolean rb, gb, bb;
|
||||
public static float x, y, tx, ty, k, d, len;
|
||||
public int rc = 0, gc = 0, bc = 0, rgb = 1, fr = 1, ar = 1;
|
||||
float[] a = new float[N];
|
||||
public Thread thr = new Thread(this);
|
||||
|
||||
Engine() {
|
||||
|
||||
setFullScreenMode(true);
|
||||
I = Image.createImage(getWidth(), getHeight());
|
||||
G = I.getGraphics();
|
||||
thr.start();
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
setFullScreenMode(true);
|
||||
filters(g);
|
||||
paintQ(G);
|
||||
repaint();
|
||||
}
|
||||
public void paintQ(Graphics grf) {
|
||||
//setFullScreenMode(true);
|
||||
rgb(grf);
|
||||
visual(grf);
|
||||
|
||||
}
|
||||
|
||||
public void keyPressed(int key) {
|
||||
if (key == KEY_NUM3 && fr == 6) {
|
||||
fr = 1;
|
||||
} else if (key == KEY_NUM1 && fr == 1) {
|
||||
fr = 6;
|
||||
} else if (key == KEY_NUM3 && fr < 6) {
|
||||
fr++;
|
||||
} else if (key == KEY_NUM1 && fr > 1) {
|
||||
fr--;
|
||||
} else if (key == KEY_NUM7 && ar == 14) {
|
||||
ar = 1;
|
||||
} else if (key == KEY_NUM9 && ar == 1) {
|
||||
ar = 14;
|
||||
} else if (key == KEY_NUM7 && ar < 14) {
|
||||
ar++;
|
||||
} else if (key == KEY_NUM9 && ar > 1) {
|
||||
ar--;
|
||||
} else if (key == -7) {
|
||||
VisualME.midlet.destroyApp(true);
|
||||
} else if (key == KEY_NUM0) {
|
||||
VisualME.midlet.display.setCurrent(VisualME.midlet.Param);
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
Random PRND = new Random();
|
||||
try {
|
||||
Thread.sleep((PRND.nextLong() >>> 1) % 30);
|
||||
} catch (InterruptedException ex) {}
|
||||
int i = (PRND.nextInt() >>> 1) % 256;
|
||||
if (dl) {
|
||||
if (i>15 && i<18) ar = (PRND.nextInt() >>> 1) % 14;
|
||||
if (i>115 && i<118) fr = (PRND.nextInt() >>> 1) % 6+1;
|
||||
}
|
||||
if (bl) if (i>165 && i<218) VisualME.midlet.display.flashBacklight(2);
|
||||
if (vl) if (i>25 && i<28) VisualME.midlet.Cw = (PRND.nextInt() >>> 1) % 7;
|
||||
if (fl) if (i>35 && i<38) T = (PRND.nextInt() >>> 1) % 4;
|
||||
if (vbl) if (i>28 && i<34) VisualME.midlet.display.vibrate((PRND.nextInt() >>> 1) % 200);
|
||||
}
|
||||
}
|
||||
|
||||
public static String time2fileName() {
|
||||
String h, m, s;
|
||||
Calendar cal = Calendar.getInstance();
|
||||
h = String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
|
||||
if (h.length() == 1) {
|
||||
h = "0" + h;
|
||||
}
|
||||
m = String.valueOf(cal.get(Calendar.MINUTE));
|
||||
if (m.length() == 1) {
|
||||
m = "0" + m;
|
||||
}
|
||||
s = String.valueOf(cal.get(Calendar.SECOND));
|
||||
if (s.length() == 1) {
|
||||
s = "0" + s;
|
||||
}
|
||||
return (h+":"+m+":"+s);
|
||||
}
|
||||
|
||||
public void filters(Graphics g) {
|
||||
if (VisualME.midlet.Cw==0) {
|
||||
g.drawImage(I, 0, 0, 20); // ïðîñòî
|
||||
}
|
||||
if (VisualME.midlet.Cw==1) {
|
||||
img = Lib_effects.effect(I, 0);// Îáåñöâåòèòü
|
||||
g.drawImage(img, 0, 0, 20);
|
||||
}
|
||||
if (VisualME.midlet.Cw==2) {
|
||||
img = Lib_effects.effect(I, 1);// Íåãàòèâ
|
||||
g.drawImage(img, 0, 0, 20);
|
||||
}
|
||||
if (VisualME.midlet.Cw==3) {
|
||||
img = Lib_effects.effect(I, 5);// Ñãëàæèâàíèå
|
||||
g.drawImage(img, 0, 0, 20);
|
||||
}
|
||||
if (VisualME.midlet.Cw==4) {
|
||||
img = Lib_effects.effect(I, 4);// Cåïèÿ
|
||||
g.drawImage(img, 0, 0, 20);
|
||||
}
|
||||
if (VisualME.midlet.Cw==5) {
|
||||
img = Lib_effects.effect(I, 7);// ×/á
|
||||
g.drawImage(img, 0, 0, 20);
|
||||
}
|
||||
if (VisualME.midlet.Cw==6) {
|
||||
img = Lib_effects.contrast(I, 255, 120, 120, 120);// ×/á
|
||||
g.drawImage(img, 0, 0, 20);
|
||||
}
|
||||
}
|
||||
|
||||
public void rgb(Graphics grf) {
|
||||
if (rgb == 1) {
|
||||
rc++;
|
||||
if (rc > 253) {
|
||||
rc--;
|
||||
rb = true;
|
||||
}
|
||||
if (rb == true) {
|
||||
rc = rc - 2;
|
||||
}
|
||||
if (rc < 18 && rb == true) {
|
||||
rc = 0;
|
||||
rb = false;
|
||||
rgb++;
|
||||
}
|
||||
}
|
||||
if (rgb == 2) {
|
||||
gc++;
|
||||
if (gc > 253) {
|
||||
gc--;
|
||||
gb = true;
|
||||
}
|
||||
if (gb == true) {
|
||||
gc = gc - 2;
|
||||
}
|
||||
if (gc < 18 && gb == true) {
|
||||
gc = 0;
|
||||
gb = false;
|
||||
rgb++;
|
||||
}
|
||||
}
|
||||
if (rgb == 3) {
|
||||
bc++;
|
||||
if (bc > 253) {
|
||||
bc--;
|
||||
bb = true;
|
||||
}
|
||||
if (bb == true) {
|
||||
bc = bc - 2;
|
||||
}
|
||||
if (bc < 18 && bb == true) {
|
||||
bc = 0;
|
||||
bb = false;
|
||||
rgb++;
|
||||
}
|
||||
}
|
||||
if (rgb == 4) {
|
||||
//System.out.println("rc="+rc+" gc= "+gc);
|
||||
rc++;
|
||||
gc++;
|
||||
if (rc > 253) {
|
||||
rc--;
|
||||
gc--;
|
||||
rb = true;
|
||||
}
|
||||
if (rb == true) {
|
||||
rc = rc - 2;
|
||||
gc = gc - 2;
|
||||
}
|
||||
if (rc < 18 && rb == true) {
|
||||
rc = 0;
|
||||
gc = 0;
|
||||
rb = false;
|
||||
rgb++;
|
||||
}
|
||||
}
|
||||
if (rgb == 5) {
|
||||
rc++;
|
||||
bc++;
|
||||
if (rc > 253) {
|
||||
rc--;
|
||||
bc--;
|
||||
rb = true;
|
||||
}
|
||||
if (rb == true) {
|
||||
rc = rc - 2;
|
||||
bc = bc - 2;
|
||||
}
|
||||
if (rc < 18 && rb == true) {
|
||||
rc = 0;
|
||||
bc = 0;
|
||||
rb = false;
|
||||
rgb++;
|
||||
}
|
||||
}
|
||||
if (rgb == 6) {
|
||||
gc++;
|
||||
bc++;
|
||||
if (gc > 253) {
|
||||
gc--;
|
||||
bc--;
|
||||
gb = true;
|
||||
}
|
||||
if (gb == true) {
|
||||
gc = gc - 2;
|
||||
bc = bc - 2;
|
||||
}
|
||||
if (gc < 18 && gb == true) {
|
||||
gc = 0;
|
||||
bc = 0;
|
||||
gb = false;
|
||||
rgb++;
|
||||
}
|
||||
}
|
||||
if (rgb == 7) {
|
||||
rc++;
|
||||
gc++;
|
||||
bc++;
|
||||
if (gc > 253) {
|
||||
rc--;
|
||||
gc--;
|
||||
bc--;
|
||||
gb = true;
|
||||
}
|
||||
if (gb == true) {
|
||||
rc = rc - 2;
|
||||
gc = gc - 2;
|
||||
bc = bc - 2;
|
||||
}
|
||||
if (gc < 18 && gb == true) {
|
||||
rc = 0;
|
||||
gc = 0;
|
||||
bc = 0;
|
||||
gb = false;
|
||||
rgb = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void visual(Graphics grf) {
|
||||
int width = grf.getClipWidth();
|
||||
int height = grf.getClipHeight();
|
||||
if (width > height) {
|
||||
len = (float) (height / L / N);
|
||||
} else {
|
||||
len = (float) (width / L / N);
|
||||
}
|
||||
Random RND = new Random();
|
||||
//a[0]=(float) Math.abs(RND.nextFloat()*18);
|
||||
k = (float) (Math.abs(RND.nextFloat() * 360) * Math.PI / 180);
|
||||
float r50 = (float) (Math.abs(RND.nextFloat()) * 50);
|
||||
d = (float) (Math.PI * 2 / S);
|
||||
if (r50 < 2) {
|
||||
k = (float) (Math.abs(RND.nextFloat() * 1440) * Math.PI / 180);
|
||||
}
|
||||
a[0] = (float) (a[0] + Math.sin(k)/U);
|
||||
for (int i = 1; i < N; i++) {
|
||||
a[i] = (float) (a[i] + (a[i - 1] - a[i]) * 0.1);
|
||||
|
||||
}
|
||||
for (int j = 0; j < S; j++) {
|
||||
x = (float) (0.5 * width);
|
||||
y = (float) (0.5 * height);
|
||||
for (int i = 1; i < N; i++) {
|
||||
grf.setColor(rc, gc, bc);
|
||||
if (fr == 1) {
|
||||
tx = (float) (x + Math.cos(j * d + a[1]) * len);
|
||||
ty = (float) (y + Math.sin(j * d + a[i]) * len);
|
||||
x = x + (float) (Math.cos(j * d + a[i]) * len);
|
||||
}
|
||||
if (fr == 2) {
|
||||
tx = (float) (x + Math.sin(j * d + a[i]) * len);
|
||||
ty = (float) (y + Math.cos(j * d + a[i]) * len);
|
||||
}
|
||||
if (fr == 3) {
|
||||
tx = (float) (x + Math.tan(j * d + a[1]) * len);
|
||||
ty = (float) (y + Math.cos(j * d + a[i]) * len);
|
||||
y = y - (float) (Math.sin(j * d + a[i]) * len);
|
||||
}
|
||||
if (fr == 4) {
|
||||
tx = (float) (x + Math.tan(j * d + a[1]) * len);
|
||||
ty = (float) (y + Math.cos(j * d + a[i]) * len);
|
||||
x = y - (float) (Math.sin(j * d + a[i]) * len);
|
||||
}
|
||||
if (fr == 5) {
|
||||
tx = (float) (x + Math.tan(j * d + a[1]) * len);
|
||||
ty = (float) (y + Math.cos(j * d + a[i]) * len);
|
||||
x = (float) (x * ty * d + a[i] - (float) (Math.sin(j * d + a[i]) * len));
|
||||
}
|
||||
if (fr == 6) {
|
||||
tx = (float) (x + Math.cos(j * d + a[1]) * len);
|
||||
ty = (float) (y + Math.sin(j * d + a[1]) * len);
|
||||
x = x + (float) (Math.sin(j * d + a[i]) * len);
|
||||
y = y + (float) (Math.cos(j * d + a[i]) * len);
|
||||
tx = (float) (x + Math.cos(j * d + a[1]) * len);
|
||||
ty = (float) (y + Math.sin(j * d + a[1]) * len);
|
||||
x = x + (float) (Math.sin(j * d + a[i]) * len);
|
||||
y = y + (float) (Math.cos(j * d + a[i]) * len);
|
||||
}
|
||||
if (ar == 2) {
|
||||
grf.setColor(255, (255 - 255 * i / N), 0);
|
||||
}
|
||||
if (ar == 3) {
|
||||
grf.setColor(rc, (255 - 255 * i / N), 255);
|
||||
}
|
||||
if (ar == 4) {
|
||||
grf.setColor((255 - 255 * i / N), 255, 0);
|
||||
}
|
||||
if (ar == 5) {
|
||||
grf.setColor((255 - 255 * i / N), (255 - 255 * i / N), 255);
|
||||
}
|
||||
if (ar == 6) {
|
||||
grf.setColor((255 - 255 * i / N), 255, 255);
|
||||
}
|
||||
if (ar == 7) {
|
||||
grf.setColor(0, 255, (255 - 255 * i / N));
|
||||
}
|
||||
if (ar == 8) {
|
||||
grf.setColor(255, gc, (255 - 255 * i / N));
|
||||
}
|
||||
if (ar == 9) {
|
||||
grf.setColor(255, (255 - 255 * i / N), (255 - 255 * i / N));
|
||||
}
|
||||
if (ar == 10) {
|
||||
grf.setColor(rc, (255 - 255 * i / N), 0);
|
||||
}
|
||||
if (ar == 11) {
|
||||
grf.setColor(255, (255 - 255 * i / N), 255);
|
||||
}
|
||||
if (ar == 12) {
|
||||
grf.setColor((255 - 255 * i / N), 0, 255);
|
||||
}
|
||||
if (ar == 13) {
|
||||
grf.setColor((255 - 255 * i / N), 255 * i / N, 0);
|
||||
}
|
||||
if (ar == 14) {
|
||||
grf.setColor(bc, 255, (255 - 255 * i / N));
|
||||
}
|
||||
if (T==0) grf.drawLine((int) x, (int) y, (int) tx, (int) ty);
|
||||
if (T==1) grf.fillArc((int) tx, (int) ty, (int) x, (int) y, 0, 360);
|
||||
if (T==2) grf.fillRect((int) tx, (int) ty, (int) x, (int) y);
|
||||
if (T==3) grf.drawString(time2fileName(),(int) x, (int) y, 20);
|
||||
x = tx;
|
||||
y = ty;
|
||||
}
|
||||
}
|
||||
int[] pixelArray = new int[width * height];
|
||||
for (int io = 0; io < pixelArray.length; io++) {
|
||||
pixelArray[io] = (int) (100-K << 24) | (0 << 16) | (0 << 8) | 0;
|
||||
}
|
||||
grf.drawRGB(pixelArray, 0, width, 0, 0, width, height, true);
|
||||
}
|
||||
}
|
568
src/Lib_effects.java
Normal file
568
src/Lib_effects.java
Normal file
@ -0,0 +1,568 @@
|
||||
|
||||
import java.util.Random;
|
||||
import javax.microedition.lcdui.*;
|
||||
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class Lib_effects {
|
||||
|
||||
private final static int CALPHA = 0, CRED = 1, CGREEN = 2, CBLUE = 3;
|
||||
private static int[] cshift = {24, 16, 8, 0};
|
||||
private static int[] cmask = {~((1 << 24) - 1), (1 << 24) - (1 << 16), (1 << 16) - 256, 255};
|
||||
|
||||
public static int red(int v) {return (v&cmask[CRED])>>>cshift[CRED];}
|
||||
public static int green(int v) {return (v&cmask[CGREEN])>>>cshift[CGREEN];}
|
||||
public static int blue(int v) {return (v&cmask[CBLUE])>>>cshift[CBLUE];}
|
||||
public static int alpha(int v) {return (v&cmask[CALPHA])>>>cshift[CALPHA];}
|
||||
|
||||
public static int avg(int v, int r, int g, int b, int s) {
|
||||
return (r * red(v) + g * green(v) + b * blue(v)) / s;
|
||||
}
|
||||
|
||||
public static int avg(int v) {
|
||||
return avg(v, 299, 587, 114, 1000);
|
||||
}
|
||||
|
||||
public static Image band(Image img, int[] colors) {
|
||||
int l = colors.length;
|
||||
int[] data = new int[img.getWidth() * img.getHeight()];
|
||||
img.getRGB(data, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = colors[(avg(data[i]) * l) / 256];
|
||||
}
|
||||
return Image.createRGBImage(data, img.getWidth(), img.getHeight(), true);
|
||||
}
|
||||
|
||||
public static int[][] Array2d(int[] d1, int w, int h) {
|
||||
int[][] d2 = new int[h][w];
|
||||
for (int i = 0; i < h; i++) {
|
||||
for (int j = 0; j < w; j++) {
|
||||
d2[i][j]=d1[i*h+j];
|
||||
}
|
||||
}
|
||||
return d2;
|
||||
}
|
||||
|
||||
public static int[] Array1d(int[][] d1, int w, int h) {
|
||||
int[] d2 = new int[h*w];
|
||||
for (int i = 0; i < h; i++) {
|
||||
for (int j = 0; j < w; j++) {
|
||||
d2[i*h+j]=d1[i][j];
|
||||
}
|
||||
}
|
||||
return d2;
|
||||
}
|
||||
|
||||
|
||||
public static Image fill(Image img, int x, int y, int r, int g, int b) {
|
||||
int[] pixel = new int[img.getWidth() * img.getHeight()];
|
||||
img.getRGB(pixel, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
|
||||
int[][] ar2 = new int[img.getHeight()][img.getWidth()]; // ôðàêòàëû åùå äîáàâèòü
|
||||
return Image.createRGBImage(pixel, img.getWidth(), img.getHeight(), true);
|
||||
}
|
||||
|
||||
public static int color(int alpha, int r, int g, int b) {
|
||||
int result = (alpha << 24) + (r << 16) + (g << 8) + b;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Image effect(Image img, int mode) {
|
||||
int[] pixel = new int[img.getWidth() * img.getHeight()];
|
||||
img.getRGB(pixel, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
|
||||
if (mode == 5) { // Ñãëàæèâàíèå
|
||||
int imwi = img.getWidth();
|
||||
for (int io = 1 + imwi; io < pixel.length - 1 - imwi; io++) {
|
||||
int qa = (pixel[io] >> 24) & 0xff;
|
||||
|
||||
int qr00 = (pixel[io - 1 - imwi] >> 16) & 0xff;
|
||||
int qg00 = (pixel[io - 1 - imwi] >> 8) & 0xff;
|
||||
int qb00 = pixel[io - 1 - imwi] & 0xff;
|
||||
|
||||
int qr01 = (pixel[io - imwi] >> 16) & 0xff;
|
||||
int qg01 = (pixel[io - imwi] >> 8) & 0xff;
|
||||
int qb01 = pixel[io - imwi] & 0xff;
|
||||
|
||||
int qr02 = (pixel[io + 1 - imwi] >> 16) & 0xff;
|
||||
int qg02 = (pixel[io + 1 - imwi] >> 8) & 0xff;
|
||||
int qb02 = pixel[io + 1 - imwi] & 0xff;
|
||||
|
||||
int qr10 = (pixel[io - 1] >> 16) & 0xff;
|
||||
int qg10 = (pixel[io - 1] >> 8) & 0xff;
|
||||
int qb10 = pixel[io - 1] & 0xff;
|
||||
|
||||
int qr11 = (pixel[io] >> 16) & 0xff;
|
||||
int qg11 = (pixel[io] >> 8) & 0xff;
|
||||
int qb11 = pixel[io] & 0xff;
|
||||
|
||||
int qr12 = (pixel[io + 1] >> 16) & 0xff;
|
||||
int qg12 = (pixel[io + 1] >> 8) & 0xff;
|
||||
int qb12 = pixel[io + 1] & 0xff;
|
||||
|
||||
int qr20 = (pixel[io - 1 + imwi] >> 16) & 0xff;
|
||||
int qg20 = (pixel[io - 1 + imwi] >> 8) & 0xff;
|
||||
int qb20 = pixel[io - 1 + imwi] & 0xff;
|
||||
|
||||
int qr21 = (pixel[io + imwi] >> 16) & 0xff;
|
||||
int qg21 = (pixel[io + imwi] >> 8) & 0xff;
|
||||
int qb21 = pixel[io + imwi] & 0xff;
|
||||
|
||||
int qr22 = (pixel[io + 1 + imwi] >> 16) & 0xff;
|
||||
int qg22 = (pixel[io + 1 + imwi] >> 8) & 0xff;
|
||||
int qb22 = pixel[io + 1 + imwi] & 0xff;
|
||||
qr11 = (qr00 + qr01 + qr02 + qr10 + qr11 + qr12 + qr20 + qr21 + qr22) / 9;
|
||||
qg11 = (qg00 + qg01 + qg02 + qg10 + qg11 + qg12 + qg20 + qg21 + qg22) / 9;
|
||||
qb11 = (qb00 + qb01 + qb02 + qb10 + qb11 + qb12 + qb20 + qb21 + qb22) / 9;
|
||||
pixel[io] = (qa << 24) | (qr11 << 16) | (qg11 << 8) | qb11;
|
||||
}
|
||||
return Image.createRGBImage(pixel, img.getWidth(), img.getHeight(), true);
|
||||
}
|
||||
for (int io = 0; io < pixel.length; io++) {
|
||||
int qa = (pixel[io] >> 24) & 0xff;
|
||||
int qr = (pixel[io] >> 16) & 0xff;
|
||||
int qg = (pixel[io] >> 8) & 0xff;
|
||||
int qb = pixel[io] & 0xff;
|
||||
if (mode == 0) { // îáåñöâå÷
|
||||
int qs = qr + qg + qb;
|
||||
qr = qs / 3;
|
||||
qg = qs / 3;
|
||||
qb = qs / 3;
|
||||
}
|
||||
if (mode == 1) { // íåãàòèâ
|
||||
qr = 255 - qr;
|
||||
qg = 255 - qg;
|
||||
qb = 255 - qb;
|
||||
}
|
||||
if (mode == 2) { // çàòåìíåíèå
|
||||
qr = qr - 20 < 0 ? 0 : qr - 20;
|
||||
qg = qg - 20 < 0 ? 0 : qg - 20;
|
||||
qb = qb - 20 < 0 ? 0 : qb - 20;
|
||||
}
|
||||
if (mode == 3) { // îñâåòëåíèå
|
||||
qr = qr + 20 > 255 ? 255 : qr + 20;
|
||||
qg = qg + 20 > 255 ? 255 : qg + 20;
|
||||
qb = qb + 20 > 255 ? 255 : qb + 20;
|
||||
}
|
||||
if (mode == 4) { // ñåïèÿ
|
||||
int depth = 40;
|
||||
qb = (qr + qg + qb) / 3;
|
||||
qr = qb + depth * 2;
|
||||
qg = qb + depth;
|
||||
if (qr > 255) {
|
||||
qr = 255;
|
||||
}
|
||||
if (qg > 255) {
|
||||
qg = 255;
|
||||
}
|
||||
}
|
||||
if (mode == 6) { // Èñêàæåíèå
|
||||
Random rnd = new Random();
|
||||
if (((rnd.nextInt() >>> 1) % 10) < 4 && io > 0) {
|
||||
pixel[io-1] = (qa << 24) | (qr << 16) | (qg << 8) | qb;
|
||||
qa = (pixel[io - 1] >> 24) & 0xff;
|
||||
qr = (pixel[io - 1] >> 16) & 0xff;
|
||||
qg = (pixel[io - 1] >> 8) & 0xff;
|
||||
qb = pixel[io - 1] & 0xff;
|
||||
}
|
||||
}
|
||||
if (mode == 7) { // ÷/á
|
||||
if ((qr+qg+qb)/3 > 128) {
|
||||
qr=qg=qb=255;
|
||||
}else {
|
||||
qr=qg=qb=0;
|
||||
}
|
||||
}
|
||||
pixel[io] = (qa << 24) | (qr << 16) | (qg << 8) | qb;
|
||||
|
||||
}
|
||||
return Image.createRGBImage(pixel, img.getWidth(), img.getHeight(), true);
|
||||
}
|
||||
|
||||
public static Image change(Image img, int ch, int val) {
|
||||
int[] pixel = new int[img.getWidth() * img.getHeight()];
|
||||
img.getRGB(pixel, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
|
||||
for (int io = 0; io < pixel.length; io++) {
|
||||
int qa = (pixel[io] >> 24) & 0xff;
|
||||
int qr = (pixel[io] >> 16) & 0xff;
|
||||
int qg = (pixel[io] >> 8) & 0xff;
|
||||
int qb = pixel[io] & 0xff;
|
||||
|
||||
if (ch == 0) { // alpha
|
||||
qa = qa + val;
|
||||
if (qa > 255) {
|
||||
qa = 255;
|
||||
}
|
||||
if (qa < 0) {
|
||||
qa = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch == 1) { // red
|
||||
qr = qr + val;
|
||||
if (qr > 255) {
|
||||
qr = 255;
|
||||
}
|
||||
if (qr < 0) {
|
||||
qr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch == 2) { // green
|
||||
qg = qg + val;
|
||||
if (qg > 255) {
|
||||
qg = 255;
|
||||
}
|
||||
if (qg < 0) {
|
||||
qg = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch == 3) { // blue
|
||||
qb = qb + val;
|
||||
if (qb > 255) {
|
||||
qb = 255;
|
||||
}
|
||||
if (qb < 0) {
|
||||
qb = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pixel[io] = (qa << 24) | (qr << 16) | (qg << 8) | qb;
|
||||
}
|
||||
return Image.createRGBImage(pixel, img.getWidth(), img.getHeight(), true);
|
||||
}
|
||||
|
||||
public static int get(Image img, int x, int y, int ch) {
|
||||
int[] pixel = new int[img.getWidth() * img.getHeight()];
|
||||
img.getRGB(pixel, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
|
||||
|
||||
int qa = (pixel[y * img.getWidth() + x] >> 24) & 0xff;
|
||||
int qr = (pixel[y * img.getWidth() + x] >> 16) & 0xff;
|
||||
int qg = (pixel[y * img.getWidth() + x] >> 8) & 0xff;
|
||||
int qb = pixel[y * img.getWidth() + x] & 0xff;
|
||||
|
||||
if (ch == 0) { // alpha
|
||||
return qa;
|
||||
}
|
||||
|
||||
if (ch == 1) { // red
|
||||
return qr;
|
||||
}
|
||||
|
||||
if (ch == 2) { // green
|
||||
return qg;
|
||||
}
|
||||
|
||||
if (ch == 3) { // blue
|
||||
return qb;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static Image saturation(Image img, int ch) {
|
||||
int[] pixelArray = new int[img.getWidth() * img.getHeight()];
|
||||
int Amount = ch;
|
||||
img.getRGB(pixelArray, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
|
||||
for (int io = 0; io < pixelArray.length; io++) {
|
||||
int qa = (pixelArray[io] >> 24) & 0xff;
|
||||
int qr = (pixelArray[io] >> 16) & 0xff;
|
||||
int qg = (pixelArray[io] >> 8) & 0xff;
|
||||
int qb = pixelArray[io] & 0xff;
|
||||
int gray = (qr + qg + qb) / 3;
|
||||
qr = (gray + (((qr - gray) * Amount) / 255));
|
||||
qg = (gray + (((qg - gray) * Amount) / 255));
|
||||
qb = (gray + (((qb - gray) * Amount) / 255));
|
||||
pixelArray[io] = (qa << 24) | (qr << 16) | (qg << 8) | qb;
|
||||
}
|
||||
return Image.createRGBImage(pixelArray, img.getWidth(), img.getHeight(), true);
|
||||
}
|
||||
|
||||
public static Image changecolor(Image img, int r1, int g1, int b1, int a2, int r2, int g2, int b2) {
|
||||
int[] pixelArray = new int[img.getWidth() * img.getHeight()];
|
||||
img.getRGB(pixelArray, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
|
||||
for (int io = 0; io < pixelArray.length; io++) {
|
||||
int qa = (pixelArray[io] >> 24) & 0xff;
|
||||
int qr = (pixelArray[io] >> 16) & 0xff;
|
||||
int qg = (pixelArray[io] >> 8) & 0xff;
|
||||
int qb = pixelArray[io] & 0xff;
|
||||
if (qr==r1 && qg==g1 && qb==b1 && qa!=0) {
|
||||
qa=a2; qr=r2; qg=g2; qb=b2;
|
||||
}
|
||||
pixelArray[io] = (qa << 24) | (qr << 16) | (qg << 8) | qb;
|
||||
}
|
||||
return Image.createRGBImage(pixelArray, img.getWidth(), img.getHeight(), true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Image brightness(Image img, int difa, int difr, int difg, int difb) {
|
||||
return linear(img, 1, difr, 1, difg, 1, difb, 1, difa);
|
||||
}
|
||||
|
||||
public static Image contrast(Image img, double sr,double sg,double sb,double sa) {
|
||||
return linear(img, sr,128-128*sr,sg,128-128*sg,sb,128-128*sb,sa,128-128*sa);
|
||||
}
|
||||
|
||||
public static Image gamma(Image img, double ga, double gr, double gg, double gb) {
|
||||
int v, r, g, b, a;
|
||||
gr=1/gr;gg=1/gg;gb=1/gb;ga=1/ga;
|
||||
int[] pixel = new int[img.getWidth() * img.getHeight()];
|
||||
img.getRGB(pixel, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
|
||||
for (int i = 0; i < pixel.length; i++) {
|
||||
v = pixel[i];
|
||||
r = range(0, 256, 255 * pow((red(v) / 255.0), gr));
|
||||
g = range(0, 256, 255 * pow((green(v) / 255.0), gg));
|
||||
b = range(0, 256, 255 * pow((blue(v) / 255.0), gb));
|
||||
a = range(0, 256, 255 * pow((alpha(v) / 255.0), ga));
|
||||
pixel[i] = color(a, r, g, b);
|
||||
}
|
||||
return Image.createRGBImage(pixel, img.getWidth(), img.getHeight(), true);
|
||||
}
|
||||
|
||||
private static Image linear(Image img, double sr, double dr, double sg, double dg,
|
||||
double sb, double db, double sa, double da) {
|
||||
int[] pixel = new int[img.getWidth() * img.getHeight()];
|
||||
img.getRGB(pixel, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
|
||||
int v, r, g, b, a;
|
||||
for (int i = 0; i < pixel.length; i++) {
|
||||
v = pixel[i];
|
||||
r = range(0, 256, red(v) * sr + dr);
|
||||
g = range(0, 256, green(v) * sg + dg);
|
||||
b = range(0, 256, blue(v) * sb + db);
|
||||
a = range(0, 256, alpha(v) * sa + da);
|
||||
pixel[i] = color(a, r, g, b);
|
||||
}
|
||||
return Image.createRGBImage(pixel, img.getWidth(), img.getHeight(), true);
|
||||
}
|
||||
|
||||
private static int range(int min, int max, double dv) {
|
||||
int v = (int) dv;
|
||||
if (v < min) {
|
||||
return min;
|
||||
}
|
||||
return (v >= max) ? max - 1 : (int) v;
|
||||
}
|
||||
|
||||
/** Square root from 3 */
|
||||
final static public double SQRT3 = 1.732050807568877294;
|
||||
/** Log10 constant */
|
||||
final static public double LOG10 = 2.302585092994045684;
|
||||
/** ln(0.5) constant */
|
||||
final static public double LOGdiv2 = -0.6931471805599453094;
|
||||
//
|
||||
static public double acos(double x)
|
||||
{
|
||||
double f=asin(x);
|
||||
if(f==Double.NaN)
|
||||
return f;
|
||||
return Math.PI/2-f;
|
||||
}
|
||||
|
||||
static public double asin(double x)
|
||||
{
|
||||
if( x<-1. || x>1. ) return Double.NaN;
|
||||
if( x==-1. ) return -Math.PI/2;
|
||||
if( x==1 ) return Math.PI/2;
|
||||
return atan(x/Math.sqrt(1-x*x));
|
||||
}
|
||||
|
||||
static public double atan(double x)
|
||||
{
|
||||
boolean signChange=false;
|
||||
boolean Invert=false;
|
||||
int sp=0;
|
||||
double x2, a;
|
||||
// check up the sign change
|
||||
if(x<0.)
|
||||
{
|
||||
x=-x;
|
||||
signChange=true;
|
||||
}
|
||||
// check up the invertation
|
||||
if(x>1.)
|
||||
{
|
||||
x=1/x;
|
||||
Invert=true;
|
||||
}
|
||||
// process shrinking the domain until x<PI/12
|
||||
while(x>Math.PI/12)
|
||||
{
|
||||
sp++;
|
||||
a=x+SQRT3;
|
||||
a=1/a;
|
||||
x=x*SQRT3;
|
||||
x=x-1;
|
||||
x=x*a;
|
||||
}
|
||||
// calculation core
|
||||
x2=x*x;
|
||||
a=x2+1.4087812;
|
||||
a=0.55913709/a;
|
||||
a=a+0.60310579;
|
||||
a=a-(x2*0.05160454);
|
||||
a=a*x;
|
||||
// process until sp=0
|
||||
while(sp>0)
|
||||
{
|
||||
a=a+Math.PI/6;
|
||||
sp--;
|
||||
}
|
||||
// invertation took place
|
||||
if(Invert) a=Math.PI/2-a;
|
||||
// sign change took place
|
||||
if(signChange) a=-a;
|
||||
//
|
||||
return a;
|
||||
}
|
||||
|
||||
static public double atan2(double y, double x)
|
||||
{
|
||||
// if x=y=0
|
||||
if(y==0. && x==0.)
|
||||
return 0.;
|
||||
// if x>0 atan(y/x)
|
||||
if(x>0.)
|
||||
return atan(y/x);
|
||||
// if x<0 sign(y)*(pi - atan(|y/x|))
|
||||
if(x<0.)
|
||||
{
|
||||
if(y<0.)
|
||||
return -(Math.PI-atan(y/x));
|
||||
else
|
||||
return Math.PI-atan(-y/x);
|
||||
}
|
||||
// if x=0 y!=0 sign(y)*pi/2
|
||||
if(y<0.)
|
||||
return -Math.PI/2.;
|
||||
else
|
||||
return Math.PI/2.;
|
||||
}
|
||||
|
||||
static public double exp(double x)
|
||||
{
|
||||
if(x==0.)
|
||||
return 1.;
|
||||
//
|
||||
double f=1;
|
||||
long d=1;
|
||||
double k;
|
||||
boolean isless=(x<0.);
|
||||
if(isless)
|
||||
x=-x;
|
||||
k=x/d;
|
||||
//
|
||||
for(long i=2; i<50; i++)
|
||||
{
|
||||
f=f+k;
|
||||
k=k*x/i;
|
||||
}
|
||||
//
|
||||
if(isless)
|
||||
return 1/f;
|
||||
else
|
||||
return f;
|
||||
}
|
||||
|
||||
static private double _log(double x)
|
||||
{
|
||||
if(!(x>0.))
|
||||
return Double.NaN;
|
||||
//
|
||||
double f=0.0;
|
||||
//
|
||||
int appendix=0;
|
||||
while(x>0.0 && x<=1.0)
|
||||
{
|
||||
x*=2.0;
|
||||
appendix++;
|
||||
}
|
||||
//
|
||||
x/=2.0;
|
||||
appendix--;
|
||||
//
|
||||
double y1=x-1.;
|
||||
double y2=x+1.;
|
||||
double y=y1/y2;
|
||||
//
|
||||
double k=y;
|
||||
y2=k*y;
|
||||
//
|
||||
for(long i=1; i<50; i+=2)
|
||||
{
|
||||
f+=k/i;
|
||||
k*=y2;
|
||||
}
|
||||
//
|
||||
f*=2.0;
|
||||
for(int i=0; i<appendix; i++)
|
||||
f+=LOGdiv2;
|
||||
//
|
||||
return f;
|
||||
}
|
||||
|
||||
static public double log(double x)
|
||||
{
|
||||
if(!(x>0.))
|
||||
return Double.NaN;
|
||||
//
|
||||
if(x==1.0)
|
||||
return 0.0;
|
||||
// Argument of _log must be (0; 1]
|
||||
if (x>1.)
|
||||
{
|
||||
x=1/x;
|
||||
return -_log(x);
|
||||
};
|
||||
//
|
||||
return _log(x);
|
||||
}
|
||||
|
||||
static public double log10(double x)
|
||||
{
|
||||
return log(x)/LOG10;
|
||||
}
|
||||
|
||||
|
||||
static public double pow(double x, double y)
|
||||
{
|
||||
if(y==0.)
|
||||
return 1.;
|
||||
if(y==1.)
|
||||
return x;
|
||||
if(x==0.)
|
||||
return 0.;
|
||||
if(x==1.)
|
||||
return 1.;
|
||||
//
|
||||
long l=(long)Math.floor(y);
|
||||
boolean integerValue=(y==(double)l);
|
||||
//
|
||||
if(integerValue)
|
||||
{
|
||||
boolean neg=false;
|
||||
if(y<0.)
|
||||
neg=true;
|
||||
//
|
||||
double result=x;
|
||||
for(long i=1; i<(neg?-l:l); i++)
|
||||
result=result*x;
|
||||
//
|
||||
if(neg)
|
||||
return 1./result;
|
||||
else
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(x>0.)
|
||||
return exp(y*log(x));
|
||||
else
|
||||
return Double.NaN;
|
||||
}
|
||||
}
|
||||
}
|
61
src/Rms.java
Normal file
61
src/Rms.java
Normal file
@ -0,0 +1,61 @@
|
||||
import java.io.*;
|
||||
import javax.microedition.rms.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class Rms {
|
||||
|
||||
private static final String rmsName = "VisualME";
|
||||
private static RecordStore rmsStore;
|
||||
public static boolean firstStart = true;
|
||||
public static String language = "en";
|
||||
|
||||
public static void saveOptions() {
|
||||
if (rmsStore != null) {
|
||||
byte[] options = null;
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(baos);
|
||||
dos.writeBoolean(firstStart);
|
||||
dos.writeUTF (language);
|
||||
dos.flush();
|
||||
options = baos.toByteArray();
|
||||
dos.close();
|
||||
rmsStore.setRecord(1, options, 0, options.length);
|
||||
} catch (InvalidRecordIDException ridex) {
|
||||
try {
|
||||
rmsStore.addRecord(options, 0, options.length);
|
||||
} catch (RecordStoreException ex) {
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
if (rmsStore != null) {
|
||||
try {
|
||||
rmsStore.closeRecordStore();
|
||||
rmsStore = null;
|
||||
} catch (RecordStoreException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void restoreOptions() {
|
||||
try {
|
||||
rmsStore = RecordStore.openRecordStore(rmsName, true);
|
||||
} catch (RecordStoreException ex) {
|
||||
rmsStore = null;
|
||||
}
|
||||
if (rmsStore != null) {
|
||||
try {
|
||||
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(rmsStore.getRecord(1)));
|
||||
firstStart = dis.readBoolean();
|
||||
language = dis.readUTF ();
|
||||
dis.close();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
94
src/VisualME.java
Normal file
94
src/VisualME.java
Normal file
@ -0,0 +1,94 @@
|
||||
|
||||
import javax.microedition.lcdui.*;
|
||||
import javax.microedition.midlet.MIDlet;
|
||||
|
||||
public class VisualME extends MIDlet implements CommandListener {
|
||||
|
||||
public Display display;
|
||||
public static VisualME midlet;
|
||||
private TextField tf1 = new TextField("Êîë-âî âåòîê", "15", 3, TextField.NUMERIC);
|
||||
private TextField tf2 = new TextField("Êîë-âî çâåíüåâ (ãèáêîñòü)", "20", 3, TextField.NUMERIC);
|
||||
private TextField tf3 = new TextField("Ðàçìûòèå", "60", 2, TextField.NUMERIC);
|
||||
private TextField tf4 = new TextField("Ïðîïîðöèè ýêðàíà", "1", 1, TextField.NUMERIC);
|
||||
private TextField tf5 = new TextField("Ñêîðîñòü", "1", 1, TextField.NUMERIC);
|
||||
private ChoiceGroup ch1 = new ChoiceGroup("", Choice.MULTIPLE);
|
||||
private ChoiceGroup ch2 = new ChoiceGroup("Ôèëüòðû", Choice.POPUP);
|
||||
private ChoiceGroup ch3 = new ChoiceGroup("Ôèãóðû", Choice.POPUP);
|
||||
private Command okCommand = new Command("Ok", Command.OK, 0);
|
||||
public Form Param;
|
||||
public static int cd, ii;
|
||||
public int Sw, Nw, Kw, Lw, Cw, Tw, Uw;
|
||||
public boolean bl, dl, vl, fl, vbl;
|
||||
|
||||
public VisualME() {
|
||||
midlet = this;
|
||||
}
|
||||
|
||||
public void pauseApp() {
|
||||
Rms.saveOptions();
|
||||
}
|
||||
|
||||
public void destroyApp(boolean unconditional) {
|
||||
if(Rms.firstStart) Rms.firstStart=false;
|
||||
Rms.saveOptions();
|
||||
notifyDestroyed();
|
||||
}
|
||||
|
||||
public void startApp() {
|
||||
Rms.restoreOptions();
|
||||
Param = new Form("Visual by aNNiMON");
|
||||
Param.append(tf1);
|
||||
Param.append(tf2);
|
||||
Param.append(tf3);
|
||||
Param.append(tf4);
|
||||
Param.append(tf5);
|
||||
ch1.append("Ïîäñâåòêà", null);
|
||||
ch1.append("Àâòîñìåíà âèçóàëèçàöèè", null);
|
||||
ch1.append("Àâòîñìåíà ýôôåêòîâ", null);
|
||||
ch1.append("Àâòîñìåíà ôèãóð", null);
|
||||
ch1.append("Âèáðàöèÿ", null);
|
||||
ch1.setSelectedIndex(0, false);
|
||||
ch1.setSelectedIndex(1, false);
|
||||
ch1.setSelectedIndex(2, false);
|
||||
ch1.setSelectedIndex(3, false);
|
||||
ch1.setSelectedIndex(4, false);
|
||||
ch2.append("Íåò", null);
|
||||
ch2.append("Îáåñöâåòèòü", null);
|
||||
ch2.append("Íåãàòèâ", null);
|
||||
ch2.append("Ñãëàæèâàíèå", null);
|
||||
ch2.append("Cåïèÿ", null);
|
||||
ch2.append("×åðíî-áåëûé", null);
|
||||
ch2.append("ßðêîñòü", null);
|
||||
ch3.append("Ëèíèè", null);
|
||||
ch3.append("Ýëëèïñû", null);
|
||||
ch3.append("Êâàäðàòû", null);
|
||||
ch3.append("Âðåìÿ", null);
|
||||
Param.append(ch1);
|
||||
Param.append(ch2);
|
||||
Param.append(ch3);
|
||||
Param.addCommand(okCommand);
|
||||
Param.setCommandListener(this);
|
||||
display = Display.getDisplay(this);
|
||||
display.setCurrent(Param);
|
||||
}
|
||||
|
||||
public void commandAction(Command c, Displayable d) {
|
||||
if (d == Param && c == okCommand) {
|
||||
Cw = ((ChoiceGroup) ch2).getSelectedIndex();
|
||||
Tw = ((ChoiceGroup) ch3).getSelectedIndex();
|
||||
bl = ch1.isSelected(0);
|
||||
dl = ch1.isSelected(1);
|
||||
vl = ch1.isSelected(2);
|
||||
fl = ch1.isSelected(3);
|
||||
vbl = ch1.isSelected(4);
|
||||
Sw = (int) Integer.parseInt(tf1.getString());
|
||||
Nw = (int) Integer.parseInt(tf2.getString());
|
||||
Kw = (int) Integer.parseInt(tf3.getString());
|
||||
Lw = (int) Integer.parseInt(tf4.getString());
|
||||
Uw = (int) Integer.parseInt(tf5.getString());
|
||||
Engine visual = new Engine();
|
||||
display = Display.getDisplay(this);
|
||||
display.setCurrent(visual);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user