Search in sources :

Example 1 with Random

use of org.terasology.engine.utilities.random.Random in project Terasology by MovingBlocks.

the class TextureAssetResolverTest method testColorTextures.

@Test
public void testColorTextures() {
    Random r = new FastRandom(123456);
    for (int i = 0; i < 10; i++) {
        int rgba = r.nextInt();
        Color red = new Color(rgba);
        ResourceUrn textureUriForColor = TextureUtil.getTextureUriForColor(red);
        String simpleString = textureUriForColor.toString();
        Optional<Texture> tex = Assets.getTexture(simpleString);
        assertTrue(tex.isPresent());
        ByteBuffer dataBuffer = tex.get().getData().getBuffers()[0];
        int firstPixel = dataBuffer.asIntBuffer().get(0);
        assertEquals(rgba, firstPixel);
    }
}
Also used : Random(org.terasology.engine.utilities.random.Random) FastRandom(org.terasology.engine.utilities.random.FastRandom) Color(org.terasology.nui.Color) FastRandom(org.terasology.engine.utilities.random.FastRandom) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 2 with Random

use of org.terasology.engine.utilities.random.Random in project Terasology by MovingBlocks.

the class TextureDataFactory method createWhiteNoiseTexture.

public static TextureData createWhiteNoiseTexture(int size, long seed, int min, int max) {
    int width = size;
    int height = size;
    ByteBuffer data = ByteBuffer.allocateDirect(4 * width * height);
    Random rng = new FastRandom(seed);
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            data.put((byte) TeraMath.clamp(rng.nextInt(min, max), 0, 255));
            data.put((byte) TeraMath.clamp(rng.nextInt(min, max), 0, 255));
            data.put((byte) TeraMath.clamp(rng.nextInt(min, max), 0, 255));
            data.put((byte) 255);
        }
    }
    // The buffer must be reset back to the initial position before passing it onward.
    data.rewind();
    return new TextureData(width, height, new ByteBuffer[] { data }, WrapMode.REPEAT, FilterMode.NEAREST);
}
Also used : Random(org.terasology.engine.utilities.random.Random) FastRandom(org.terasology.engine.utilities.random.FastRandom) FastRandom(org.terasology.engine.utilities.random.FastRandom) ByteBuffer(java.nio.ByteBuffer)

Example 3 with Random

use of org.terasology.engine.utilities.random.Random in project Terasology by MovingBlocks.

the class PlayerConfig method defaultPlayerColor.

/**
 * Randomly generates a default color for the player via a random int generator using FastRandom object.
 *
 * @return a Color object with the player's default color.
 */
private Color defaultPlayerColor() {
    Random rng = new FastRandom();
    List<Color> colors = CieCamColors.L65C65;
    return colors.get(rng.nextInt(colors.size()));
}
Also used : Random(org.terasology.engine.utilities.random.Random) FastRandom(org.terasology.engine.utilities.random.FastRandom) Color(org.terasology.nui.Color) FastRandom(org.terasology.engine.utilities.random.FastRandom)

Aggregations

FastRandom (org.terasology.engine.utilities.random.FastRandom)3 Random (org.terasology.engine.utilities.random.Random)3 ByteBuffer (java.nio.ByteBuffer)2 Color (org.terasology.nui.Color)2 Test (org.junit.jupiter.api.Test)1 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)1