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

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,84 @@
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.Pixmap.Format;
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 fileHandle = Gdx.files.internal("badlogic.bmp");
etalon = new Pixmap(fileHandle);
etalonTexture = new Texture(etalon);
pixmap = new Pixmap(etalon.getWidth(), etalon.getHeight(), Format.RGB888);
buffer = new int[etalon.getWidth()][etalon.getHeight()][3];
for (int i = 0; i < pixmap.getWidth(); ++i) {
for (int j = 0; j < pixmap.getHeight(); ++j) {
buffer[i][j][0] = 0xff;
buffer[i][j][1] = 0xff;
buffer[i][j][2] = 0xff;
}
}
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];
}
if (etalonGreen < buffer[i][j][1]) {
--buffer[i][j][1];
}
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();
}
}