Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.devtech.biome;
- import javax.imageio.ImageIO;
- import java.awt.Color;
- import java.awt.Desktop;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import static net.devtech.Rand.next;
- import static net.devtech.Rand.seed;
- public class BiomeGen {
- private final int power;
- private final int size;
- private final int mod;
- public BiomeGen(int power) {
- this.power = power;
- this.size = 1 << power;
- this.mod = size - 1;
- }
- public int getBiome(int x, int y) {
- int rx = x >>> power;
- int ry = y >>> power;
- int current = compute(rx, ry, x, y);
- int next;
- int offsetx = 0;
- int offsety = 0;
- if ((next = compute(rx - 1, ry, x, y)) < current) {
- offsetx = -1;
- offsety = 0;
- current = next;
- }
- if ((next = compute(rx, ry + 1, x, y)) < current) {
- offsetx = 0;
- offsety = 1;
- current = next;
- }
- if ((next = compute(rx + 1, ry, x, y)) < current) {
- offsetx = 1;
- offsety = 0;
- current = next;
- }
- if ((next = compute(rx, ry - 1, x, y)) < current) {
- offsetx = 0;
- offsety = -1;
- current = next;
- }
- if ((next = compute(rx - 1, ry - 1, x, y)) < current) {
- offsetx = -1;
- offsety = -1;
- current = next;
- }
- if ((next = compute(rx + 1, ry + 1, x, y)) < current) {
- offsetx = 1;
- offsety = 1;
- current = next;
- }
- if ((next = compute(rx + 1, ry - 1, x, y)) < current) {
- offsetx = 1;
- offsety = -1;
- current = next;
- }
- if (compute(rx - 1, ry + 1, x, y) < current) {
- offsetx = -1;
- offsety = 1;
- }
- return next(seed(rx + offsetx, ry + offsety));
- }
- private int compute(int rx, int ry, int x, int y) {
- long[] arr = {seed(rx, ry)};
- int ox = rx * size + (next(arr) & mod) - x;
- int oy = ry * size + (next(arr) & mod) - y;
- return ox * ox + oy * oy;
- }
- public static void main(String[] args) throws IOException {
- BiomeGen gen = new BiomeGen(6);
- final int size = 2048;
- BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_4BYTE_ABGR);
- for (int i = 0; i < size; i++)
- for (int i1 = 0; i1 < size; i1++)
- image.setRGB(i, i1, new Color((gen.getBiome(i1, i)) & 255, (gen.getBiome(i1, i)) & 255, (gen.getBiome(i1, i)) & 255, (((gen.getBiome(i1, i)) & 255) == 0) ? 0 : 255).getRGB());
- File temp = File.createTempFile("bruh", ".png");
- ImageIO.write(image, "png", temp);
- Desktop.getDesktop().open(temp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement