Hello,
Just registered. It might be that I’ve found a new home for my new hobby.
I’m toying around with Java’s AWT and Swing, and trying to generate a visual 2D map “for a game”.
I’m using SimplexNoise class to generate the numbers, from this step, seems like I can’t find much more information about what and how.
I understand that I need to convert my numbers to a Colors and apply them to the “map” I’m generating.
So I have this initialization:
SimplexNoise.genGrad(677);
int initX = 0, initY = 0;
int mapWidth = 1000, mapHeight = 700;
for (int i = initX; i < mapWidth + initX; i++) {
for (int j = initY; j < mapHeight + initY; j++) {
double res = 512;
double tile = SimplexNoise.noise(i / res, j / res);
}
}
Which gives me numbers from -1 to 1.
I then proceed to create a blank Window:
public static void createWindow() {
JFrame frame = new JFrame("MapGenerator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1000, 700);
// make the frame half the height and width
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int height = screenSize.height;
int width = screenSize.width;
// center the jframe on screen
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
And now I assume I need to use Graphics2D and draw every pixel on it by the color my numbers are related to and then somehow attach this element to the JFrame.
Am I right? I’m not asking for a “copy&paste” examples (but this is awesome as well), but at least a direction of what to do. What class to use, and which approach to apply to accomplish this task.
My desired output is something like:
Thanks a lot!