public void postRender(Bitmap screenBitmap, Graphics2D g2d) { // int[] pixels = screenBitmap.pixels; // for (int i = 0; i < pixels.length; i++) { // int x = i % screenBitmap.w - GameComponent.WIDTH / 2; int y = i / screenBitmap.w - GameComponent.HEIGHT / 2; // // x , // , 0..255 double angle = (x / (double) screenBitmap.h * y / (double) screenBitmap.h) * Math.PI * 2.0 * (255 - dayFactor) / 255.0; // int xx = (int) (x * Math.cos(angle) - y * Math.sin(angle)) + GameComponent.WIDTH / 2; int yy = (int) (y * Math.cos(angle) + x * Math.sin(angle)) + GameComponent.HEIGHT / 2; // , if (xx >= 0 && yy >= 0 && xx < screenBitmap.w && yy < screenBitmap.h) { int c = pixels[xx + yy * screenBitmap.w]; int r = (c >> 16) & 0xff; int g = (c >> 8) & 0xff; int b = (c >> 0) & 0xff; // gray scale, //https://ru.wikipedia.org/wiki/%D0%9E%D1%82%D1%82%D0%B5%D0%BD%D0%BA%D0%B8_%D1%81%D0%B5%D1%80%D0%BE%D0%B3%D0%BE int m = (r * 30 + g * 59 + b * 11) / 100; // r = (r + m) / 2 * dayFactor / 255; g = (g + m) / 2 * dayFactor / 255; b = (b + m) / 2 * dayFactor / 255; // , postData[i] = 0xff << 24 | r << 16 | g << 8 | b; } else { // , " " int rnd = (int) (random.nextDouble() * 16); postData[i] = 0xff << 24 | (0x4C + rnd) << 16 | rnd << 8 | rnd; } } // , . for (int i = 0; i < postData.length; i++) { pixels[i] = postData[i]; } g2d.setColor(Color.WHITE); g2d.drawString("score: " + score, 10, GameComponent.HEIGHT - 10); }
// 1616, 16 public static BufferedImage[] generate(int[] t0, int[] t1, int sz) { double iSz = 1.0 / sz; BufferedImage[] result = new BufferedImage[16]; for (int i = 0; i < 16; i++) { // result[i] = new BufferedImage(sz, sz, BufferedImage.TYPE_INT_RGB); int[] data = new int[sz * sz]; // 4 // , i 4 int a = (i >> 0) & 1; int b = (i >> 1) & 1; int c = (i >> 2) & 1; int d = (i >> 3) & 1; // for (int y = 0; y < sz; y++) { double yp = y * iSz; for (int x = 0; x < sz; x++) { double xp = x * iSz; // ab t = xp double ab = a + (b - a) * xp; // cd t = xp double cd = c + (d - c) * xp; // ab cd t = yp double val = ab + (cd - ab) * yp; //... - val // , val if (val < 0) val = 0; if (val > 1.0) val = 1.0; // 1 2 t = val int c0 = t0[x + y * sz]; int c1 = t1[x + y * sz]; int col = Mth.lerpRGB(c0, c1, val); // data[x + y * sz] = col; } } result[i].setRGB(0, 0, sz, sz, data, 0, sz); } return result; }
public void render(Graphics2D g2d, Level level, int x, int y, int xOffs, int yOffs) { int xx = x >> 4; int yy = y >> 4; int t = 0; // if (level.getTile(xx, yy) != Tile.water) t += 1; // if (level.getTile(xx + 1, yy) != Tile.water) t += 2; // if (level.getTile(xx, yy + 1) != Tile.water) t += 4; // if (level.getTile(xx + 1, yy + 1) != Tile.water) t += 8; g2d.drawImage(Art.waterToGrassTiles[t], x - xOffs, y - yOffs, null); }
Source: https://habr.com/ru/post/269527/
All Articles