|
From: <diz...@us...> - 2007-08-14 21:56:36
|
Revision: 73
http://fortress.svn.sourceforge.net/fortress/?rev=73&view=rev
Author: dizzutch
Date: 2007-08-14 14:56:35 -0700 (Tue, 14 Aug 2007)
Log Message:
-----------
Added Application, there are some normalization errors, but I will work on those later.
Modified Paths:
--------------
trunk/mapgen/MapGenerator.java
trunk/mapgen/MapSection.java
trunk/mapgen/Test.java
Added Paths:
-----------
trunk/mapgen/MapGenApp.java
Added: trunk/mapgen/MapGenApp.java
===================================================================
--- trunk/mapgen/MapGenApp.java (rev 0)
+++ trunk/mapgen/MapGenApp.java 2007-08-14 21:56:35 UTC (rev 73)
@@ -0,0 +1,37 @@
+import java.awt.*;
+import java.awt.geom.*;
+import javax.swing.*;
+
+public class MapGenApp extends JPanel {
+ private MapGenerator map;
+
+ public void paintComponent(Graphics g) {
+ clear(g);
+ Graphics2D g2d = (Graphics2D)g;
+ for(int h = 0; h < map.getHeight(); h++) {
+ for(int w = 0; w < map.getWidth(); w++) {
+ double c = map.getMapSection(h,w).getHeight();
+ float nc = 1 - (float)c;
+ g2d.setColor(new Color(nc,nc,nc));
+ g2d.draw(new Ellipse2D.Double((double)h,(double)w,1.0,1.0));
+ }
+ }
+ }
+
+ protected void clear(Graphics g) {
+ super.paintComponent(g);
+ }
+
+ public static void main(String[] args) {
+ MapGenApp app = new MapGenApp();
+ app.map = new MapGenerator(600,600);
+ app.map.generateMap_HillAlgorithm(5);
+ JFrame frame = new JFrame("mapgen");
+ frame.setBackground(Color.white);
+ app.setBackground(Color.white);
+ frame.setSize(600,600);
+ frame.setContentPane(app);
+ frame.addWindowListener(new ExitListener());
+ frame.setVisible(true);
+ }
+}
Modified: trunk/mapgen/MapGenerator.java
===================================================================
--- trunk/mapgen/MapGenerator.java 2007-08-14 20:14:09 UTC (rev 72)
+++ trunk/mapgen/MapGenerator.java 2007-08-14 21:56:35 UTC (rev 73)
@@ -38,20 +38,47 @@
}
}
- public void generateMap_HillAlgorithm() {
+ public void generateMap_HillAlgorithm(int iterations) {
Random rand = new Random();
- for (int i = 0; i < 1; i++) {
+ double min = 0;
+ double max = 0;
+ for (int i = 0; i < iterations; i++) {
//generate random centerpoint
int x1 = rand.nextInt(this.height);
int y1 = rand.nextInt(this.width);
//generate random radius
- int radius = rand.nextInt(this.width/2);
+ int radius = rand.nextInt(this.width/2) + 1;
+ double radius2 = java.lang.Math.pow(radius, 2);
//for each point on the map, calculate height
for (int x2 = 0; x2 < this.height; x2++) {
for (int y2 = 0; y2 < this.width; y2++) {
- map[x2][y2].setHeight((float)java.lang.Math.pow(radius, 2) - ((float)java.lang.Math.pow(x2-x1,2)) + ((float)java.lang.Math.pow(y2-y1,2)));
+ double left = java.lang.Math.pow((x2-x1),2);
+ double right = java.lang.Math.pow((y2-y1),2);
+ double value = radius2 - (left + right);
+ if (value >= 0) {
+ min = (value < min) ? value : min;
+ max = (value > max) ? value : max;
+ double h = map[x2][y2].getHeight();
+ map[x2][y2].setHeight(value + h);
+ }
}
}
}
+ //normalize
+ System.out.println("max : "+ max);
+ System.out.println("min : "+ min);
+ double nmin = 0;
+ double nmax = 0;
+ for (int x = 0; x < this.height; x++) {
+ for (int y = 0; y < this.width; y++) {
+ double h = map[x][y].getHeight();
+ double value = ((h - min) / (max - min));
+ nmin = (value < nmin) ? value : nmin;
+ nmax = (value > nmax) ? value : nmax;
+ map[x][y].setHeight(value);
+ }
+ }
+ System.out.println("nmax : "+ nmax);
+ System.out.println("nmin : "+ nmin);
}
}
Modified: trunk/mapgen/MapSection.java
===================================================================
--- trunk/mapgen/MapSection.java 2007-08-14 20:14:09 UTC (rev 72)
+++ trunk/mapgen/MapSection.java 2007-08-14 21:56:35 UTC (rev 73)
@@ -1,5 +1,5 @@
public class MapSection {
- private float height;
+ private double height;
private int type;
//Constructor
@@ -8,7 +8,7 @@
this.type = 0;
}
- public float getHeight() {
+ public double getHeight() {
return this.height;
}
@@ -16,7 +16,7 @@
return this.type;
}
- public void setHeight(float new_height) {
+ public void setHeight(double new_height) {
this.height = new_height;
}
Modified: trunk/mapgen/Test.java
===================================================================
--- trunk/mapgen/Test.java 2007-08-14 20:14:09 UTC (rev 72)
+++ trunk/mapgen/Test.java 2007-08-14 21:56:35 UTC (rev 73)
@@ -1,8 +1,7 @@
public class Test {
public static void main(String argv[]) {
- MapGenerator mg = new MapGenerator(10,10);
+ MapGenerator mg = new MapGenerator(20,20);
+ mg.generateMap_HillAlgorithm(1);
mg.printMap();
- mg.generateMap_HillAlgorithm();
- mg.printMap();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|