Random Noise Generation!!
Ever since I successfully randomized the file an entity uses for its texture, I’v been working on creating random textured during runtime to truly randomize my chaos entity’s visuals.
Noise Generation
I’ve been using the Java BufferedImage class to generate random png’s to use for static. I iterate through each pixel and assign random r, g and b values (in the rgb color system). By default, it looks like static noise, but I’ve been trying custom operations and variables to instill patterns. Here is an example of the code:
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// generating values less than 256
int a = (int) (100);
int r = (int) (initial + (y + offsetR));
int g = (int) (initial + (Math.abs(Math.round(Math.sin(x)))));
int b = (int) (initial + (Math.abs(Math.round(Math.cos(x)))));
offsetR += 10;
//* Math.abs(offsetG*Math.sin(rand.nextInt(100)))
if(initial > 256){
initial = rand.nextInt(256);
}
//pixel
int p = (a << 24) | (r << 16) | (g << 8) | b;
img.setRGB(x, y, p);
}
Below, I have screenshots of different image files and entities I randomly generated using this code during testing.
Technical Issues(I haaatee fabric api why why why)
My initial approach was to call a method with the code above in the chaos entity’s constructor, which would generate a file titled "random" + entityID + ".png" (with entityID being a unique numerical ID assigned to each entity) on runtime, and the entity would use this generated file as its random texture. However, the rendering system can only detect files that were present in the project at compiletime, and these images are generated whenever an entity spawns during runtime. Whenever I would spawn a mob, it would have the “purple and black missing asset” texture until I closed and reran the code.
Temporary Fix
As of now, I generate 20 random noise pngs on initialization (when the program starts), and assign each spawned chaos entity one of these 20 images as its texture. This severely reduces the amount of randomness I was aiming for, and still needs the game to be run and rerun at least once so that there are always 20 random images present.
Moving forward
I really want to try to make the random image system more reliable and stable, and am working on making the patterns more interesting. However, I also want to move on to randomizing behavior soon. Randomizing visuals has destroyed me 😭
Here are some images of randomized files and entities I generated during testing different patternss :))
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.