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);
}
}
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);
}
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()));
}
Aggregations