Добавил вторую главу занимательного программирования

This commit is contained in:
2025-12-15 00:36:33 +01:00
parent c1147629f7
commit 2878f1e34c
128 changed files with 6744 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project.name = appName + "-core"

View File

@@ -0,0 +1,92 @@
package net.caraus.fadein;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.ScreenUtils;
public class FadeIn extends ApplicationAdapter {
SpriteBatch batch;
Texture etalonTexture;
Pixmap etalon;
Pixmap pixmap;
Texture img;
int[][][] buffer;
@Override
public void create () {
batch = new SpriteBatch();
FileHandle etalonHandle = Gdx.files.internal("badlogic.bmp");
etalon = new Pixmap(etalonHandle);
etalonTexture = new Texture(etalon);
FileHandle imgHandle = Gdx.files.internal("background2.bmp");
pixmap = new Pixmap(imgHandle);
buffer = new int[pixmap.getWidth()][pixmap.getHeight()][3];
for (int i = 0; i < pixmap.getWidth(); ++i) {
for (int j = 0; j < pixmap.getHeight(); ++j) {
int pixmapPixel = pixmap.getPixel(i, j);
buffer[i][j][0] = (pixmapPixel >> 24) & 0xff; // Red.
buffer[i][j][1] = (pixmapPixel >> 16) & 0xff; // Green.
buffer[i][j][2] = (pixmapPixel >> 8) & 0xff; // Blue.
}
}
img = new Texture(pixmap);
}
@Override
public void render () {
ScreenUtils.clear(1, 0, 0, 1);
for (int i = 0; i < pixmap.getWidth(); ++i) {
for (int j = 0; j < pixmap.getHeight(); ++j) {
int etalonPixel = etalon.getPixel(i, j);
int etalonRed = (etalonPixel >> 24) & 0xff;
int etalonGreen = (etalonPixel >> 16) & 0xff;
int etalonBlue = (etalonPixel >> 8) & 0xff;
if (etalonRed < buffer[i][j][0]) {
--buffer[i][j][0];
} else if (etalonRed > buffer[i][j][0]) {
++buffer[i][j][0];
}
if (etalonGreen < buffer[i][j][1]) {
--buffer[i][j][1];
} else if (etalonGreen > buffer[i][j][1]) {
++buffer[i][j][1];
}
if (etalonBlue < buffer[i][j][2]) {
--buffer[i][j][2];
} else if (etalonBlue > buffer[i][j][2]) {
++buffer[i][j][2];
}
pixmap.setColor((buffer[i][j][0] << 24) | (buffer[i][j][1] << 16) | (buffer[i][j][2] << 8) | 0xff);
pixmap.drawPixel(i, j);
}
}
img.draw(pixmap, 0, 0);
batch.begin();
batch.draw(etalonTexture, 0, 0);
batch.draw(img, etalon.getWidth() + 15, 0);
batch.end();
}
@Override
public void dispose () {
batch.dispose();
etalonTexture.dispose();
etalon.dispose();
img.dispose();
pixmap.dispose();
}
}