4
This commit is contained in:
parent
e04a789207
commit
e586e8230c
@ -40,8 +40,13 @@ public class Background {
|
||||
0xA0000000, //22:00
|
||||
0xB0000000, //23:00
|
||||
};
|
||||
|
||||
// Сколькигранная звезда?
|
||||
private static final int STAR_POINTS = 5;
|
||||
|
||||
/* массив пикселей для затемнения экрана */
|
||||
private int[] night;
|
||||
private int hour;
|
||||
|
||||
private int w, h;
|
||||
|
||||
@ -54,6 +59,7 @@ public class Background {
|
||||
|
||||
/* Установить затемнение в зависимости от времени суток */
|
||||
public final void setNight(int hour) {
|
||||
this.hour = hour;
|
||||
if (night[0] == colorsNight[hour]) return;
|
||||
for (int i = 0; i < night.length; i++)
|
||||
night[i] = colorsNight[hour];
|
||||
@ -65,11 +71,27 @@ public class Background {
|
||||
Image img = Image.createImage(w, h);
|
||||
Graphics g = img.getGraphics();
|
||||
// Рисуем небо
|
||||
Util.drawVGradient(g, 0x1D75F9, 0x8AC8EA, 0, 0, w, h-h/3);
|
||||
Util.drawVGradient(g, 0x0052D6, 0x67A5C7, 0, 0, w, h-h/3);
|
||||
// Снежный покров
|
||||
Util.drawVGradient(g, 0xBEDFE2, 0xE8FFF7, 0, h-h/3, w, h/3);
|
||||
Util.drawVGradient(g, 0x9BBCBF, 0xC5DCD4, 0, h-h/3, w, h/3);
|
||||
// Елка
|
||||
drawTree(g, w/2, h-h/10, h/2);
|
||||
return img;
|
||||
}
|
||||
|
||||
/*
|
||||
* Звезда
|
||||
*/
|
||||
public void preDraw(Graphics g) {
|
||||
int color = 0xFF6666;
|
||||
if ((hour > 6) && (hour < 19)) color = 0x994444;
|
||||
g.setColor(color);
|
||||
drawStar(g, w/2, 2*h/5, g.getClipWidth()/20, 5);
|
||||
g.setColor(color-0x002222);
|
||||
drawStar(g, w/2, 2*h/5, g.getClipWidth()/25, 5);
|
||||
g.setColor(color-0x004444);
|
||||
drawStar(g, w/2, 2*h/5, g.getClipWidth()/30, 5);
|
||||
}
|
||||
|
||||
/*
|
||||
* Пост обработка. Время дня.
|
||||
@ -78,4 +100,39 @@ public class Background {
|
||||
g.drawRGB(night, 0, w, 0, 0, w, h/2, true);
|
||||
g.drawRGB(night, 0, w, 0, h/2, w, h/2, true);
|
||||
}
|
||||
|
||||
/* Рисуем елку высотой height */
|
||||
private void drawTree(Graphics g, int x, int y, int height) {
|
||||
final int FLOOR = 8; // сколько ярусов у елки
|
||||
int ww = g.getClipWidth() / 30;
|
||||
// Ствол
|
||||
g.setColor(0x785B30);
|
||||
int ws = ww * 2;
|
||||
g.fillRect(x-ws/2, y-ws, ws, 2*ws);
|
||||
g.setColor(0x00FF00);
|
||||
int hf = height / FLOOR;
|
||||
for (int i = 1; i < FLOOR; i++) {
|
||||
for (int j = -ww*i; j < ww*i; j++) {
|
||||
int green = (int) (220 + Util.random(-30, 30));
|
||||
g.setColor(0, green, 0);
|
||||
g.drawLine(x, y-height+hf*i-(hf-i), x+j, y-height+hf*(i+1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Рисуем звезду */
|
||||
private void drawStar(Graphics g, int cx, int cy, int radius, int points) {
|
||||
double angle = ((Math.PI*2)/points); //360/STAR_POINTS
|
||||
double pi2 = -Math.PI/2;
|
||||
for (int i = 0; i < STAR_POINTS; i++) {
|
||||
int x1 = cx + (int) (radius * Math.cos(angle*i+pi2));
|
||||
int y1 = cy + (int) (radius * Math.sin(angle*i+pi2));
|
||||
int xl = cx + (int) (radius/2 * Math.cos(angle*i-angle/2+pi2));
|
||||
int yl = cy + (int) (radius/2 * Math.sin(angle*i-angle/2+pi2));
|
||||
int xr = cx + (int) (radius/2 * Math.cos(angle*i+angle/2+pi2));
|
||||
int yr = cy + (int) (radius/2 * Math.sin(angle*i+angle/2+pi2));
|
||||
g.fillTriangle(xl, yl, x1, y1, xr, yr);
|
||||
}
|
||||
g.fillArc(cx-radius/2, cy-radius/2, radius, radius, 0, 360);
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class DrawParticles extends Canvas implements Runnable {
|
||||
setFullScreenMode(true);
|
||||
w = getWidth();
|
||||
h = getHeight();
|
||||
hour = 0;
|
||||
hour = 8;
|
||||
speed = MIN_SPEED;
|
||||
wind = (int) Util.random(0, 360);//250;
|
||||
Snow.setSpeed(speed);
|
||||
@ -44,12 +44,13 @@ public class DrawParticles extends Canvas implements Runnable {
|
||||
|
||||
public void paint(Graphics g) {
|
||||
g.drawImage(background, 0, 0, 20);
|
||||
bg.preDraw(g);
|
||||
// рисуем системы
|
||||
for (int i = 0; i < particles.size(); i++) {
|
||||
((ParticleSystem) particles.elementAt(i)).render(g);
|
||||
}
|
||||
// пост обработка. Ночь/день.
|
||||
bg.postDraw(g);
|
||||
// эффекты времени суток
|
||||
if (Parameters.timeEffects) bg.postDraw(g);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@ -63,7 +64,7 @@ public class DrawParticles extends Canvas implements Runnable {
|
||||
timeToChangeWind = System.currentTimeMillis() + (long)(Util.random(5, 30)*1000);
|
||||
}
|
||||
}
|
||||
bg.setNight(hour);
|
||||
if (Parameters.timeEffects) bg.setNight(hour);
|
||||
Snow.setWind(wind);
|
||||
repaint();
|
||||
try {
|
||||
|
@ -14,4 +14,7 @@ public class Parameters {
|
||||
|
||||
/* Автоматическое изменение ветра */
|
||||
public static boolean autoWind = true;
|
||||
|
||||
/* Эффекты времени суток */
|
||||
public static boolean timeEffects = true;
|
||||
}
|
||||
|
@ -77,7 +77,8 @@ public class Snow extends ParticleSystem {
|
||||
int w_y = (int) (window.y / particles[i].z);
|
||||
int w_w = (int) (window.w * particles[i].z);
|
||||
int wind_x = (int) (2*Math.cos(windAngle));
|
||||
if (y > window.h) {
|
||||
int y_max = (int) (window.h - (particles[i].z * window.h/3)/MAX_Z);
|
||||
if (y > y_max) {//if (y > window.h) {
|
||||
if (wind_x > 0) particles[i].x = Util.random(w_x-wind_x*10, w_w);
|
||||
else if (wind_x < 0) particles[i].x = Util.random(w_x, w_w-wind_x*10);
|
||||
else particles[i].x = Util.random(w_x, w_w);
|
||||
|
@ -109,6 +109,7 @@ public class Util {
|
||||
|
||||
return (ca << 24) | (cr << 16) | (cg << 8) | cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить цвет нужного канала в пикселе
|
||||
* @param argb пиксель
|
||||
|
Loading…
Reference in New Issue
Block a user