[Polycasso-commit] SF.net SVN: polycasso:[37] trunk/polycasso/src/com/mebigfatguy/polycasso/ Polygo
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-11-24 05:39:22
|
Revision: 37
http://polycasso.svn.sourceforge.net/polycasso/?rev=37&view=rev
Author: dbrosius
Date: 2009-11-24 05:39:15 +0000 (Tue, 24 Nov 2009)
Log Message:
-----------
javadoc
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java 2009-11-24 05:34:14 UTC (rev 36)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java 2009-11-24 05:39:15 UTC (rev 37)
@@ -25,6 +25,10 @@
import java.awt.Polygon;
import java.util.Random;
+/**
+ * an immutable class for holding the information for one polygon, including points, color
+ * and alpha level.
+ */
public class PolygonData implements Cloneable {
public static final int NUM_POLYS = 50;
public static final int MAX_POINTS = 8;
@@ -33,12 +37,25 @@
private float alpha;
private Polygon polygon;
+ /**
+ * creates a polygon data structure with required information
+ *
+ * @param c the color of the polygon
+ * @param xpar the alpha level of the polygon
+ * @param poly the points of the polygon
+ */
public PolygonData(Color c, float xpar, Polygon poly) {
color = c;
alpha = xpar;
polygon = poly;
}
+ /**
+ * creates a totally random polygon that is limited by the specified size
+ *
+ * @param size the maximum size of the bounding box of the polygon
+ * @return a random polygon
+ */
public static PolygonData randomPoly(Dimension size) {
Random r = new Random();
Polygon polygon = new Polygon();
@@ -53,6 +70,12 @@
return new PolygonData(c, r.nextFloat(), polygon);
}
+ /**
+ * creates an array of NUM_POLYS polygons that are randomly generated
+ *
+ * @param size the maximum size of the bounding box of any one polygon
+ * @return an array of polygon datas
+ */
public static PolygonData[] randomPolys(Dimension size) {
PolygonData[] data = new PolygonData[NUM_POLYS];
@@ -63,6 +86,11 @@
return data;
}
+ /**
+ * clones this polygon data data
+ *
+ * @return a copy of the polygon data
+ */
public Object clone() {
try {
PolygonData clone = (PolygonData)super.clone();
@@ -75,6 +103,15 @@
}
}
+ /**
+ * attempts to improve on one polygon randomly by adjusting it according to a randomly
+ * selected improvement type
+ *
+ * @param data the array of polygondata objects
+ * @param size the maximum size of the bounding box of any polygon
+ *
+ * @return the improvement type used to alter the data
+ */
public static ImprovementType improveRandomly(PolygonData[] data, Dimension size) {
Random r = new Random();
int idx = r.nextInt(data.length);
@@ -212,12 +249,26 @@
return type;
}
+ /**
+ * draws this polygondata on a specified graphics object
+ *
+ * @param g the graphics object on which to draw this polygon
+ */
public void draw(Graphics2D g) {
g.setColor(color);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
g.fillPolygon(polygon);
}
+ /**
+ * clip a value between a min and max value
+ *
+ * @param min the min value
+ * @param max the max value
+ * @param value the value to clip
+ *
+ * @return the clipped value
+ */
private static int clipToRange(int min, int max, int value) {
if (value < min)
return min;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|