Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import java.awt.Color;
- import javax.swing.JComponent;
- import javax.swing.JFrame;
- import java.awt.image.BufferedImage;
- public class Test {
- public static void main(String[] args){
- int n = 100;
- float[][] map = new float[n][n];
- for(int i=0; i<n;i++){
- for(int j=0; j<n;j++){
- map[i][j] = (float) Math.random();
- }
- }
- showImage(map);
- }
- public static void showImage(float[][] map){
- float maxHeight = Float.MIN_VALUE;
- float minHeight = Float.MAX_VALUE;
- for (float[] row : map){
- for (float height : row){
- if (height > maxHeight){
- maxHeight = height;
- }
- if (height < minHeight){
- minHeight = height;
- }
- }
- }
- int size = map.length;
- final BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
- for (int x = 0; x < size; x++){
- for (int y = 0; y < size; y++){
- Color color = Color.getHSBColor((float)((map[x][y] - minHeight)/(maxHeight - minHeight)), 1, 1);
- image.setRGB(x,y,color.getRGB());
- }
- }
- JFrame frame = new JFrame("Picture");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.add(new JComponent(){
- @Override
- public void paint(Graphics g){
- g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
- }
- });
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement