Thread: [Polycasso-commit] SF.net SVN: polycasso:[21] trunk/polycasso/src/com/mebigfatguy/polycasso
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-11-23 22:20:01
|
Revision: 21
http://polycasso.svn.sourceforge.net/polycasso/?rev=21&view=rev
Author: dbrosius
Date: 2009-11-23 22:19:51 +0000 (Mon, 23 Nov 2009)
Log Message:
-----------
put debug code under direction of a global flag
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterPanel.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-11-23 21:47:03 UTC (rev 20)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-11-23 22:19:51 UTC (rev 21)
@@ -126,18 +126,21 @@
double delta = calculateDelta(image, targetImage);
- //String message = null;
+ String message = null;
synchronized(lock) {
attempt++;
if (delta < bestScore) {
bestData = data;
bestScore = delta;
- //message = "Attempt: " + attempt + " BestScore: " + bestScore + " type: " + type.name();
+ if (Polycasso.DEBUG)
+ message = "Attempt: " + attempt + " BestScore: " + bestScore + " type: " + type.name();
fireImageGenerated(image);
}
}
- //if (message != null)
- // System.out.println(message);
+ if (Polycasso.DEBUG) {
+ if (message != null)
+ System.out.println(message);
+ }
}
} catch (Exception e) {
e.printStackTrace();
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-23 21:47:03 UTC (rev 20)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-23 22:19:51 UTC (rev 21)
@@ -92,7 +92,10 @@
Image targetImage = RandomImageFinder.findImage();
panel.setTarget(targetImage);
Dimension size = new Dimension(targetImage.getWidth(PainterFrame.this), targetImage.getHeight(PainterFrame.this));
- setSize(size);
+ if (Polycasso.DEBUG){
+ Dimension wSize = new Dimension(size.width, size.height * 2);
+ setSize(wSize);
+ }
generator = new ImageGenerator(targetImage, size);
generator.addImageGeneratedListener(PainterFrame.this);
generator.startGenerating();
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterPanel.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterPanel.java 2009-11-23 21:47:03 UTC (rev 20)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterPanel.java 2009-11-23 22:19:51 UTC (rev 21)
@@ -51,8 +51,10 @@
synchronized(lock) {
if (bestImage != null)
g.drawImage(bestImage, 0, 0, bestImage.getWidth(this), bestImage.getHeight(this), Color.WHITE, this);
-// if (targetImage != null)
-// g.drawImage(targetImage, 0, targetImage.getHeight(this), targetImage.getWidth(this), targetImage.getHeight(this), Color.WHITE, this);
+ if (Polycasso.DEBUG) {
+ if (targetImage != null)
+ g.drawImage(targetImage, 0, targetImage.getHeight(this), targetImage.getWidth(this), targetImage.getHeight(this), Color.WHITE, this);
+ }
}
}
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java 2009-11-23 21:47:03 UTC (rev 20)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java 2009-11-23 22:19:51 UTC (rev 21)
@@ -23,6 +23,8 @@
public class Polycasso {
+ public static final boolean DEBUG = false;
+
public static void main(String[] args) {
PainterFrame pf = new PainterFrame();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-11-25 03:59:00
|
Revision: 48
http://polycasso.svn.sourceforge.net/polycasso/?rev=48&view=rev
Author: dbrosius
Date: 2009-11-25 03:58:52 +0000 (Wed, 25 Nov 2009)
Log Message:
-----------
pull out improving to a separate class, start out with no polygons, add AddPolygon and RemovePolygon improvem
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-11-25 03:57:47 UTC (rev 47)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-11-25 03:58:52 UTC (rev 48)
@@ -27,6 +27,7 @@
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
/**
@@ -59,7 +60,7 @@
g.drawImage(image, 0, 0, size.width, size.height, Color.WHITE, null);
feedback = new Feedback(targetImage);
imageSize = size;
- bestData = PolygonData.randomPolys(size);
+ bestData = new PolygonData[0];
}
/**
@@ -139,20 +140,21 @@
BufferedImage image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2d = (Graphics2D)image.getGraphics();
Composite srcOpaque = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f);
+ Improver improver = new Improver(imageSize);
while (!Thread.interrupted()) {
- PolygonData[] data;
synchronized(lock) {
- data = bestData.clone();
+ improver.setData(bestData);
}
- ImprovementType type = PolygonData.improveRandomly(data, imageSize);
+ ImprovementType type = improver.improveRandomly();
g2d.setColor(Color.BLACK);
g2d.setComposite(srcOpaque);
g2d.fillRect(0, 0, imageSize.width, imageSize.height);
-
+
+ List<PolygonData> data = improver.getData();
for (PolygonData pd : data) {
pd.draw(g2d);
}
@@ -163,7 +165,7 @@
synchronized(lock) {
attempt++;
if (delta < bestScore) {
- bestData = data;
+ bestData = data.toArray(new PolygonData[data.size()]);
bestScore = delta;
if (Polycasso.DEBUG)
message = "Attempt: " + attempt + " BestScore: " + bestScore + " type: " + type.name();
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java 2009-11-25 03:57:47 UTC (rev 47)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java 2009-11-25 03:58:52 UTC (rev 48)
@@ -23,6 +23,8 @@
* to make to an image.
*/
public enum ImprovementType {
+ AddPolygon,
+ RemovePolygon,
AddPoint,
RemovePoint,
MovePoint,
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java 2009-11-25 03:57:47 UTC (rev 47)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java 2009-11-25 03:58:52 UTC (rev 48)
@@ -30,7 +30,6 @@
* and alpha level.
*/
public class PolygonData implements Cloneable {
- public static final int NUM_POLYS = 50;
public static final int MAX_POINTS = 8;
private Color color;
@@ -50,6 +49,22 @@
polygon = poly;
}
+ public Polygon getPolygon() {
+ return polygon;
+ }
+
+ public void setAlpha(float xpar) {
+ alpha = xpar;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color newColor) {
+ color = newColor;
+ }
+
/**
* creates a totally random polygon that is limited by the specified size
*
@@ -69,23 +84,7 @@
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];
- for (int i = 0; i < NUM_POLYS; i++) {
- data[i] = randomPoly(size);
- }
-
- return data;
- }
-
/**
* clones this polygon data data
*
@@ -104,152 +103,6 @@
}
/**
- * 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);
- PolygonData pd = data[idx] = (PolygonData)data[idx].clone();
-
- ImprovementType type = ImprovementType.getRandomImprovement();
- switch (type) {
- case AddPoint: {
- if (pd.polygon.npoints <= MAX_POINTS) {
- pd.polygon.addPoint(0, 0);
- int insPos = r.nextInt(pd.polygon.npoints);
- int x = r.nextInt(size.width);
- int y = r.nextInt(size.height);
-
- System.arraycopy(pd.polygon.xpoints, insPos, pd.polygon.xpoints, insPos + 1, pd.polygon.npoints - insPos - 1);
- pd.polygon.xpoints[insPos] = x;
- System.arraycopy(pd.polygon.ypoints, insPos, pd.polygon.ypoints, insPos + 1, pd.polygon.npoints - insPos - 1);
- pd.polygon.ypoints[insPos] = y;
- } else {
- type = ImprovementType.CompleteChange;
- PolygonData sd = PolygonData.randomPoly(size);
- pd.polygon = sd.polygon;
- pd.color = sd.color;
- pd.alpha = sd.alpha;
- }
- }
- break;
-
- case RemovePoint:
- if (pd.polygon.npoints > 3) {
- int delPos = r.nextInt(pd.polygon.npoints);
-
- System.arraycopy(pd.polygon.xpoints, delPos+1, pd.polygon.xpoints, delPos, pd.polygon.npoints - delPos - 1);
- System.arraycopy(pd.polygon.ypoints, delPos+1, pd.polygon.ypoints, delPos, pd.polygon.npoints - delPos - 1);
- pd.polygon.npoints--;
- } else {
- type = ImprovementType.CompleteChange;
- PolygonData sd = PolygonData.randomPoly(size);
- pd.polygon = sd.polygon;
- pd.color = sd.color;
- pd.alpha = sd.alpha;
- }
- break;
-
- case MovePoint:
- int movePos = r.nextInt(pd.polygon.npoints);
- pd.polygon.xpoints[movePos] = r.nextInt(size.width);
- pd.polygon.ypoints[movePos] = r.nextInt(size.height);
- break;
-
- case ReorderPoly:
- System.arraycopy(data, idx+1, data, idx, NUM_POLYS - idx - 1);
- idx = r.nextInt(NUM_POLYS);
- System.arraycopy(data, idx, data, idx+1, NUM_POLYS - idx - 1);
- data[idx] = pd;
-
- break;
-
- case ShrinkPoly: {
- double midX = pd.polygon.xpoints[0];
- double midY = pd.polygon.ypoints[0];
- for (int i = 1; i < pd.polygon.npoints; i++) {
- midX += pd.polygon.xpoints[i];
- midY += pd.polygon.ypoints[i];
- }
- midX /= pd.polygon.npoints;
- midY /= pd.polygon.npoints;
-
- int shrinkFactor = r.nextInt(5);
- for (int i = 0; i < pd.polygon.npoints; i++) {
- pd.polygon.xpoints[i] += (pd.polygon.xpoints[i] < midX) ? shrinkFactor : -shrinkFactor;
- pd.polygon.ypoints[i] += (pd.polygon.ypoints[i] < midY) ? shrinkFactor : -shrinkFactor;
- }
- }
- break;
-
- case EnlargePoly: {
- double midX = pd.polygon.xpoints[0];
- double midY = pd.polygon.ypoints[0];
- for (int i = 1; i < pd.polygon.npoints; i++) {
- midX += pd.polygon.xpoints[i];
- midY += pd.polygon.ypoints[i];
- }
- midX /= pd.polygon.npoints;
- midY /= pd.polygon.npoints;
-
- int expandFactor = r.nextInt(5);
- for (int i = 0; i < pd.polygon.npoints; i++) {
- pd.polygon.xpoints[i] += (pd.polygon.xpoints[i] < midX) ? -expandFactor : expandFactor;
- pd.polygon.ypoints[i] += (pd.polygon.ypoints[i] < midY) ? -expandFactor : expandFactor;
- pd.polygon.xpoints[i] = clipToRange(0, size.width, pd.polygon.xpoints[i]);
- pd.polygon.ypoints[i] = clipToRange(0, size.height, pd.polygon.ypoints[i]);
- }
- }
- break;
-
- case ChangeColor:
- int comp = r.nextInt(3);
- switch (comp) {
- case 0: {
- int newColor = pd.color.getRed() + (r.nextInt(10) - 5);
- newColor = clipToRange(0, 255, newColor);
- pd.color = new Color(newColor, pd.color.getGreen(), pd.color.getBlue());
- }
- break;
-
- case 1: {
- int newColor = pd.color.getGreen() + (r.nextInt(10) - 5);
- newColor = clipToRange(0, 255, newColor);
- pd.color = new Color(pd.color.getRed(), newColor, pd.color.getBlue());
- }
- break;
-
- case 2: {
- int newColor = pd.color.getBlue() + (r.nextInt(10) - 5);
- newColor = clipToRange(0, 255, newColor);
- pd.color = new Color(pd.color.getRed(), pd.color.getGreen(), r.nextInt(255));
- }
- break;
- }
- break;
-
- case ChangeAlpha:
- pd.alpha = r.nextFloat();
- break;
-
- case CompleteChange:
- PolygonData sd = PolygonData.randomPoly(size);
- pd.polygon = sd.polygon;
- pd.color = sd.color;
- pd.alpha = sd.alpha;
- break;
- }
-
- return type;
- }
-
- /**
* draws this polygondata on a specified graphics object
*
* @param g the graphics object on which to draw this polygon
@@ -259,21 +112,4 @@
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;
- else if (value > max)
- return max;
- return value;
- }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-11-25 06:36:18
|
Revision: 53
http://polycasso.svn.sourceforge.net/polycasso/?rev=53&view=rev
Author: dbrosius
Date: 2009-11-25 06:35:46 +0000 (Wed, 25 Nov 2009)
Log Message:
-----------
add RectifyPoint
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java 2009-11-25 05:56:12 UTC (rev 52)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java 2009-11-25 06:35:46 UTC (rev 53)
@@ -27,7 +27,8 @@
RemovePolygon,
AddPoint,
RemovePoint,
- MovePoint,
+ MovePoint,
+ RectifyPoint,
ReorderPoly,
ShrinkPoly,
EnlargePoly,
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java 2009-11-25 05:56:12 UTC (rev 52)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java 2009-11-25 06:35:46 UTC (rev 53)
@@ -152,6 +152,23 @@
}
break;
+ case RectifyPoint: {
+ int idx = r.nextInt(polygons.size());
+ PolygonData pd = (PolygonData)polygons.get(idx).clone();
+ Polygon polygon = pd.getPolygon();
+ int rectifyPos = r.nextInt(polygon.npoints);
+ int targetPos = (rectifyPos == 0) ? polygon.npoints - 1 : (rectifyPos - 1);
+
+ if (Math.abs(polygon.xpoints[rectifyPos] - polygon.xpoints[targetPos]) <
+ Math.abs(polygon.ypoints[rectifyPos] - polygon.ypoints[targetPos])) {
+ polygon.xpoints[rectifyPos] = polygon.xpoints[targetPos];
+ } else {
+ polygon.ypoints[rectifyPos] = polygon.ypoints[targetPos];
+ }
+ polygons.set(idx, pd);
+ }
+ break;
+
case ReorderPoly: {
if (polygons.size() > 2) {
PolygonData pd = polygons.remove(r.nextInt(polygons.size()));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-11-28 01:54:32
|
Revision: 80
http://polycasso.svn.sourceforge.net/polycasso/?rev=80&view=rev
Author: dbrosius
Date: 2009-11-28 01:54:25 +0000 (Sat, 28 Nov 2009)
Log Message:
-----------
add an image completor
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-28 01:54:03 UTC (rev 79)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-28 01:54:25 UTC (rev 80)
@@ -42,6 +42,7 @@
private static final long serialVersionUID = 7729602294481171194L;
private PainterPanel panel;
private JMenuItem paintImage;
+ private JMenuItem completeImage;
private JMenuItem quitItem;
ImageGenerator generator;
@@ -76,6 +77,10 @@
JMenu fileMenu = new JMenu(PolycassoBundle.getString(PolycassoBundle.Key.File));
paintImage = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.PaintImage));
fileMenu.add(paintImage);
+ completeImage = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.CompleteImage));
+ completeImage.setEnabled(false);
+ fileMenu.add(completeImage);
+ fileMenu.addSeparator();
quitItem = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.Quit));
fileMenu.add(quitItem);
mb.add(fileMenu);
@@ -113,6 +118,7 @@
generator = new ImageGenerator(targetImage, size);
generator.addImageGeneratedListener(PainterFrame.this);
generator.startGenerating();
+ completeImage.setEnabled(true);
} catch (IOException ioe) {
JOptionPane.showMessageDialog(null, ioe.getMessage());
@@ -120,9 +126,21 @@
}
});
+ completeImage.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ if (generator != null)
+ generator.complete();
+
+ completeImage.setEnabled(false);
+ }
+ });
+
quitItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
+ if (generator != null)
+ generator.stopGenerating();
dispose();
System.exit(0);
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-11-28 01:54:03 UTC (rev 79)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-11-28 01:54:25 UTC (rev 80)
@@ -32,6 +32,7 @@
Title("pc.title"),
File("pc.file"),
PaintImage("pc.paintimage"),
+ CompleteImage("pc.completeimage"),
Quit("pc.quit");
String id;
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-11-28 01:54:03 UTC (rev 79)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-11-28 01:54:25 UTC (rev 80)
@@ -19,4 +19,5 @@
pc.title = Polycasso
pc.file = File
pc.paintimage = Start Generating Image
+pc.completeimage = Complete Image
pc.quit = Quit
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-11-28 05:36:36
|
Revision: 86
http://polycasso.svn.sourceforge.net/polycasso/?rev=86&view=rev
Author: dbrosius
Date: 2009-11-28 05:36:28 +0000 (Sat, 28 Nov 2009)
Log Message:
-----------
add about box
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-28 05:35:54 UTC (rev 85)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-28 05:36:28 UTC (rev 86)
@@ -44,6 +44,7 @@
private JMenuItem paintImage;
private JMenuItem completeImage;
private JMenuItem quitItem;
+ private JMenuItem aboutItem;
ImageGenerator generator;
/**
@@ -84,6 +85,10 @@
quitItem = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.Quit));
fileMenu.add(quitItem);
mb.add(fileMenu);
+ JMenu aboutMenu = new JMenu(PolycassoBundle.getString(PolycassoBundle.Key.About));
+ aboutItem = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.AboutPolycasso));
+ aboutMenu.add(aboutItem);
+ mb.add(aboutMenu);
setJMenuBar(mb);
}
@@ -148,6 +153,16 @@
System.exit(0);
}
});
+
+ aboutItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ AboutDialog ad = new AboutDialog();
+ ad.setLocationRelativeTo(PainterFrame.this);
+ ad.setModal(true);
+ ad.setVisible(true);
+ }
+ });
}
/**
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-11-28 05:35:54 UTC (rev 85)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-11-28 05:36:28 UTC (rev 86)
@@ -30,10 +30,13 @@
*/
enum Key {
Title("pc.title"),
+ Info("pc.info"),
File("pc.file"),
PaintImage("pc.paintimage"),
CompleteImage("pc.completeimage"),
- Quit("pc.quit");
+ Quit("pc.quit"),
+ About("pc.about"),
+ AboutPolycasso("pc.aboutpolycasso");
String id;
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-11-28 05:35:54 UTC (rev 85)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-11-28 05:36:28 UTC (rev 86)
@@ -17,7 +17,10 @@
# * under the License.
# */
pc.title = Polycasso
+pc.info = A cubism-style artwork generator that layers semi-transparent polygon \nvia a training feedback loop. Produces increasingly \nrealistic work though hill climbing.
pc.file = File
pc.paintimage = Start Generating Image
pc.completeimage = Complete Image
-pc.quit = Quit
\ No newline at end of file
+pc.quit = Quit
+pc.about = About
+pc.aboutpolycasso = About Polycasso
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-11-28 23:21:35
|
Revision: 92
http://polycasso.svn.sourceforge.net/polycasso/?rev=92&view=rev
Author: dbrosius
Date: 2009-11-28 23:21:28 +0000 (Sat, 28 Nov 2009)
Log Message:
-----------
add a settings dialog (those settings are not used at present)
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-28 23:20:40 UTC (rev 91)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-28 23:21:28 UTC (rev 92)
@@ -45,7 +45,9 @@
private JMenuItem completeImage;
private JMenuItem quitItem;
private JMenuItem aboutItem;
- ImageGenerator generator;
+ private JMenuItem settingsItem;
+ private ImageGenerator generator;
+ private Settings settings;
/**
* creates the main window, setups up menus and listeners
@@ -56,6 +58,7 @@
initMenus();
initListeners();
pack();
+ settings = new Settings();
generator = null;
}
@@ -85,6 +88,12 @@
quitItem = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.Quit));
fileMenu.add(quitItem);
mb.add(fileMenu);
+
+ JMenu editMenu = new JMenu(PolycassoBundle.getString(PolycassoBundle.Key.Edit));
+ settingsItem = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.Settings));
+ editMenu.add(settingsItem);
+ mb.add(editMenu);
+
JMenu aboutMenu = new JMenu(PolycassoBundle.getString(PolycassoBundle.Key.About));
aboutItem = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.AboutPolycasso));
aboutMenu.add(aboutItem);
@@ -154,6 +163,22 @@
}
});
+ settingsItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ SettingsDialog dialog = new SettingsDialog(settings);
+ dialog.setLocationRelativeTo(PainterFrame.this);
+ dialog.setModal(true);
+ dialog.setVisible(true);
+ if (dialog.isOK()) {
+ Settings dlgSettings = dialog.getSettings();
+ settings.setMaxImageSize(dlgSettings.getMaxImageSize());
+ settings.setMaxPolygons(dlgSettings.getMaxPolygons());
+ settings.setMaxPtMovement(dlgSettings.getMaxPtMovement());
+ }
+ }
+ });
+
aboutItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-11-28 23:20:40 UTC (rev 91)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-11-28 23:21:28 UTC (rev 92)
@@ -30,13 +30,22 @@
*/
enum Key {
Title("pc.title"),
+ OK("pc.ok"),
+ Cancel("pc.cancel"),
Info("pc.info"),
File("pc.file"),
PaintImage("pc.paintimage"),
CompleteImage("pc.completeimage"),
Quit("pc.quit"),
+ Edit("pc.edit"),
+ Settings("pc.settings"),
About("pc.about"),
- AboutPolycasso("pc.aboutpolycasso");
+ AboutPolycasso("pc.aboutpolycasso"),
+ MaxImageSize("pc.maximagesize"),
+ Width("pc.width"),
+ Height("pc.height"),
+ MaximumPolygons("pc.maximumpolygons"),
+ MaximumPointMovement("pc.maximumpointmovement");
String id;
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-11-28 23:20:40 UTC (rev 91)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-11-28 23:21:28 UTC (rev 92)
@@ -17,10 +17,19 @@
# * under the License.
# */
pc.title = Polycasso
+pc.ok = OK
+pc.cancel = Cancel
pc.info = A cubism-style artwork generator that layers semi-transparent polygon \nvia a training feedback loop. Produces increasingly \nrealistic work though hill climbing.
pc.file = File
pc.paintimage = Start Generating Image
pc.completeimage = Complete Image
pc.quit = Quit
+pc.edit = Edit
+pc.settings = Settings
pc.about = About
pc.aboutpolycasso = About Polycasso
+pc.maximagesize = Maximum Image Size
+pc.width = Width
+pc.height = Height
+pc.maximumpolygons = Maximum Polygons
+pc.maximumpointmovement = Maximum Point Movement
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-11-29 07:12:11
|
Revision: 123
http://polycasso.svn.sourceforge.net/polycasso/?rev=123&view=rev
Author: dbrosius
Date: 2009-11-29 07:12:03 +0000 (Sun, 29 Nov 2009)
Log Message:
-----------
move max color to the settings dialog
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-11-29 06:56:23 UTC (rev 122)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-11-29 07:12:03 UTC (rev 123)
@@ -47,6 +47,7 @@
MaximumPolygons("pc.maximumpolygons"),
MaximumPolygonPoints("pc.maxpolygonpoints"),
MaximumPointMovement("pc.maximumpointmovement"),
+ MaximumColorChange("pc.maximumcolorchange"),
BadSetting("pc.badsetting");
String id;
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2009-11-29 06:56:23 UTC (rev 122)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2009-11-29 07:12:03 UTC (rev 123)
@@ -56,6 +56,7 @@
private JTextField maxPolygonField;
private JTextField maxPolygonPointsField;
private JTextField maxPtMoveField;
+ private JTextField maxColorChangeField;
private boolean isOK;
/**
@@ -111,7 +112,7 @@
SelectAllFocuser focuser = new SelectAllFocuser();
JPanel optPanel = new JPanel();
optPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
- optPanel.setLayout(new FormLayout("pref, 3dlu, 100px, 5dlu, pref, 3dlu, 100px", "pref, 1dlu, pref, 15dlu, pref, 1dlu, pref, 1dlu, pref"));
+ optPanel.setLayout(new FormLayout("pref, 3dlu, 100px, 5dlu, pref, 3dlu, 100px", "pref, 1dlu, pref, 15dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref"));
CellConstraints cc = new CellConstraints();
JLabel maxSizeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaxImageSize));
@@ -161,6 +162,16 @@
maxPtMoveField.setText(String.valueOf(dlgSettings.getMaxPtMovement()));
optPanel.add(maxPtMoveField, cc.xy(7, 9));
maxPtMoveField.addFocusListener(focuser);
+
+ JLabel maxColorChangeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaximumColorChange));
+ optPanel.add(maxColorChangeLabel, cc.xyw(1, 11, 5));
+ maxColorChangeField = new JTextField(4);
+ maxColorChangeField.setDocument(new IntegerDocument());
+ maxColorChangeLabel.setLabelFor(maxColorChangeField);
+ maxColorChangeField.setText(String.valueOf(dlgSettings.getMaxColorChange()));
+ optPanel.add(maxColorChangeField, cc.xy(7, 11));
+ maxColorChangeField.addFocusListener(focuser);
+
return optPanel;
}
@@ -196,7 +207,7 @@
dlgSettings.setMaxPolygons(Integer.parseInt(maxPolygonField.getText()));
dlgSettings.setMaxPoints(Integer.parseInt(maxPolygonPointsField.getText()));
dlgSettings.setMaxPtMovement(Integer.parseInt(maxPtMoveField.getText()));
-
+ dlgSettings.setMaxColorChange(Integer.parseInt(maxColorChangeField.getText()));
if (validateSettings()) {
isOK = true;
dispose();
@@ -260,6 +271,9 @@
} else if (dlgSettings.getMaxPtMovement() < 5) {
maxPtMoveField.setText("5");
maxPtMoveField.requestFocus();
+ } else if (dlgSettings.getMaxColorChange() < 5) {
+ maxColorChangeField.setText("5");
+ maxColorChangeField.requestFocus();
} else {
return true;
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-11-29 06:56:23 UTC (rev 122)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-11-29 07:12:03 UTC (rev 123)
@@ -34,4 +34,5 @@
pc.maximumpolygons = Maximum Polygons
pc.maxpolygonpoints = Maximum Points per Polygon
pc.maximumpointmovement = Maximum Point Movement
+pc.maximumcolorchange = Maximum Color Change
pc.badsetting = The setting specified was too small to properly function
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-12-01 14:31:21
|
Revision: 125
http://polycasso.svn.sourceforge.net/polycasso/?rev=125&view=rev
Author: dbrosius
Date: 2009-12-01 14:31:12 +0000 (Tue, 01 Dec 2009)
Log Message:
-----------
add NumCompetingImages
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-12-01 14:25:34 UTC (rev 124)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-12-01 14:31:12 UTC (rev 125)
@@ -174,6 +174,7 @@
Settings dlgSettings = dialog.getSettings();
settings.setMaxImageSize(dlgSettings.getMaxImageSize());
settings.setMaxPolygons(dlgSettings.getMaxPolygons());
+ settings.setNumCompetingImages(dlgSettings.getNumCompetingImages());
settings.setMaxPoints(dlgSettings.getMaxPoints());
settings.setMaxPtMovement(dlgSettings.getMaxPtMovement());
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-12-01 14:25:34 UTC (rev 124)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-12-01 14:31:12 UTC (rev 125)
@@ -45,6 +45,7 @@
Width("pc.width"),
Height("pc.height"),
MaximumPolygons("pc.maximumpolygons"),
+ NumberOfCompetingImages("pc.numberofcompetingimages"),
MaximumPolygonPoints("pc.maxpolygonpoints"),
MaximumPointMovement("pc.maximumpointmovement"),
MaximumColorChange("pc.maximumcolorchange"),
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2009-12-01 14:25:34 UTC (rev 124)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2009-12-01 14:31:12 UTC (rev 125)
@@ -39,6 +39,7 @@
public Settings() {
maxImageSize = new Dimension(800, 600);
maxPolygons = 50;
+ numCompetingImages = 100;
maxPoints = 8;
maxPtMovement = 20;
maxColorChange = 40;
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2009-12-01 14:25:34 UTC (rev 124)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2009-12-01 14:31:12 UTC (rev 125)
@@ -54,6 +54,7 @@
private JTextField widthField;
private JTextField heightField;
private JTextField maxPolygonField;
+ private JTextField numCompetingImagesField;
private JTextField maxPolygonPointsField;
private JTextField maxPtMoveField;
private JTextField maxColorChangeField;
@@ -112,7 +113,7 @@
SelectAllFocuser focuser = new SelectAllFocuser();
JPanel optPanel = new JPanel();
optPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
- optPanel.setLayout(new FormLayout("pref, 3dlu, 100px, 5dlu, pref, 3dlu, 100px", "pref, 1dlu, pref, 15dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref"));
+ optPanel.setLayout(new FormLayout("pref, 3dlu, 100px, 5dlu, pref, 3dlu, 100px", "pref, 1dlu, pref, 15dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref"));
CellConstraints cc = new CellConstraints();
JLabel maxSizeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaxImageSize));
@@ -145,31 +146,40 @@
optPanel.add(maxPolygonField, cc.xy(7, 5));
maxPolygonField.addFocusListener(focuser);
+ JLabel numCompetingImagesLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.NumberOfCompetingImages));
+ optPanel.add(numCompetingImagesLabel, cc.xyw(1, 7, 5));
+ numCompetingImagesField = new JTextField(4);
+ numCompetingImagesField.setDocument(new IntegerDocument());
+ numCompetingImagesLabel.setLabelFor(numCompetingImagesField);
+ numCompetingImagesField.setText(String.valueOf(dlgSettings.getNumCompetingImages()));
+ optPanel.add(numCompetingImagesField, cc.xy(7, 7));
+ numCompetingImagesField.addFocusListener(focuser);
+
JLabel maxPolyPointLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaximumPolygonPoints));
- optPanel.add(maxPolyPointLabel, cc.xyw(1, 7, 7));
+ optPanel.add(maxPolyPointLabel, cc.xyw(1, 9, 7));
maxPolygonPointsField = new JTextField(4);
maxPolygonPointsField.setDocument(new IntegerDocument());
maxPolyPointLabel.setLabelFor(maxPolygonPointsField);
maxPolygonPointsField.setText(String.valueOf(dlgSettings.getMaxPoints()));
- optPanel.add(maxPolygonPointsField, cc.xy(7, 7));
+ optPanel.add(maxPolygonPointsField, cc.xy(7, 9));
maxPolygonPointsField.addFocusListener(focuser);
JLabel maxPtMoveLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaximumPointMovement));
- optPanel.add(maxPtMoveLabel, cc.xyw(1, 9, 5));
+ optPanel.add(maxPtMoveLabel, cc.xyw(1, 11, 5));
maxPtMoveField = new JTextField(4);
maxPtMoveField.setDocument(new IntegerDocument());
maxPtMoveLabel.setLabelFor(maxPtMoveField);
maxPtMoveField.setText(String.valueOf(dlgSettings.getMaxPtMovement()));
- optPanel.add(maxPtMoveField, cc.xy(7, 9));
+ optPanel.add(maxPtMoveField, cc.xy(7, 11));
maxPtMoveField.addFocusListener(focuser);
JLabel maxColorChangeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaximumColorChange));
- optPanel.add(maxColorChangeLabel, cc.xyw(1, 11, 5));
+ optPanel.add(maxColorChangeLabel, cc.xyw(1, 13, 5));
maxColorChangeField = new JTextField(4);
maxColorChangeField.setDocument(new IntegerDocument());
maxColorChangeLabel.setLabelFor(maxColorChangeField);
maxColorChangeField.setText(String.valueOf(dlgSettings.getMaxColorChange()));
- optPanel.add(maxColorChangeField, cc.xy(7, 11));
+ optPanel.add(maxColorChangeField, cc.xy(7, 13));
maxColorChangeField.addFocusListener(focuser);
return optPanel;
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-12-01 14:25:34 UTC (rev 124)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-12-01 14:31:12 UTC (rev 125)
@@ -32,6 +32,7 @@
pc.width = Width
pc.height = Height
pc.maximumpolygons = Maximum Polygons
+pc.numberofcompetingimages = Number of Competing Images
pc.maxpolygonpoints = Maximum Points per Polygon
pc.maximumpointmovement = Maximum Point Movement
pc.maximumcolorchange = Maximum Color Change
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-10-03 05:59:46
|
Revision: 228
http://polycasso.svn.sourceforge.net/polycasso/?rev=228&view=rev
Author: dbrosius
Date: 2010-10-03 05:59:39 +0000 (Sun, 03 Oct 2010)
Log Message:
-----------
Add Generation/Elite handling, along with breeding and some more improver types. Also mark a change successful if it is something that creates an elite member. Stub in annealing, not used yet.
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java
trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementTypeStats.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
Added Paths:
-----------
trunk/polycasso/src/com/mebigfatguy/polycasso/GenerationHandler.java
trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementResult.java
Added: trunk/polycasso/src/com/mebigfatguy/polycasso/GenerationHandler.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/GenerationHandler.java (rev 0)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/GenerationHandler.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -0,0 +1,189 @@
+/*
+ * polycasso - Cubism Artwork generator
+ * Copyright 2009-2010 MeBigFatGuy.com
+ * Copyright 2009-2010 Dave Brosius
+ * Inspired by work by Roger Alsing
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package com.mebigfatguy.polycasso;
+
+import java.awt.Dimension;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * class that maintains the set of polygon data for this generation of images
+ */
+public class GenerationHandler {
+
+ /**
+ * class that holds a sample set of polygons and it's score
+ */
+ public static class Member implements Comparable<Member> {
+
+ double score;
+ PolygonData[] data;
+
+ Member(double polyScore, PolygonData[] polyData) {
+ score = polyScore;
+ data = polyData;
+ }
+
+ @Override
+ public int compareTo(Member o) {
+ if (score > o.score)
+ return 1;
+ else if (score < o.score)
+ return -1;
+ return 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int)score * 1000;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof Member) {
+ return score == ((Member)o).score;
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + score + ": " + Arrays.toString(data) + ")";
+ }
+ }
+
+ private List<Member> generation;
+ private Random random;
+ private Settings settings;
+ private int generationNumber;
+ private double annealingValue;
+ private Member bestMember;
+ private double eliteCutOff;
+ private int generationBests;
+ private int generationElites;
+
+ /**
+ * constructs a handler for managing successive generations of image samples
+ *
+ * @param confSettings settings to use for generation and elite size
+ * @param imageSize the size of the target image
+ */
+ public GenerationHandler(Settings confSettings, Dimension imageSize) {
+ random = new Random();
+ generationNumber = 0;
+ settings = confSettings;
+ bestMember = new Member(Double.MAX_VALUE, new PolygonData[0]);
+ eliteCutOff = Double.MAX_VALUE;
+ generation = new ArrayList<Member>(settings.getGenerationSize() + 10);
+ annealingValue = settings.getStartTemperature() * settings.getStartTemperature() * imageSize.height * imageSize.width;
+ generationBests = 0;
+ generationElites = 0;
+ }
+
+ /**
+ * add a sample polygon set to this generation with a given score
+ *
+ * @param score the deviation from perfection this set calculates
+ *
+ * @param polygonData the polygons that draw the image
+ *
+ * @return whether this is the best polygon set so far
+ */
+ public ImprovementResult addPolygonData(double score, PolygonData[] polygonData) {
+ synchronized(generation) {
+ Member newMember = new Member(score, polygonData);
+ generation.add(newMember);
+ if (generation.size() >= settings.getGenerationSize()) {
+ processGeneration();
+ } else {
+ Collections.sort(generation);
+ }
+ if (score < bestMember.score) {
+ bestMember = newMember;
+ generationBests++;
+ return ImprovementResult.BEST;
+ } else if (score < eliteCutOff) {
+ generationElites++;
+ return ImprovementResult.ELITE;
+ }
+
+ return ImprovementResult.FAIL;
+ }
+ }
+
+ /**
+ * pick a random polygon sample either from the general pool or elite pool
+ * scew the results towards the elite
+ *
+ * @param elite whether to pick from the elite pool or not
+ * @return a random polygon set
+ */
+ public PolygonData[] getRandomPolygonData(boolean elite) {
+ synchronized(generation) {
+ int size = elite ? (settings.getEliteSize() % generation.size()) : generation.size();
+
+ if (size == 0)
+ return null;
+
+ int r = random.nextInt(size);
+
+ int idx = (r * r) / (size * size);
+
+ return generation.get(idx).data;
+ }
+ }
+
+ /**
+ * returns the best polygon set to draw the picture
+ *
+ * @return the best polygon set
+ */
+ public Member getBestMember() {
+ synchronized(generation) {
+ return bestMember;
+ }
+ }
+
+ private void processGeneration() {
+ int eliteSize = settings.getEliteSize();
+
+ Collections.<GenerationHandler.Member>sort(generation);
+ int sz = generation.size();
+
+ List<Member> nextGeneration = new ArrayList<Member>(settings.getGenerationSize() + 10);
+ for (int i = 0; i < eliteSize; i++) {
+ nextGeneration.add(generation.get(i));
+ }
+
+ generation = nextGeneration;
+
+ eliteCutOff = generation.get(eliteSize-1).score;
+
+ if (Polycasso.DEBUG) {
+ System.out.println("Generation " + generationNumber + " had " + generationBests + " bests and " + generationElites + " elites. Best Score: " + generation.get(0).score);
+ }
+ generationBests = 0;
+ generationElites = 0;
+ generationNumber++;
+ annealingValue *= (1.0 - settings.getCoolingRate());
+ }
+}
Property changes on: trunk/polycasso/src/com/mebigfatguy/polycasso/GenerationHandler.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2010-10-03 05:47:22 UTC (rev 227)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -36,20 +36,13 @@
* This class generates multiple images in parallel to keep multicore processors busy.
*/
public class ImageGenerator implements Runnable {
- private static int attempt = 0;
private Set<ImageGeneratedListener> listeners = new HashSet<ImageGeneratedListener>();
private Settings settings;
private BufferedImage targetImage;
- private PolygonData[] bestData;
- private double bestScore = Double.MAX_VALUE;
- private BufferedImage candidateImage;
- private PolygonData[] candidateData;
- private double candidateScore = Double.MAX_VALUE;
- private int candidateStart = 0;
+ private GenerationHandler generationHandler;
private Dimension imageSize;
private Feedback feedback;
private Thread[] t = null;
- private Object lock = new Object();
private Object startStopLock = new Object();
/**
@@ -64,8 +57,8 @@
targetImage = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = targetImage.getGraphics();
g.drawImage(image, 0, 0, imageSize.width, imageSize.height, Color.WHITE, null);
+ generationHandler = new GenerationHandler(settings, imageSize);
feedback = new Feedback(targetImage);
- bestData = new PolygonData[0];
}
/**
@@ -88,16 +81,6 @@
}
/**
- * returns the best polygon data that has been generated thus far
- *
- * @return the array of polygons that are to be rendered
- */
- public PolygonData[] getBestData() {
- synchronized(lock) {
- return bestData.clone();
- }
- }
- /**
* allows interested parties to register to receive events when a new best image has been
* found.
*
@@ -134,11 +117,11 @@
*/
public void startGenerating() {
synchronized(startStopLock) {
- attempt = 0;
if (t == null) {
t = new Thread[Runtime.getRuntime().availableProcessors() + 1];
for (int i = 0; i < t.length; i++) {
t[i] = new Thread(this);
+ t[i].setName("Improver : " + i);
t[i].start();
}
}
@@ -174,13 +157,21 @@
if (t != null) {
stopGenerating();
t = new Thread[1];
- t[0] = new Thread(new ImageCompleter(this, targetImage, bestData, imageSize));
+ t[0] = new Thread(new ImageCompleter(this, targetImage, generationHandler.getBestMember().data, imageSize));
t[0].start();
}
}
}
/**
+ * retrieves the best set of polygons for drawing the image so far
+ *
+ * @return the best set of polygons
+ */
+ public PolygonData[] getBestData() {
+ return generationHandler.getBestMember().data;
+ }
+ /**
* the runnable interface implementation to repeatedly improve upon the image and check to
* see if it is closer to the target image. Images are created in batches of settings.numCompetingImages
* and the best one (if better than the parent) is selected as the new best.
@@ -190,14 +181,9 @@
BufferedImage image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2d = (Graphics2D)image.getGraphics();
Composite srcOpaque = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f);
- Improver improver = new Improver(settings, imageSize);
+ Improver improver = new Improver(settings, generationHandler, imageSize);
while (!Thread.interrupted()) {
-
- synchronized(lock) {
- improver.setData(bestData);
- }
-
ImprovementType type = improver.improveRandomly();
g2d.setColor(Color.BLACK);
@@ -211,39 +197,25 @@
double delta = feedback.calculateDelta(image);
- String message = null;
- boolean wasSuccessful = false;
- synchronized(lock) {
- attempt++;
- if (delta < candidateScore) {
+ boolean wasSuccessful;
+
+ ImprovementResult result = generationHandler.addPolygonData(delta, data.toArray(new PolygonData[data.size()]));
+ switch (result) {
+ case BEST:
+ fireImageGenerated(image);
+ wasSuccessful = true;
+ image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR);
+ g2d = (Graphics2D)image.getGraphics();
+ break;
+
+ case ELITE:
wasSuccessful = true;
- candidateData = data.toArray(new PolygonData[data.size()]);
- candidateScore = delta;
- candidateImage = image;
-
- if (Polycasso.DEBUG)
- message = "Attempt: " + attempt + " CandidateScore: " + candidateScore + " BestScore: " + bestScore + " type: " + type.name();
- }
+ break;
- if ((candidateStart + settings.getNumCompetingImages()) <= attempt) {
- if (candidateScore < bestScore) {
- bestData = candidateData;
- bestScore = candidateScore;
- fireImageGenerated(candidateImage);
- }
- candidateStart = attempt;
- }
+ default:
+ wasSuccessful = false;
}
-
- if (Polycasso.DEBUG) {
- if (message != null)
- System.out.println(message);
- }
- if (wasSuccessful) {
- image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR);
- g2d = (Graphics2D)image.getGraphics();
- }
improver.typeWasSuccessful(type, wasSuccessful);
}
} catch (Exception e) {
Added: trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementResult.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementResult.java (rev 0)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementResult.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -0,0 +1,25 @@
+/*
+ * polycasso - Cubism Artwork generator
+ * Copyright 2009-2010 MeBigFatGuy.com
+ * Copyright 2009-2010 Dave Brosius
+ * Inspired by work by Roger Alsing
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package com.mebigfatguy.polycasso;
+
+public enum ImprovementResult {
+ BEST,
+ ELITE,
+ FAIL;
+}
Property changes on: trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementResult.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java 2010-10-03 05:47:22 UTC (rev 227)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementType.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -74,8 +74,25 @@
* adjust the transparency of a random existing polygon
*/
ChangeAlpha,
+ /*
+ * change the color to white
+ */
+ White,
+ /*
+ * change the color to black
+ */
+ Black,
/**
+ * combine two sets of polygons
+ */
+ Breed,
+ /**
+ * combine two sets of polygons one from an elite
+ */
+ BreedElite,
+ /**
* completely change all attributes of a random existing polygon
*/
CompleteChange;
+
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementTypeStats.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementTypeStats.java 2010-10-03 05:47:22 UTC (rev 227)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementTypeStats.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -29,7 +29,7 @@
*/
public class ImprovementTypeStats {
- private static final int MAX_FAILURE_RUN = 100;
+ private static final int MAX_FAILURE_RUN = 25;
private static class Stats {
public int successes = 1;
public int totals = 1;
@@ -66,11 +66,11 @@
stats.totals++;
failureRun = successful ? 0 : failureRun + 1;
if (failureRun > MAX_FAILURE_RUN) {
-// if (Polycasso.DEBUG){
-// System.out.println("** Stats at time of failure run **");
-// System.out.println(this);
-// System.out.println("**********************************");
-// }
+ if (Polycasso.DEBUG){
+ System.out.println("** Stats at time of failure run **");
+ System.out.println(this);
+ System.out.println("**********************************");
+ }
initStats();
} else {
stats.pct = ((double)stats.successes) / ((double) stats.totals);
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java 2010-10-03 05:47:22 UTC (rev 227)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -22,8 +22,8 @@
import java.awt.Dimension;
import java.awt.Polygon;
import java.awt.Rectangle;
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.LinkedList;
import java.util.List;
import java.util.Random;
@@ -34,6 +34,7 @@
*/
public class Improver {
private Settings settings;
+ private GenerationHandler generationHandler;
private Dimension imageSize;
private List<PolygonData> polygons = null;
private ImprovementTypeStats stats;
@@ -42,25 +43,18 @@
/**
* create an improver using a specified image size
* @param confSettings the settings to be used
+ * @param genHandler the generation handler
* @param size the size of the image
*/
- public Improver(Settings confSettings, Dimension size) {
+ public Improver(Settings confSettings, GenerationHandler genHandler, Dimension size) {
settings = confSettings;
+ generationHandler = genHandler;
imageSize = size;
stats = new ImprovementTypeStats();
r = new Random();
}
/**
- * sets the new set of polygons by copying them
- *
- * @param data the best set of polygon data so far
- */
- public void setData(PolygonData[] data) {
- polygons = new LinkedList<PolygonData>(Arrays.<PolygonData>asList(data));
- }
-
- /**
* get the list of polygons usually after attempted to be improved
*
* @return the list of polygons
@@ -86,12 +80,16 @@
* @return the improvement type used to alter the data
*/
public ImprovementType improveRandomly() {
- if (polygons.isEmpty()) {
- polygons.add(PolygonData.randomPoly(imageSize, settings.getMaxPoints()));
- return ImprovementType.AddPolygon;
+
+ {
+ PolygonData[] randomData = generationHandler.getRandomPolygonData(false);
+ if (randomData != null)
+ polygons = new ArrayList<PolygonData>(Arrays.asList(randomData.clone()));
+ else
+ polygons = new ArrayList<PolygonData>();
}
- ImprovementType type = stats.getRandomImprovementType();
+ ImprovementType type = (polygons.isEmpty()) ? ImprovementType.AddPolygon : stats.getRandomImprovementType();
switch (type) {
case AddPolygon: {
@@ -292,6 +290,24 @@
}
break;
+ case White: {
+ int idx = r.nextInt(polygons.size());
+ PolygonData pd = (PolygonData)polygons.get(idx).clone();
+ pd.setColor(Color.WHITE);
+ pd.setAlpha(1);
+ polygons.set(idx, pd);
+ }
+ break;
+
+ case Black: {
+ int idx = r.nextInt(polygons.size());
+ PolygonData pd = (PolygonData)polygons.get(idx).clone();
+ pd.setColor(Color.BLACK);
+ pd.setAlpha(1);
+ polygons.set(idx, pd);
+ }
+ break;
+
case ChangeAlpha:
int idx = r.nextInt(polygons.size());
PolygonData pd = (PolygonData)polygons.get(idx).clone();
@@ -299,6 +315,36 @@
polygons.set(idx, pd);
break;
+ case Breed: {
+ PolygonData[] copyData = generationHandler.getRandomPolygonData(false);
+ if ((copyData == null) || (copyData.length == 0)) {
+ randomCompleteChange();
+ } else {
+ idx = r.nextInt(copyData.length);
+ if (idx >= polygons.size()) {
+ polygons.add(copyData[idx]);
+ } else {
+ polygons.set(idx, copyData[idx]);
+ }
+ }
+ }
+ break;
+
+ case BreedElite: {
+ PolygonData[] copyData = generationHandler.getRandomPolygonData(true);
+ if ((copyData == null) || (copyData.length == 0)) {
+ randomCompleteChange();
+ } else {
+ idx = r.nextInt(copyData.length);
+ if (idx >= polygons.size()) {
+ polygons.add(copyData[idx]);
+ } else {
+ polygons.set(idx, copyData[idx]);
+ }
+ }
+ }
+ break;
+
case CompleteChange: {
randomCompleteChange();
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2010-10-03 05:47:22 UTC (rev 227)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -222,9 +222,13 @@
dialog.setVisible(true);
if (dialog.isOK()) {
Settings dlgSettings = dialog.getSettings();
+ settings.setGenerationSize(dlgSettings.getGenerationSize());
+ settings.setEliteSize(dlgSettings.getEliteSize());
+ settings.setUseAnnealing(dlgSettings.isUseAnnealing());
+ settings.setStartTemperature(dlgSettings.getStartTemperature());
+ settings.setCoolingRate(dlgSettings.getCoolingRate());
settings.setMaxImageSize(dlgSettings.getMaxImageSize());
settings.setMaxPolygons(dlgSettings.getMaxPolygons());
- settings.setNumCompetingImages(dlgSettings.getNumCompetingImages());
settings.setMaxPoints(dlgSettings.getMaxPoints());
settings.setMaxPtMovement(dlgSettings.getMaxPtMovement());
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java 2010-10-03 05:47:22 UTC (rev 227)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -28,7 +28,7 @@
/**
* enable some console debugging, and show the target image
*/
- public static final boolean DEBUG = false;
+ public static final boolean DEBUG = true;
/**
* the main entry point to the web start app
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java 2010-10-03 05:47:22 UTC (rev 227)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -175,4 +175,20 @@
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
g.fillPolygon(polygon);
}
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("(");
+ String sep = "";
+ for (int i = 0; i < polygon.npoints; i++) {
+ sb.append(sep);
+ sep = "|";
+ sb.append(polygon.xpoints[i]);
+ sb.append(",");
+ sb.append(polygon.ypoints[i]);
+ }
+ sb.append(")");
+ return sb.toString();
+ }
}
\ No newline at end of file
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2010-10-03 05:47:22 UTC (rev 227)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -35,7 +35,6 @@
private double startTemperature;
private double coolingRate;
private Dimension maxImageSize;
- private int numCompetingImages;
private int maxPolygons;
private int maxPoints;
private int maxPtMovement;
@@ -45,14 +44,13 @@
* constructs a settings object with rational defaults
*/
public Settings() {
- generationSize = 50;
+ generationSize = 40;
eliteSize = 10;
useAnnealing = true;
- startTemperature = 20;
- coolingRate = 0.1;
+ startTemperature = 1;
+ coolingRate = 0.01;
maxImageSize = new Dimension(800, 600);
maxPolygons = 100;
- numCompetingImages = 20;
maxPoints = 7;
maxPtMovement = 20;
maxColorChange = 40;
@@ -72,19 +70,38 @@
}
}
-
+ /**
+ * sets the generation size
+ *
+ * @param generationSz the size of each generation
+ */
public void setGenerationSize(int generationSz) {
generationSize = generationSz;
}
+ /**
+ * gets the generation size
+ *
+ * @return the generation size
+ */
public int getGenerationSize() {
return generationSize;
}
+ /**
+ * sets the elite size, the number of members that are copied from one generation to another
+ *
+ * @param eliteSz the elite size
+ */
public void setEliteSize(int eliteSz) {
eliteSize = eliteSz;
}
+ /**
+ * gets the elite size, the number of members that are copied from one generation to another
+ *
+ * @return the elite size
+ */
public int getEliteSize() {
return eliteSize;
}
@@ -107,18 +124,38 @@
return useAnnealing;
}
+ /**
+ * sets the error below which polygon samples can be included in a generation, even if not the best
+ *
+ * @param startTemp the pixel error cutoff
+ */
public void setStartTemperature(double startTemp) {
startTemperature = startTemp;
}
+ /**
+ * gets the error below wich polygon samples can be included in a generation, even if not the best
+ *
+ * @return the pixel error cutoff
+ */
public double getStartTemperature() {
return startTemperature;
}
+ /**
+ * sets how quickly the error cutoff decrements each generation
+ *
+ * @param coolRate the cutoff decrementor value
+ */
public void setCoolingRate(double coolRate) {
coolingRate = coolRate;
}
+ /**
+ * gets how quickly the error cutoff decrements each generation
+ *
+ * @return the cutoff decrementor value
+ */
public double getCoolingRate() {
return coolingRate;
}
@@ -142,24 +179,6 @@
}
/**
- * set the number of images that are competing in parallel for the best image
- *
- * @param competingImages number of images
- */
- public void setNumCompetingImages(int competingImages) {
- numCompetingImages = competingImages;
- }
-
- /**
- * gets the number of images that are competing in parallel for the best image
- *
- * @return the number of images
- */
- public int getNumCompetingImages() {
- return numCompetingImages;
- }
-
- /**
* sets the maximum polygons that can be used to image the picture
*
* @param maxPolys the maximum number of polygons
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2010-10-03 05:47:22 UTC (rev 227)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2010-10-03 05:59:39 UTC (rev 228)
@@ -61,7 +61,6 @@
private JTextField widthField;
private JTextField heightField;
private JTextField maxPolygonField;
- private JTextField numCompetingImagesField;
private JTextField maxPolygonPointsField;
private JTextField maxPtMoveField;
private JTextField maxColorChangeField;
@@ -130,7 +129,7 @@
JPanel optPanel = new JPanel();
optPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(PolycassoBundle.getString(PolycassoBundle.Key.ImageOptions)),
BorderFactory.createEmptyBorder(10, 10, 10, 10)));
- optPanel.setLayout(new FormLayout("pref, 3dlu, 100px, 5dlu, pref, 3dlu, 100px", "pref, 1dlu, pref, 15dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref"));
+ optPanel.setLayout(new FormLayout("pref, 3dlu, 100px, 5dlu, pref, 3dlu, 100px", "pref, 1dlu, pref, 15dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref"));
CellConstraints cc = new CellConstraints();
JLabel maxSizeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaxImageSize));
@@ -159,37 +158,29 @@
maxPolyLabel.setLabelFor(maxPolygonField);
optPanel.add(maxPolygonField, cc.xy(7, 5));
maxPolygonField.addFocusListener(focuser);
-
- JLabel numCompetingImagesLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.NumberOfCompetingImages));
- optPanel.add(numCompetingImagesLabel, cc.xyw(1, 7, 5));
- numCompetingImagesField = new JTextField(4);
- numCompetingImagesField.setDocument(new IntegerDocument());
- numCompetingImagesLabel.setLabelFor(numCompetingImagesField);
- optPanel.add(numCompetingImagesField, cc.xy(7, 7));
- numCompetingImagesField.addFocusListener(focuser);
-
+
JLabel maxPolyPointLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaximumPolygonPoints));
- optPanel.add(maxPolyPointLabel, cc.xyw(1, 9, 7));
+ optPanel.add(maxPolyPointLabel, cc.xyw(1, 7, 7));
maxPolygonPointsField = new JTextField(4);
maxPolygonPointsField.setDocument(new IntegerDocument());
maxPolyPointLabel.setLabelFor(maxPolygonPointsField);
- optPanel.add(maxPolygonPointsField, cc.xy(7, 9));
+ optPanel.add(maxPolygonPointsField, cc.xy(7, 7));
maxPolygonPointsField.addFocusListener(focuser);
JLabel maxPtMoveLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaximumPointMovement));
- optPanel.add(maxPtMoveLabel, cc.xyw(1, 11, 5));
+ optPanel.add(maxPtMoveLabel, cc.xyw(1, 9, 5));
maxPtMoveField = new JTextField(4);
maxPtMoveField.setDocument(new IntegerDocument());
maxPtMoveLabel.setLabelFor(maxPtMoveField);
- optPanel.add(maxPtMoveField, cc.xy(7, 11));
+ optPanel.add(maxPtMoveField, cc.xy(7, 9));
maxPtMoveField.addFocusListener(focuser);
JLabel maxColorChangeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaximumColorChange));
- optPanel.add(maxColorChangeLabel, cc.xyw(1, 13, 5));
+ optPanel.add(maxColorChangeLabel, cc.xyw(1, 11, 5));
maxColorChangeField = new JTextField(4);
maxColorChangeField.setDocument(new IntegerDocument());
maxColorChangeLabel.setLabelFor(maxColorChangeField);
- optPanel.add(maxColorChangeField, cc.xy(7, 13));
+ optPanel.add(maxColorChangeField, cc.xy(7, 11));
maxColorChangeField.addFocusListener(focuser);
populateValues();
@@ -260,7 +251,6 @@
widthField.setText(String.valueOf(dlgSettings.getMaxImageSize().width));
heightField.setText(String.valueOf(dlgSettings.getMaxImageSize().height));
maxPolygonField.setText(String.valueOf(dlgSettings.getMaxPolygons()));
- numCompetingImagesField.setText(String.valueOf(dlgSettings.getNumCompetingImages()));
maxPolygonPointsField.setText(String.valueOf(dlgSettings.getMaxPoints()));
maxPtMoveField.setText(String.valueOf(dlgSettings.getMaxPtMovement()));
maxColorChangeField.setText(String.valueOf(dlgSettings.getMaxColorChange()));
@@ -316,9 +306,13 @@
okButton.addActionList...
[truncated message content] |
|
From: <dbr...@us...> - 2009-11-28 23:37:24
|
Revision: 95
http://polycasso.svn.sourceforge.net/polycasso/?rev=95&view=rev
Author: dbrosius
Date: 2009-11-28 23:37:18 +0000 (Sat, 28 Nov 2009)
Log Message:
-----------
limit image size to the settings limit
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-11-28 23:32:38 UTC (rev 94)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-11-28 23:37:18 UTC (rev 95)
@@ -38,6 +38,7 @@
public class ImageGenerator implements Runnable {
private static int attempt = 0;
private Set<ImageGeneratedListener> listeners = new HashSet<ImageGeneratedListener>();
+ private Settings settings;
private BufferedImage targetImage;
private PolygonData[] bestData;
private double bestScore = Double.MAX_VALUE;
@@ -49,20 +50,31 @@
/**
* creates an ImageGenerator for the given target image, and size
+ * @param settings the configuration settings
* @param image the target image
- *
* @param size the dimension of the image
*/
- public ImageGenerator(Image image, Dimension size) {
- targetImage = new BufferedImage(size.width, size.height, BufferedImage.TYPE_4BYTE_ABGR);
+ public ImageGenerator(Settings confSettings, Image image, Dimension size) {
+ settings = confSettings;
+ imageSize = trimSize(size, settings.getMaxImageSize());
+ targetImage = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = targetImage.getGraphics();
- g.drawImage(image, 0, 0, size.width, size.height, Color.WHITE, null);
+ g.drawImage(image, 0, 0, imageSize.width, imageSize.height, Color.WHITE, null);
feedback = new Feedback(targetImage);
- imageSize = size;
bestData = new PolygonData[0];
}
/**
+ * returns the image size that is being generated. This size might be different the original image
+ * if the size is bigger then the max setting.
+ *
+ * @return the image size
+ */
+ public Dimension getImageSize() {
+ return imageSize;
+ }
+
+ /**
* allows interested parties to register to receive events when a new best image has been
* found.
*
@@ -204,4 +216,16 @@
e.printStackTrace();
}
}
+
+ private Dimension trimSize(Dimension origSize, Dimension maxSize) {
+ if ((origSize.width < maxSize.width) && (origSize.height < maxSize.height))
+ return origSize;
+
+ double hFrac = (double)maxSize.width / (double)origSize.width;
+ double vFrac = (double)maxSize.height/ (double)origSize.height;
+
+ double frac = (hFrac < vFrac) ? hFrac : vFrac;
+
+ return new Dimension((int)(frac * origSize.width), (int)(frac * origSize.height));
+ }
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-28 23:32:38 UTC (rev 94)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-28 23:37:18 UTC (rev 95)
@@ -132,7 +132,7 @@
wSize.height *= 2;
}
setSize(wSize);
- generator = new ImageGenerator(targetImage, size);
+ generator = new ImageGenerator(settings, targetImage, size);
generator.addImageGeneratedListener(PainterFrame.this);
generator.startGenerating();
completeImage.setEnabled(true);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-11-28 23:41:51
|
Revision: 96
http://polycasso.svn.sourceforge.net/polycasso/?rev=96&view=rev
Author: dbrosius
Date: 2009-11-28 23:41:42 +0000 (Sat, 28 Nov 2009)
Log Message:
-----------
push settings to the improver to use for maxpolys and maxptmovement
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-11-28 23:37:18 UTC (rev 95)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-11-28 23:41:42 UTC (rev 96)
@@ -166,7 +166,7 @@
BufferedImage image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2d = (Graphics2D)image.getGraphics();
Composite srcOpaque = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f);
- Improver improver = new Improver(imageSize);
+ Improver improver = new Improver(null, imageSize);
while (!Thread.interrupted()) {
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java 2009-11-28 23:37:18 UTC (rev 95)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java 2009-11-28 23:41:42 UTC (rev 96)
@@ -33,9 +33,7 @@
* polygons have had success being transformed.
*/
public class Improver {
- public static final int NUM_POLYS = 50;
- public static final int MAX_PT_MOVEMENT = 20;
-
+ private Settings settings;
private Dimension imageSize;
private List<PolygonData> polygons = null;
private ImprovementTypeStats stats;
@@ -43,10 +41,11 @@
/**
* create an improver using a specified image size
- *
+ * @param confSettings the settings to be used
* @param size the size of the image
*/
- public Improver(Dimension size) {
+ public Improver(Settings confSettings, Dimension size) {
+ settings = confSettings;
imageSize = size;
stats = new ImprovementTypeStats();
r = new Random();
@@ -96,7 +95,7 @@
switch (type) {
case AddPolygon: {
- if (polygons.size() < NUM_POLYS) {
+ if (polygons.size() < settings.getMaxPolygons()) {
PolygonData pd = PolygonData.randomPoly(imageSize);
polygons.add(pd);
} else {
@@ -121,8 +120,9 @@
polygon.addPoint(0, 0);
int insPos = r.nextInt(polygon.npoints);
int lastPt = (insPos + polygon.npoints - 1) % polygon.npoints;
- int maxX = Math.max(MAX_PT_MOVEMENT, Math.abs(polygon.xpoints[lastPt] - polygon.xpoints[insPos]));
- int maxY = Math.max(MAX_PT_MOVEMENT, Math.abs(polygon.ypoints[lastPt] - polygon.ypoints[insPos]));
+ int maxMovement = settings.getMaxPtMovement();
+ int maxX = Math.max(maxMovement, Math.abs(polygon.xpoints[lastPt] - polygon.xpoints[insPos]));
+ int maxY = Math.max(maxMovement, Math.abs(polygon.ypoints[lastPt] - polygon.ypoints[insPos]));
int x = r.nextInt(maxX) + Math.min(polygon.xpoints[lastPt], polygon.xpoints[insPos]);
int y = r.nextInt(maxY) + Math.min(polygon.ypoints[lastPt], polygon.ypoints[insPos]);
@@ -165,8 +165,9 @@
PolygonData pd = (PolygonData)polygons.get(idx).clone();
Polygon polygon = pd.getPolygon();
int movePos = r.nextInt(polygon.npoints);
- int moveX = r.nextInt(MAX_PT_MOVEMENT * 2) - MAX_PT_MOVEMENT;
- int moveY = r.nextInt(MAX_PT_MOVEMENT * 2) - MAX_PT_MOVEMENT;
+ int maxMovement = settings.getMaxPtMovement();
+ int moveX = r.nextInt(maxMovement * 2) - maxMovement;
+ int moveY = r.nextInt(maxMovement * 2) - maxMovement;
polygon.xpoints[movePos] += moveX;
polygon.ypoints[movePos] += moveY;
clipToRange(0, imageSize.width, polygon.xpoints[movePos]);
@@ -213,7 +214,7 @@
double midX = bbox.getCenterX();
double midY = bbox.getCenterY();
- int shrinkFactor = r.nextInt(MAX_PT_MOVEMENT);
+ int shrinkFactor = r.nextInt(settings.getMaxPtMovement());
for (int i = 0; i < polygon.npoints; i++) {
polygon.xpoints[i] += (polygon.xpoints[i] < midX) ? shrinkFactor : -shrinkFactor;
polygon.ypoints[i] += (polygon.ypoints[i] < midY) ? shrinkFactor : -shrinkFactor;
@@ -231,7 +232,7 @@
double midX = bbox.getCenterX();
double midY = bbox.getCenterY();
- int expandFactor = r.nextInt(MAX_PT_MOVEMENT);
+ int expandFactor = r.nextInt(settings.getMaxPtMovement());
for (int i = 0; i < polygon.npoints; i++) {
polygon.xpoints[i] += (polygon.xpoints[i] < midX) ? -expandFactor : expandFactor;
polygon.ypoints[i] += (polygon.ypoints[i] < midY) ? -expandFactor : expandFactor;
@@ -246,8 +247,9 @@
int idx = r.nextInt(polygons.size());
PolygonData pd = (PolygonData)polygons.get(idx).clone();
Polygon polygon = pd.getPolygon();
- int shiftX = r.nextInt(2 * MAX_PT_MOVEMENT) + MAX_PT_MOVEMENT;
- int shiftY = r.nextInt(2 * MAX_PT_MOVEMENT) + MAX_PT_MOVEMENT;
+ int maxMovement = settings.getMaxPtMovement();
+ int shiftX = r.nextInt(2 * maxMovement) + maxMovement;
+ int shiftY = r.nextInt(2 * maxMovement) + maxMovement;
for (int i = 0; i < polygon.npoints; i++) {
polygon.xpoints[i] += shiftX;
polygon.ypoints[i] += shiftY;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-11-29 02:49:07
|
Revision: 108
http://polycasso.svn.sourceforge.net/polycasso/?rev=108&view=rev
Author: dbrosius
Date: 2009-11-29 02:48:59 +0000 (Sun, 29 Nov 2009)
Log Message:
-----------
add max points per poly to settings, and add validation to the settings dialog
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java
trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java 2009-11-29 02:28:13 UTC (rev 107)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java 2009-11-29 02:48:59 UTC (rev 108)
@@ -87,7 +87,7 @@
*/
public ImprovementType improveRandomly() {
if (polygons.isEmpty()) {
- polygons.add(PolygonData.randomPoly(imageSize));
+ polygons.add(PolygonData.randomPoly(imageSize, settings.getMaxPoints()));
return ImprovementType.AddPolygon;
}
@@ -96,7 +96,7 @@
switch (type) {
case AddPolygon: {
if (polygons.size() < settings.getMaxPolygons()) {
- PolygonData pd = PolygonData.randomPoly(imageSize);
+ PolygonData pd = PolygonData.randomPoly(imageSize, settings.getMaxPoints());
polygons.add(pd);
} else {
randomCompleteChange();
@@ -116,7 +116,7 @@
int idx = r.nextInt(polygons.size());
PolygonData pd = (PolygonData)polygons.get(idx).clone();
Polygon polygon = pd.getPolygon();
- if (polygon.npoints <= PolygonData.MAX_POINTS) {
+ if (polygon.npoints <= settings.getMaxPoints()) {
polygon.addPoint(0, 0);
int insPos = r.nextInt(polygon.npoints);
int lastPt = (insPos + polygon.npoints - 1) % polygon.npoints;
@@ -312,7 +312,7 @@
*/
private void randomCompleteChange() {
int idx = r.nextInt(polygons.size());
- polygons.set(idx, PolygonData.randomPoly(imageSize));
+ polygons.set(idx, PolygonData.randomPoly(imageSize, settings.getMaxPoints()));
}
/**
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-29 02:28:13 UTC (rev 107)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-11-29 02:48:59 UTC (rev 108)
@@ -174,6 +174,7 @@
Settings dlgSettings = dialog.getSettings();
settings.setMaxImageSize(dlgSettings.getMaxImageSize());
settings.setMaxPolygons(dlgSettings.getMaxPolygons());
+ settings.setMaxPoints(dlgSettings.getMaxPoints());
settings.setMaxPtMovement(dlgSettings.getMaxPtMovement());
}
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-11-29 02:28:13 UTC (rev 107)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-11-29 02:48:59 UTC (rev 108)
@@ -45,7 +45,9 @@
Width("pc.width"),
Height("pc.height"),
MaximumPolygons("pc.maximumpolygons"),
- MaximumPointMovement("pc.maximumpointmovement");
+ MaximumPolygonPoints("pc.maxpolygonpoints"),
+ MaximumPointMovement("pc.maximumpointmovement"),
+ BadSetting("pc.badsetting");
String id;
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java 2009-11-29 02:28:13 UTC (rev 107)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java 2009-11-29 02:48:59 UTC (rev 108)
@@ -30,7 +30,6 @@
* and alpha level.
*/
public class PolygonData implements Cloneable {
- public static final int MAX_POINTS = 8;
private Color color;
private float alpha;
@@ -71,10 +70,10 @@
* @param size the maximum size of the bounding box of the polygon
* @return a random polygon
*/
- public static PolygonData randomPoly(Dimension size) {
+ public static PolygonData randomPoly(Dimension size, int maxPoints) {
Random r = new Random();
Polygon polygon = new Polygon();
- int numPoints = r.nextInt(MAX_POINTS - 3) + 3;
+ int numPoints = r.nextInt(maxPoints - 3) + 3;
for (int i = 0; i < numPoints; i++) {
polygon.addPoint(r.nextInt(size.width), r.nextInt(size.height));
@@ -98,7 +97,7 @@
return clone;
} catch (CloneNotSupportedException cnse) {
- return randomPoly(new Dimension(100, 100));
+ return randomPoly(new Dimension(100, 100), 3);
}
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2009-11-29 02:28:13 UTC (rev 107)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2009-11-29 02:48:59 UTC (rev 108)
@@ -32,6 +32,7 @@
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
+import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;
@@ -49,6 +50,7 @@
private JTextField widthField;
private JTextField heightField;
private JTextField maxPolygonField;
+ private JTextField maxPolygonPointsField;
private JTextField maxPtMoveField;
private boolean isOK;
@@ -82,7 +84,7 @@
SelectAllFocuser focuser = new SelectAllFocuser();
JPanel optPanel = new JPanel();
optPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
- optPanel.setLayout(new FormLayout("pref, 3dlu, 100px, 5dlu, pref, 3dlu, 100px", "pref, 1dlu, pref, 15dlu, pref, 1dlu, pref"));
+ optPanel.setLayout(new FormLayout("pref, 3dlu, 100px, 5dlu, pref, 3dlu, 100px", "pref, 1dlu, pref, 15dlu, pref, 1dlu, pref, 1dlu, pref"));
CellConstraints cc = new CellConstraints();
JLabel maxSizeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaxImageSize));
@@ -115,13 +117,22 @@
optPanel.add(maxPolygonField, cc.xy(7, 5));
maxPolygonField.addFocusListener(focuser);
+ JLabel maxPolyPointLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaximumPolygonPoints));
+ optPanel.add(maxPolyPointLabel, cc.xyw(1, 7, 7));
+ maxPolygonPointsField = new JTextField(4);
+ maxPolygonPointsField.setDocument(new IntegerDocument());
+ maxPolyPointLabel.setLabelFor(maxPolygonPointsField);
+ maxPolygonPointsField.setText(String.valueOf(dlgSettings.getMaxPoints()));
+ optPanel.add(maxPolygonPointsField, cc.xy(7, 7));
+ maxPolygonPointsField.addFocusListener(focuser);
+
JLabel maxPtMoveLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.MaximumPointMovement));
- optPanel.add(maxPtMoveLabel, cc.xyw(1, 7, 5));
+ optPanel.add(maxPtMoveLabel, cc.xyw(1, 9, 5));
maxPtMoveField = new JTextField(4);
maxPtMoveField.setDocument(new IntegerDocument());
maxPtMoveLabel.setLabelFor(maxPtMoveField);
maxPtMoveField.setText(String.valueOf(dlgSettings.getMaxPtMovement()));
- optPanel.add(maxPtMoveField, cc.xy(7, 7));
+ optPanel.add(maxPtMoveField, cc.xy(7, 9));
maxPtMoveField.addFocusListener(focuser);
return optPanel;
}
@@ -148,9 +159,13 @@
public void actionPerformed(ActionEvent ae) {
dlgSettings.setMaxImageSize(new Dimension(Integer.parseInt(widthField.getText()), Integer.parseInt(heightField.getText())));
dlgSettings.setMaxPolygons(Integer.parseInt(maxPolygonField.getText()));
+ dlgSettings.setMaxPoints(Integer.parseInt(maxPolygonPointsField.getText()));
dlgSettings.setMaxPtMovement(Integer.parseInt(maxPtMoveField.getText()));
- isOK = true;
- dispose();
+
+ if (validateSettings()) {
+ isOK = true;
+ dispose();
+ }
}
});
@@ -173,7 +188,31 @@
@Override
public void focusLost(FocusEvent fe) {
+ }
+ }
+
+ private boolean validateSettings() {
+ if (dlgSettings.getMaxImageSize().width < 10) {
+ widthField.setText("10");
+ widthField.requestFocus();
+ } else if (dlgSettings.getMaxImageSize().height < 10) {
+ heightField.setText("10");
+ heightField.requestFocus();
+ } else if (dlgSettings.getMaxPolygons() < 10) {
+ maxPolygonField.setText("10");
+ maxPolygonField.requestFocus();
+ } else if (dlgSettings.getMaxPoints() < 3) {
+ maxPolygonPointsField.setText("3");
+ maxPolygonPointsField.requestFocus();
+ } else if (dlgSettings.getMaxPtMovement() < 5) {
+ maxPtMoveField.setText("5");
+ maxPtMoveField.requestFocus();
+ } else {
+ return true;
}
+ JOptionPane.showMessageDialog(this, PolycassoBundle.getString(PolycassoBundle.Key.BadSetting));
+ return false;
+
}
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-11-29 02:28:13 UTC (rev 107)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-11-29 02:48:59 UTC (rev 108)
@@ -32,4 +32,6 @@
pc.width = Width
pc.height = Height
pc.maximumpolygons = Maximum Polygons
+pc.maxpolygonpoints = Maximum Points per Polygon
pc.maximumpointmovement = Maximum Point Movement
+pc.badsetting = The setting specified was too small to properly function
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-12-07 05:05:15
|
Revision: 148
http://polycasso.svn.sourceforge.net/polycasso/?rev=148&view=rev
Author: dbrosius
Date: 2009-12-07 05:05:07 +0000 (Mon, 07 Dec 2009)
Log Message:
-----------
stub in specific savers
Added Paths:
-----------
trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PNGSaver.java
trunk/polycasso/src/com/mebigfatguy/polycasso/SVGSaver.java
Added: trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java (rev 0)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java 2009-12-07 05:05:07 UTC (rev 148)
@@ -0,0 +1,33 @@
+/*
+ * polycasso - Cubism Artwork generator
+ * Copyright 2009 MeBigFatGuy.com
+ * Copyright 2009 Dave Brosius
+ * Inspired by work by Roger Alsing
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package com.mebigfatguy.polycasso;
+
+import java.awt.Dimension;
+import java.io.IOException;
+
+public class JavaSaver implements Saver {
+
+ @Override
+ public void save(String fileName, Dimension imageSize, PolygonData[] data)
+ throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on: trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/polycasso/src/com/mebigfatguy/polycasso/PNGSaver.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PNGSaver.java (rev 0)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PNGSaver.java 2009-12-07 05:05:07 UTC (rev 148)
@@ -0,0 +1,33 @@
+/*
+ * polycasso - Cubism Artwork generator
+ * Copyright 2009 MeBigFatGuy.com
+ * Copyright 2009 Dave Brosius
+ * Inspired by work by Roger Alsing
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package com.mebigfatguy.polycasso;
+
+import java.awt.Dimension;
+import java.io.IOException;
+
+public class PNGSaver implements Saver {
+
+ @Override
+ public void save(String fileName, Dimension imageSize, PolygonData[] data)
+ throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on: trunk/polycasso/src/com/mebigfatguy/polycasso/PNGSaver.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/polycasso/src/com/mebigfatguy/polycasso/SVGSaver.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/SVGSaver.java (rev 0)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/SVGSaver.java 2009-12-07 05:05:07 UTC (rev 148)
@@ -0,0 +1,33 @@
+/*
+ * polycasso - Cubism Artwork generator
+ * Copyright 2009 MeBigFatGuy.com
+ * Copyright 2009 Dave Brosius
+ * Inspired by work by Roger Alsing
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package com.mebigfatguy.polycasso;
+
+import java.awt.Dimension;
+import java.io.IOException;
+
+public class SVGSaver implements Saver {
+
+ @Override
+ public void save(String fileName, Dimension imageSize, PolygonData[] data)
+ throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on: trunk/polycasso/src/com/mebigfatguy/polycasso/SVGSaver.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-12-07 05:21:13
|
Revision: 154
http://polycasso.svn.sourceforge.net/polycasso/?rev=154&view=rev
Author: dbrosius
Date: 2009-12-07 05:21:07 +0000 (Mon, 07 Dec 2009)
Log Message:
-----------
more save implementation
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/FileSelector.java
trunk/polycasso/src/com/mebigfatguy/polycasso/FileType.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/FileSelector.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/FileSelector.java 2009-12-07 05:08:22 UTC (rev 153)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/FileSelector.java 2009-12-07 05:21:07 UTC (rev 154)
@@ -21,6 +21,7 @@
import java.io.File;
import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
public class FileSelector {
@@ -32,6 +33,8 @@
public String getFileName() {
JFileChooser chooser = new JFileChooser();
+ chooser.setFileFilter(new PolyFilter());
+ chooser.setDialogTitle(PolycassoBundle.getString(PolycassoBundle.Key.SaveAs));
int option = chooser.showSaveDialog(null);
if (option == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
@@ -46,4 +49,22 @@
return null;
}
+
+ class PolyFilter extends FileFilter {
+
+ @Override
+ public boolean accept(File file) {
+ if (file.isDirectory()) {
+ return true;
+ }
+
+ return (file.getPath().endsWith(fileType.getExtension()));
+ }
+
+ @Override
+ public String getDescription() {
+ return fileType.getDescription();
+ }
+
+ }
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/FileType.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/FileType.java 2009-12-07 05:08:22 UTC (rev 153)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/FileType.java 2009-12-07 05:21:07 UTC (rev 154)
@@ -20,31 +20,37 @@
public enum FileType {
- PNG(".png") {
+ PNG(".png", PolycassoBundle.Key.PNGDescription) {
public Saver getSaver() {
return new PNGSaver();
}
},
- SVG(".svg") {
+ SVG(".svg", PolycassoBundle.Key.SVGDescription) {
public Saver getSaver() {
return new SVGSaver();
}
},
- Java(".java") {
+ Java(".java", PolycassoBundle.Key.JAVADescription) {
public Saver getSaver() {
return new JavaSaver();
}
};
private String extension;
+ private PolycassoBundle.Key descriptionKey;
- FileType(String ext) {
+ FileType(String ext, PolycassoBundle.Key descKey) {
extension = ext;
+ descriptionKey = descKey;
}
public String getExtension() {
return extension;
}
+ public String getDescription() {
+ return PolycassoBundle.getString(descriptionKey);
+ }
+
public abstract Saver getSaver();
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-12-07 05:08:22 UTC (rev 153)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-12-07 05:21:07 UTC (rev 154)
@@ -38,8 +38,11 @@
CompleteImage("pc.completeimage"),
SaveAs("pc.saveas"),
PNG("pc.png"),
+ PNGDescription("pc.pngdescription"),
SVG("pc.svg"),
+ SVGDescription("pc.svgdescription"),
JAVA("pc.java"),
+ JAVADescription("pc.javadescription"),
Quit("pc.quit"),
Edit("pc.edit"),
Settings("pc.settings"),
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-12-07 05:08:22 UTC (rev 153)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-12-07 05:21:07 UTC (rev 154)
@@ -25,8 +25,11 @@
pc.completeimage = Complete Image
pc.saveas = Save as
pc.png = PNG
+pc.pngdescription = (*.png) PNG Image files
pc.svg = SVG
+pc.svgdescription = (*.svg) Scalable Vector Graphics files
pc.java = Java class
+pc.javadescription = (*.java) Java Class files
pc.quit = Quit
pc.edit = Edit
pc.settings = Settings
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-12-10 05:03:32
|
Revision: 171
http://polycasso.svn.sourceforge.net/polycasso/?rev=171&view=rev
Author: dbrosius
Date: 2009-12-10 05:03:19 +0000 (Thu, 10 Dec 2009)
Log Message:
-----------
add an overwrite confirm dialog
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-12-10 04:12:46 UTC (rev 170)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-12-10 05:03:19 UTC (rev 171)
@@ -26,6 +26,7 @@
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
@@ -249,6 +250,13 @@
FileSelector selector = new FileSelector(type);
String fileName = selector.getFileName();
if (fileName != null) {
+ File f = new File(fileName);
+ if (f.exists()) {
+ String message = MessageFormat.format(PolycassoBundle.getString(PolycassoBundle.Key.OverwriteWarning), fileName);
+ int choice = JOptionPane.showConfirmDialog(PainterFrame.this, message, PolycassoBundle.getString(PolycassoBundle.Key.SaveAs), JOptionPane.YES_NO_OPTION);
+ if (choice != JOptionPane.YES_OPTION)
+ return;
+ }
type.getSaver().save(fileName, generator.getImageSize(), generator.getBestData());
}
} catch (IOException ioe) {
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-12-10 04:12:46 UTC (rev 170)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-12-10 05:03:19 UTC (rev 171)
@@ -57,7 +57,8 @@
MaximumPointMovement("pc.maximumpointmovement"),
MaximumColorChange("pc.maximumcolorchange"),
BadSetting("pc.badsetting"),
- SaveFailure("pc.savefailure");
+ SaveFailure("pc.savefailure"),
+ OverwriteWarning("pc.overwritewarning");
String id;
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-12-10 04:12:46 UTC (rev 170)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-12-10 05:03:19 UTC (rev 171)
@@ -45,3 +45,4 @@
pc.maximumcolorchange = Maximum Color Change
pc.badsetting = The setting specified was too small to properly function
pc.savefailure = Failed saving file: {0}
+pc.overwritewarning = The file {0} already exists, do you wish to overwrite it?
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-12-18 05:50:42
|
Revision: 197
http://polycasso.svn.sourceforge.net/polycasso/?rev=197&view=rev
Author: dbrosius
Date: 2009-12-18 04:33:04 +0000 (Fri, 18 Dec 2009)
Log Message:
-----------
add building an image from a user specified url
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-12-18 04:27:18 UTC (rev 196)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-12-18 04:33:04 UTC (rev 197)
@@ -30,6 +30,7 @@
import java.io.IOException;
import java.text.MessageFormat;
+import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
@@ -44,6 +45,7 @@
private static final long serialVersionUID = 7729602294481171194L;
private PainterPanel panel;
private JMenuItem paintImage;
+ private JMenuItem copyImage;
private JMenuItem completeImage;
private JMenu saveAsMenu;
private JMenuItem saveAsPNGItem;
@@ -87,6 +89,8 @@
JMenu fileMenu = new JMenu(PolycassoBundle.getString(PolycassoBundle.Key.File));
paintImage = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.PaintImage));
fileMenu.add(paintImage);
+ copyImage = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.CopyImage));
+ fileMenu.add(copyImage);
completeImage = new JMenuItem(PolycassoBundle.getString(PolycassoBundle.Key.CompleteImage));
completeImage.setEnabled(false);
fileMenu.add(completeImage);
@@ -135,31 +139,25 @@
@Override
public void actionPerformed(ActionEvent ae) {
try {
- if (generator != null)
- generator.stopGenerating();
-
Image targetImage = RandomImageFinder.findImage();
- ImageSizer sizer = new ImageSizer(targetImage);
- Dimension size = new Dimension(sizer.getWidth(), sizer.getHeight());
- generator = new ImageGenerator(settings, targetImage, size);
-
- panel.setTarget(generator.getTargetImage());
- size = generator.getImageSize();
-
- Dimension wSize = new Dimension(size);
- wSize.height += 2 * PainterFrame.this.getJMenuBar().getHeight();
- if (Polycasso.DEBUG){
- wSize.height *= 2;
+ beginGenerating(targetImage);
+ } catch (IOException ioe) {
+ JOptionPane.showMessageDialog(PainterFrame.this, ioe.getMessage());
+ }
+ }
+ });
+
+ copyImage.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ try {
+ String url = JOptionPane.showInputDialog(PainterFrame.this, PolycassoBundle.getString(PolycassoBundle.Key.EnterURL));
+ if (url != null) {
+ Image targetImage = new ImageIcon(URLFetcher.fetchURLData(url)).getImage();
+ beginGenerating(targetImage);
}
- setSize(wSize);
- generator = new ImageGenerator(settings, targetImage, size);
- generator.addImageGeneratedListener(PainterFrame.this);
- generator.startGenerating();
- completeImage.setEnabled(true);
- saveAsMenu.setEnabled(true);
-
} catch (IOException ioe) {
- JOptionPane.showMessageDialog(null, ioe.getMessage());
+ JOptionPane.showMessageDialog(PainterFrame.this, ioe.getMessage());
}
}
});
@@ -267,4 +265,28 @@
JOptionPane.showMessageDialog(PainterFrame.this, message);
}
}
+
+ private void beginGenerating(Image targetImage) {
+ if (generator != null)
+ generator.stopGenerating();
+
+ ImageSizer sizer = new ImageSizer(targetImage);
+ Dimension size = new Dimension(sizer.getWidth(), sizer.getHeight());
+ generator = new ImageGenerator(settings, targetImage, size);
+
+ panel.setTarget(generator.getTargetImage());
+ size = generator.getImageSize();
+
+ Dimension wSize = new Dimension(size);
+ wSize.height += 2 * PainterFrame.this.getJMenuBar().getHeight();
+ if (Polycasso.DEBUG){
+ wSize.height *= 2;
+ }
+ setSize(wSize);
+ generator = new ImageGenerator(settings, targetImage, size);
+ generator.addImageGeneratedListener(PainterFrame.this);
+ generator.startGenerating();
+ completeImage.setEnabled(true);
+ saveAsMenu.setEnabled(true);
+ }
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-12-18 04:27:18 UTC (rev 196)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-12-18 04:33:04 UTC (rev 197)
@@ -35,6 +35,7 @@
Info("pc.info"),
File("pc.file"),
PaintImage("pc.paintimage"),
+ CopyImage("pc.copyimage"),
CompleteImage("pc.completeimage"),
SaveAs("pc.saveas"),
PNG("pc.png"),
@@ -56,6 +57,7 @@
MaximumPolygonPoints("pc.maxpolygonpoints"),
MaximumPointMovement("pc.maximumpointmovement"),
MaximumColorChange("pc.maximumcolorchange"),
+ EnterURL("pc.enterurl"),
BadSetting("pc.badsetting"),
SaveFailure("pc.savefailure"),
OverwriteWarning("pc.overwritewarning");
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-12-18 04:27:18 UTC (rev 196)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-12-18 04:33:04 UTC (rev 197)
@@ -21,7 +21,8 @@
pc.cancel = Cancel
pc.info = A cubism-style artwork generator that layers semi-transparent polygons \nvia a training feedback loop. Produces increasingly realistic work \nthrough hill climbing. For more info see\nhttp://polycasso.sourceforge.net
pc.file = File
-pc.paintimage = Start Generating Image
+pc.paintimage = Generate Random Image
+pc.copyimage = Generate Image from Source
pc.completeimage = Complete Image
pc.saveas = Save as
pc.png = PNG
@@ -43,6 +44,7 @@
pc.maxpolygonpoints = Maximum Points per Polygon
pc.maximumpointmovement = Maximum Point Movement
pc.maximumcolorchange = Maximum Color Change
+pc.enterurl = Enter URL (file or http) of image to use as a source
pc.badsetting = The setting specified was too small to properly function
pc.savefailure = Failed saving file: {0}
pc.overwritewarning = The file {0} already exists, do you wish to overwrite it?
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-12-31 07:46:28
|
Revision: 214
http://polycasso.svn.sourceforge.net/polycasso/?rev=214&view=rev
Author: dbrosius
Date: 2009-12-31 07:46:18 +0000 (Thu, 31 Dec 2009)
Log Message:
-----------
save settings to disk
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-12-31 07:33:18 UTC (rev 213)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2009-12-31 07:46:18 UTC (rev 214)
@@ -26,8 +26,14 @@
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.text.MessageFormat;
import javax.swing.ImageIcon;
@@ -37,6 +43,8 @@
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
+import org.apache.commons.io.IOUtils;
+
/**
* the main window for showing the image as it is being improved on.
*/
@@ -66,7 +74,7 @@
initMenus();
initListeners();
pack();
- settings = new Settings();
+ settings = loadSettings();
generator = null;
}
@@ -131,6 +139,7 @@
@Override
public void windowClosing(WindowEvent we) {
dispose();
+ saveSettings(settings);
System.exit(0);
}
});
@@ -199,6 +208,7 @@
if (generator != null)
generator.stopGenerating();
dispose();
+ saveSettings(settings);
System.exit(0);
}
});
@@ -289,4 +299,35 @@
completeImage.setEnabled(true);
saveAsMenu.setEnabled(true);
}
+
+ private Settings loadSettings() {
+ ObjectInputStream ois = null;
+ try {
+ File polyDir = getSettingsDirectory();
+ ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(new File(polyDir, "settings.ser"))));
+ return (Settings)ois.readObject();
+ } catch (Exception e) {
+ return new Settings();
+ } finally {
+ IOUtils.closeQuietly(ois);
+ }
+ }
+
+ private void saveSettings(Settings settings) {
+ ObjectOutputStream oos = null;
+ try {
+ File polyDir = getSettingsDirectory();
+ oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(new File(polyDir, "settings.ser"))));
+ oos.writeObject(settings);
+ } catch (Exception e) {
+ } finally {
+ IOUtils.closeQuietly(oos);
+ }
+ }
+
+ private File getSettingsDirectory() {
+ File polyDir = new File(System.getProperty("user.home"), ".polycasso");
+ polyDir.mkdirs();
+ return polyDir;
+ }
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2009-12-31 07:33:18 UTC (rev 213)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2009-12-31 07:46:18 UTC (rev 214)
@@ -19,13 +19,16 @@
package com.mebigfatguy.polycasso;
import java.awt.Dimension;
+import java.io.Serializable;
/**
* a simple java bean holding settings that are used to control how
* Polycasso runs
*/
-public class Settings implements Cloneable {
+public class Settings implements Cloneable, Serializable {
+ private static final long serialVersionUID = -8827208887550245450L;
+
private Dimension maxImageSize;
private int numCompetingImages;
private int maxPolygons;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-12-31 07:54:20
|
Revision: 215
http://polycasso.svn.sourceforge.net/polycasso/?rev=215&view=rev
Author: dbrosius
Date: 2009-12-31 07:54:11 +0000 (Thu, 31 Dec 2009)
Log Message:
-----------
add a reset settings button
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
trunk/polycasso/src/com/mebigfatguy/polycasso/resource_de.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-12-31 07:46:18 UTC (rev 214)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2009-12-31 07:54:11 UTC (rev 215)
@@ -30,6 +30,7 @@
*/
enum Key {
Title("pc.title"),
+ Reset("pc.reset"),
OK("pc.ok"),
Cancel("pc.cancel"),
Info("pc.info"),
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2009-12-31 07:46:18 UTC (rev 214)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2009-12-31 07:54:11 UTC (rev 215)
@@ -49,6 +49,7 @@
private static final long serialVersionUID = 5044661806014080056L;
Settings dlgSettings;
+ private JButton resetButton;
private JButton okButton;
private JButton cancelButton;
private JTextField widthField;
@@ -124,7 +125,6 @@
widthField = new JTextField(4);
widthField.setDocument(new IntegerDocument());
widthLabel.setLabelFor(widthField);
- widthField.setText(String.valueOf(dlgSettings.getMaxImageSize().width));
optPanel.add(widthField, cc.xy(3, 3));
widthField.addFocusListener(focuser);
@@ -133,7 +133,6 @@
heightField = new JTextField(4);
heightField.setDocument(new IntegerDocument());
heightLabel.setLabelFor(heightField);
- heightField.setText(String.valueOf(dlgSettings.getMaxImageSize().height));
optPanel.add(heightField, cc.xy(7, 3));
heightField.addFocusListener(focuser);
@@ -142,7 +141,6 @@
maxPolygonField = new JTextField(4);
maxPolygonField.setDocument(new IntegerDocument());
maxPolyLabel.setLabelFor(maxPolygonField);
- maxPolygonField.setText(String.valueOf(dlgSettings.getMaxPolygons()));
optPanel.add(maxPolygonField, cc.xy(7, 5));
maxPolygonField.addFocusListener(focuser);
@@ -151,7 +149,6 @@
numCompetingImagesField = new JTextField(4);
numCompetingImagesField.setDocument(new IntegerDocument());
numCompetingImagesLabel.setLabelFor(numCompetingImagesField);
- numCompetingImagesField.setText(String.valueOf(dlgSettings.getNumCompetingImages()));
optPanel.add(numCompetingImagesField, cc.xy(7, 7));
numCompetingImagesField.addFocusListener(focuser);
@@ -160,7 +157,6 @@
maxPolygonPointsField = new JTextField(4);
maxPolygonPointsField.setDocument(new IntegerDocument());
maxPolyPointLabel.setLabelFor(maxPolygonPointsField);
- maxPolygonPointsField.setText(String.valueOf(dlgSettings.getMaxPoints()));
optPanel.add(maxPolygonPointsField, cc.xy(7, 9));
maxPolygonPointsField.addFocusListener(focuser);
@@ -169,7 +165,6 @@
maxPtMoveField = new JTextField(4);
maxPtMoveField.setDocument(new IntegerDocument());
maxPtMoveLabel.setLabelFor(maxPtMoveField);
- maxPtMoveField.setText(String.valueOf(dlgSettings.getMaxPtMovement()));
optPanel.add(maxPtMoveField, cc.xy(7, 11));
maxPtMoveField.addFocusListener(focuser);
@@ -178,13 +173,25 @@
maxColorChangeField = new JTextField(4);
maxColorChangeField.setDocument(new IntegerDocument());
maxColorChangeLabel.setLabelFor(maxColorChangeField);
- maxColorChangeField.setText(String.valueOf(dlgSettings.getMaxColorChange()));
optPanel.add(maxColorChangeField, cc.xy(7, 13));
maxColorChangeField.addFocusListener(focuser);
+ populateValues();
+
return optPanel;
}
+ private void populateValues() {
+ widthField.setText(String.valueOf(dlgSettings.getMaxImageSize().width));
+ heightField.setText(String.valueOf(dlgSettings.getMaxImageSize().height));
+ maxPolygonField.setText(String.valueOf(dlgSettings.getMaxPolygons()));
+ numCompetingImagesField.setText(String.valueOf(dlgSettings.getNumCompetingImages()));
+ maxPolygonPointsField.setText(String.valueOf(dlgSettings.getMaxPoints()));
+ maxPtMoveField.setText(String.valueOf(dlgSettings.getMaxPtMovement()));
+ maxColorChangeField.setText(String.valueOf(dlgSettings.getMaxColorChange()));
+
+ }
+
/**
* creates the control panel
*
@@ -194,11 +201,15 @@
JPanel ctrlPanel = new JPanel();
ctrlPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
ctrlPanel.setLayout(new BoxLayout(ctrlPanel, BoxLayout.X_AXIS));
- ctrlPanel.add(Box.createHorizontalGlue());
+ resetButton = new JButton(PolycassoBundle.getString(PolycassoBundle.Key.Reset));
okButton = new JButton(PolycassoBundle.getString(PolycassoBundle.Key.OK));
cancelButton = new JButton(PolycassoBundle.getString(PolycassoBundle.Key.Cancel));
+ ctrlPanel.add(Box.createHorizontalStrut(10));
+ ctrlPanel.add(resetButton);
+ ctrlPanel.add(Box.createHorizontalGlue());
+ ctrlPanel.add(Box.createHorizontalStrut(10));
ctrlPanel.add(okButton);
ctrlPanel.add(Box.createHorizontalStrut(10));
ctrlPanel.add(cancelButton);
@@ -210,6 +221,14 @@
* sets up all the control listeners for the dialog
*/
private void initListeners() {
+ resetButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ dlgSettings = new Settings();
+ populateValues();
+ }
+ });
+
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-12-31 07:46:18 UTC (rev 214)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2009-12-31 07:54:11 UTC (rev 215)
@@ -17,6 +17,7 @@
# * under the License.
# */
pc.title = Polycasso
+pc.reset = Reset
pc.ok = OK
pc.cancel = Cancel
pc.info = A cubism-style artwork generator that layers semi-transparent polygons \nvia a training feedback loop. Produces increasingly realistic work \nthrough hill climbing. For more info see\nhttp://polycasso.sourceforge.net
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource_de.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource_de.properties 2009-12-31 07:46:18 UTC (rev 214)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource_de.properties 2009-12-31 07:54:11 UTC (rev 215)
@@ -17,6 +17,7 @@
# * under the License.
# */
pc.title = Polycasso
+pc.reset = Einrichten
pc.ok = OK
pc.cancel = Abbrechen
pc.info = Ein Kubismus-Stil Grafik-Generator, semi-transparente Schichten Polygone\nvia ein Ausbildungs-Feedback-Schleife. Erzeugt immer realistischer work\nthrough H\xFCgel klettern. F\xFCr weitere Informationen siehe\nhttp://polycasso.sourceforge.net
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-01 04:19:02
|
Revision: 218
http://polycasso.svn.sourceforge.net/polycasso/?rev=218&view=rev
Author: dbrosius
Date: 2010-01-01 04:18:52 +0000 (Fri, 01 Jan 2010)
Log Message:
-----------
split the data out from the code to draw it
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java
trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.template
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java 2010-01-01 01:19:31 UTC (rev 217)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java 2010-01-01 04:18:52 UTC (rev 218)
@@ -69,52 +69,18 @@
templateStream = getClass().getResourceAsStream("/com/mebigfatguy/polycasso/JavaSaver.template");
String template = IOUtils.toString(templateStream);
- StringWriter insert = new StringWriter();
- PrintWriter polyWriter = new PrintWriter(insert);
- for (PolygonData pd : data) {
- polyWriter.print(TABS);
- polyWriter.println("poly.reset();");
- Polygon poly = pd.getPolygon();
-
- for (int p = 0; p < poly.npoints; p++) {
- polyWriter.print(TABS);
- polyWriter.print("poly.addPoint(");
- polyWriter.print(poly.xpoints[p]);
- polyWriter.print(", ");
- polyWriter.print(poly.ypoints[p]);
- polyWriter.println(");");
- }
- Color c = pd.getColor();
- polyWriter.print(TABS);
- polyWriter.print("color = new Color(");
- polyWriter.print(c.getRed());
- polyWriter.print(", ");
- polyWriter.print(c.getGreen());
- polyWriter.print(", ");
- polyWriter.print(c.getBlue());
- polyWriter.println(");");
-
- polyWriter.print(TABS);
- polyWriter.println("g2d.setColor(color);");
-
- polyWriter.print(TABS);
- polyWriter.print("composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, ");
- polyWriter.print(pd.getAlpha());
- polyWriter.println("f);");
-
- polyWriter.print(TABS);
- polyWriter.println("g2d.setComposite(composite);");
-
- polyWriter.print(TABS);
- polyWriter.println("g2d.fillPolygon(poly);");
- }
- polyWriter.flush();
+ String polygonData = getPolygonData(data);
+ String colorData = getColorData(data);
+ String transparencyData = getTransparencyData(data);
+
/* All the curly braces confuses MessageFormat, so just do it manually */
template = template.replaceAll("\\{0\\}", className);
template = template.replaceAll("\\{1\\}", String.valueOf(imageSize.width));
template = template.replaceAll("\\{2\\}", String.valueOf(imageSize.height));
- template = template.replaceAll("\\{3\\}", insert.toString());
+ template = template.replaceAll("\\{3\\}", polygonData);
+ template = template.replaceAll("\\{4\\}", colorData);
+ template = template.replaceAll("\\{5\\}", transparencyData);
pw.println(template);
@@ -123,8 +89,105 @@
} finally {
IOUtils.closeQuietly(templateStream);
IOUtils.closeQuietly(pw);
+ }
+ }
+
+ private String getPolygonData(PolygonData[] data) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+
+ String outerComma = "";
+ String innerComma;
+ for (int i = 0; i < data.length; i++) {
+
+ PolygonData pd = data[i];
+
+ pw.println(outerComma);
+ pw.print(TABS);
+ pw.println("{");
+
+ /* Xs */
+ pw.print(TABS);
+ pw.print("\t{");
+
+ innerComma = "";
+ Polygon poly = pd.getPolygon();
+ for (int j = 0; j < poly.npoints; j++) {
+ pw.print(innerComma);
+ pw.print(poly.xpoints[j]);
+ innerComma = ",";
+ }
+
+ pw.println("},");
+
+ /* Ys */
+ pw.print(TABS);
+ pw.print("\t{");
+
+ innerComma = "";
+ poly = pd.getPolygon();
+ for (int j = 0; j < poly.npoints; j++) {
+ pw.print(innerComma);
+ pw.print(poly.ypoints[j]);
+ innerComma = ",";
+ }
+
+ pw.println("}");
+
+ pw.print(TABS);
+ pw.print("}");
+ outerComma = ",";
}
+ pw.flush();
+ return sw.toString();
}
+
+ private String getColorData(PolygonData[] data) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+
+ String comma = "";
+ for (int i = 0; i < data.length; i++) {
+
+ PolygonData pd = data[i];
+
+ pw.println(comma);
+ pw.print(TABS);
+ pw.print("{");
+
+ Color color = pd.getColor();
+ pw.print(color.getRed());
+ pw.print(",");
+ pw.print(color.getGreen());
+ pw.print(",");
+ pw.print(color.getBlue());
+ pw.print("}");
+ comma = ",";
+ }
+
+ pw.flush();
+ return sw.toString();
+ }
+
+ private String getTransparencyData(PolygonData[] data) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ pw.println();
+ pw.print(TABS);
+ String comma = "";
+ for (int i = 0; i < data.length; i++) {
+
+ PolygonData pd = data[i];
+
+ pw.print(comma);
+ pw.print(pd.getAlpha());
+ pw.print("f");
+ comma = ",";
+ }
+
+ pw.flush();
+ return sw.toString();
+ }
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.template
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.template 2010-01-01 01:19:31 UTC (rev 217)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.template 2010-01-01 04:18:52 UTC (rev 218)
@@ -34,19 +34,38 @@
public static void main(String[] args) {
JFrame frame = new JFrame() {
- {
+ {
+ final int[][][] polygonData = new int[][][]
+ {{3}
+ };
+
+ final int[][] colorData = new int[][]
+ {{4}
+ };
+
+ final float [] transparencyData = new float[]
+ {{5}
+ };
+
Container cp = getContentPane();
cp.add(new JPanel() {
+ private static final long serialVersionUID = 1L;
+
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
- g2d.fillRect(0, 0, {1}, {2});
- Polygon poly = new Polygon();
- AlphaComposite composite;
- Color color;
-{3}
+ g2d.fillRect(0, 0, {1}, {2});
+
+ for (int i = 0; i < polygonData.length; i++) {
+ Polygon polygon = new Polygon(polygonData[i][0], polygonData[i][1], polygonData[i][0].length);
+ Color color = new Color(colorData[i][0], colorData[i][1], colorData[i][2]);
+ g2d.setColor(color);
+ AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparencyData[i]);
+ g2d.setComposite(composite);
+ g2d.fillPolygon(polygon);
+ }
}
});
pack();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-01 04:20:30
|
Revision: 219
http://polycasso.svn.sourceforge.net/polycasso/?rev=219&view=rev
Author: dbrosius
Date: 2010-01-01 04:20:23 +0000 (Fri, 01 Jan 2010)
Log Message:
-----------
split the overwrite warning into two lines
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
trunk/polycasso/src/com/mebigfatguy/polycasso/resource_de.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2010-01-01 04:18:52 UTC (rev 218)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2010-01-01 04:20:23 UTC (rev 219)
@@ -48,4 +48,4 @@
pc.enterurl = Enter URL (file or http) of image to use as a source
pc.badsetting = The setting specified was too small to properly function
pc.savefailure = Failed saving file: {0}
-pc.overwritewarning = The file {0} already exists, do you wish to overwrite it?
+pc.overwritewarning = The file {0} already exists,\ndo you wish to overwrite it?
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource_de.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource_de.properties 2010-01-01 04:18:52 UTC (rev 218)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource_de.properties 2010-01-01 04:20:23 UTC (rev 219)
@@ -48,4 +48,4 @@
pc.enterurl = Geben Sie die URL (Datei-oder http) des Bildes als Quelle verwenden
pc.badsetting = Die Einstellung angegeben wurde zu klein, um die einwandfreie Funktion
pc.savefailure = Fehler beim Speichern der Datei: {0}
-pc.overwritewarning = Die Datei (0) existiert bereits, m\xF6chten Sie sie \xFCberschreiben?
+pc.overwritewarning = Die Datei (0) existiert bereits,\nm\xF6chten Sie sie \xFCberschreiben?
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-01 04:48:03
|
Revision: 220
http://polycasso.svn.sourceforge.net/polycasso/?rev=220&view=rev
Author: dbrosius
Date: 2010-01-01 04:47:53 +0000 (Fri, 01 Jan 2010)
Log Message:
-----------
draw the image polygon by polygon with a delay
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java
trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.template
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java 2010-01-01 04:20:23 UTC (rev 219)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.java 2010-01-01 04:47:53 UTC (rev 220)
@@ -37,7 +37,7 @@
public class JavaSaver implements Saver {
private static final String EXTENSION = ".java";
- private static final String TABS = "\t\t\t\t\t\t";
+ private static final String TABS = "\t\t\t\t\t";
/**
* saves the polygon data as a java file that opens a JFrame and draws the polygons
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.template
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.template 2010-01-01 04:20:23 UTC (rev 219)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/JavaSaver.template 2010-01-01 04:47:53 UTC (rev 220)
@@ -22,31 +22,49 @@
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
+import javax.swing.Timer;
/**
* generates an image by laying semi-transparent polygons on top of each other.
* Class generated by Polycasso (http://polycasso.sourceforge.net)
*/
public class {0} {
-
+ private static final int DEFAULT_DELAY = 500;
+
public static void main(String[] args) {
+ int inputDelay;
+ try {
+ inputDelay = Integer.parseInt(args[0]);
+ } catch (Exception e) {
+ inputDelay = DEFAULT_DELAY;
+ }
+
+ final int delay = inputDelay;
+
JFrame frame = new JFrame() {
+ private static final long serialVersionUID = 1L;
+
+ private Timer timer;
+ private int displayCount = 0;
+
+ private int[][][] polygonData = new int[][][]
+ {{3}
+ };
+
+ private int[][] colorData = new int[][]
+ {{4}
+ };
+
+ private float [] transparencyData = new float[]
+ {{5}
+ };
+
{
- final int[][][] polygonData = new int[][][]
- {{3}
- };
-
- final int[][] colorData = new int[][]
- {{4}
- };
-
- final float [] transparencyData = new float[]
- {{5}
- };
-
Container cp = getContentPane();
cp.add(new JPanel() {
private static final long serialVersionUID = 1L;
@@ -58,7 +76,12 @@
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, {1}, {2});
- for (int i = 0; i < polygonData.length; i++) {
+ int limit;
+ synchronized(timer) {
+ limit = displayCount;
+ }
+
+ for (int i = 0; i < limit; i++) {
Polygon polygon = new Polygon(polygonData[i][0], polygonData[i][1], polygonData[i][0].length);
Color color = new Color(colorData[i][0], colorData[i][1], colorData[i][2]);
g2d.setColor(color);
@@ -69,6 +92,23 @@
}
});
pack();
+
+ timer = new Timer(delay, new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ synchronized(timer) {
+ if (displayCount < polygonData.length) {
+ displayCount++;
+ } else {
+ timer.stop();
+ }
+ repaint();
+ }
+
+ }
+ });
+ timer.setRepeats(true);
+ timer.start();
}
};
frame.setSize({1}, {2} + 20);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-06-09 06:11:19
|
Revision: 224
http://polycasso.svn.sourceforge.net/polycasso/?rev=224&view=rev
Author: dbrosius
Date: 2010-06-09 06:11:13 +0000 (Wed, 09 Jun 2010)
Log Message:
-----------
warnings
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/FileType.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PainterPanel.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/FileType.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/FileType.java 2010-06-07 02:57:53 UTC (rev 223)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/FileType.java 2010-06-09 06:11:13 UTC (rev 224)
@@ -27,6 +27,7 @@
* A portable network graphics file
*/
PNG(".png", PolycassoBundle.Key.PNGDescription) {
+ @Override
public Saver getSaver() {
return new PNGSaver();
}
@@ -35,6 +36,7 @@
* a scalable vector graphics file
*/
SVG(".svg", PolycassoBundle.Key.SVGDescription) {
+ @Override
public Saver getSaver() {
return new SVGSaver();
}
@@ -43,6 +45,7 @@
* a java file
*/
Java(".java", PolycassoBundle.Key.JAVADescription) {
+ @Override
public Saver getSaver() {
return new JavaSaver();
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2010-06-07 02:57:53 UTC (rev 223)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterFrame.java 2010-06-09 06:11:13 UTC (rev 224)
@@ -313,12 +313,12 @@
}
}
- private void saveSettings(Settings settings) {
+ private void saveSettings(Settings s) {
ObjectOutputStream oos = null;
try {
File polyDir = getSettingsDirectory();
oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(new File(polyDir, "settings.ser"))));
- oos.writeObject(settings);
+ oos.writeObject(s);
} catch (Exception e) {
} finally {
IOUtils.closeQuietly(oos);
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PainterPanel.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PainterPanel.java 2010-06-07 02:57:53 UTC (rev 223)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PainterPanel.java 2010-06-09 06:11:13 UTC (rev 224)
@@ -31,7 +31,7 @@
public class PainterPanel extends JPanel {
private static final long serialVersionUID = -4005448126783525299L;
- private Object lock = new Object();
+ private final Object lock = new Object();
private Image targetImage;
private Image bestImage;
@@ -66,6 +66,7 @@
*
* @param g the graphics object of the panel
*/
+ @Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
synchronized(lock) {
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2010-06-07 02:57:53 UTC (rev 223)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2010-06-09 06:11:13 UTC (rev 224)
@@ -82,7 +82,7 @@
public String id() {
return id;
}
- };
+ }
private static ResourceBundle bundle = ResourceBundle.getBundle("com/mebigfatguy/polycasso/resource");
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java 2010-06-07 02:57:53 UTC (rev 223)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolygonData.java 2010-06-09 06:11:13 UTC (rev 224)
@@ -152,6 +152,7 @@
*
* @return a copy of the polygon data
*/
+ @Override
public Object clone() {
try {
PolygonData clone = (PolygonData)super.clone();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-09-29 04:05:26
|
Revision: 225
http://polycasso.svn.sourceforge.net/polycasso/?rev=225&view=rev
Author: dbrosius
Date: 2010-09-29 04:05:19 +0000 (Wed, 29 Sep 2010)
Log Message:
-----------
start adding genetic settings
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Added Paths:
-----------
trunk/polycasso/src/com/mebigfatguy/polycasso/DoubleDocument.java
Added: trunk/polycasso/src/com/mebigfatguy/polycasso/DoubleDocument.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/DoubleDocument.java (rev 0)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/DoubleDocument.java 2010-09-29 04:05:19 UTC (rev 225)
@@ -0,0 +1,59 @@
+/*
+ * polycasso - Cubism Artwork generator
+ * Copyright 2009-2010 MeBigFatGuy.com
+ * Copyright 2009-2010 Dave Brosius
+ * Inspired by work by Roger Alsing
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package com.mebigfatguy.polycasso;
+
+import java.awt.Toolkit;
+
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.PlainDocument;
+
+/**
+ * a Document model class for text components to only allow
+ * integer values
+ */
+public class DoubleDocument extends PlainDocument {
+
+ private static final long serialVersionUID = -6755728406523769124L;
+
+ /**
+ * intercepts string insertions to make sure that the values to be put into
+ * a text component is only a positive double value
+ *
+ * @param pos where the text is being inserted
+ * @param insertStr the new text that was typed
+ * @param atts the attributes for the text (unused)
+ */
+ @Override
+ public void insertString(int pos, String insertStr, AttributeSet atts) throws BadLocationException {
+ StringBuilder text = new StringBuilder(getText(0, getLength()));
+ try {
+ text.insert(pos, insertStr);
+ double value = Double.parseDouble(text.toString());
+ if (value < 0) {
+ Toolkit.getDefaultToolkit().beep();
+ } else {
+ super.insertString(pos, insertStr, atts);
+ }
+ } catch (Exception e) {
+ Toolkit.getDefaultToolkit().beep();
+ }
+ }
+
+}
Property changes on: trunk/polycasso/src/com/mebigfatguy/polycasso/DoubleDocument.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java 2010-06-09 06:11:13 UTC (rev 224)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java 2010-09-29 04:05:19 UTC (rev 225)
@@ -26,7 +26,7 @@
/**
* a Document model class for text components to only allow
- * integer values
+ * positive integer values
*/
public class IntegerDocument extends PlainDocument {
@@ -45,8 +45,12 @@
StringBuilder text = new StringBuilder(getText(0, getLength()));
try {
text.insert(pos, insertStr);
- Integer.parseInt(text.toString());
- super.insertString(pos, insertStr, atts);
+ int value = Integer.parseInt(text.toString());
+ if (value < 0) {
+ Toolkit.getDefaultToolkit().beep();
+ } else {
+ super.insertString(pos, insertStr, atts);
+ }
} catch (Exception e) {
Toolkit.getDefaultToolkit().beep();
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2010-06-09 06:11:13 UTC (rev 224)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2010-09-29 04:05:19 UTC (rev 225)
@@ -50,6 +50,13 @@
Settings("pc.settings"),
About("pc.about"),
AboutPolycasso("pc.aboutpolycasso"),
+ GeneticsOptions("pc.geneticsoptions"),
+ GenerationSize("pc.generationsize"),
+ EliteSize("pc.elitesize"),
+ UseAnnealing("pc.useannealing"),
+ StartTemperature("pc.starttemperature"),
+ CoolingRate("pc.coolingrate"),
+ ImageOptions("pc.imageoptions"),
MaxImageSize("pc.maximagesize"),
Width("pc.width"),
Height("pc.height"),
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2010-06-09 06:11:13 UTC (rev 224)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2010-09-29 04:05:19 UTC (rev 225)
@@ -26,9 +26,14 @@
* Polycasso runs
*/
public class Settings implements Cloneable, Serializable {
-
- private static final long serialVersionUID = -8827208887550245450L;
+ private static final long serialVersionUID = 8021543124907733235L;
+
+ private int generationSize;
+ private int eliteSize;
+ private boolean useAnnealing;
+ private double startTemperature;
+ private double coolingRate;
private Dimension maxImageSize;
private int numCompetingImages;
private int maxPolygons;
@@ -40,6 +45,11 @@
* constructs a settings object with rational defaults
*/
public Settings() {
+ generationSize = 50;
+ eliteSize = 10;
+ useAnnealing = true;
+ startTemperature = 20;
+ coolingRate = 0.1;
maxImageSize = new Dimension(800, 600);
maxPolygons = 100;
numCompetingImages = 20;
@@ -62,7 +72,58 @@
}
}
+
+ public void setGenerationSize(int generationSz) {
+ generationSize = generationSz;
+ }
+
+ public int getGenerationSize() {
+ return generationSize;
+ }
+
+ public void setEliteSize(int eliteSz) {
+ eliteSize = eliteSz;
+ }
+
+ public int getEliteSize() {
+ return eliteSize;
+ }
+
/**
+ * sets whether to use simulated annealing
+ *
+ * @param annealing whether to use annealing
+ */
+ public void setUseAnnealing(boolean annealing) {
+ useAnnealing = annealing;
+ }
+
+ /**
+ * gets whether to use simulating annealing
+ *
+ * @return whether to use simulating annealing
+ */
+ public boolean isUseAnnealing() {
+ return useAnnealing;
+ }
+
+ public void setStartTemperature(double startTemp) {
+ startTemperature = startTemp;
+ }
+
+ public double getStartTemperature() {
+ return startTemperature;
+ }
+
+ public void setCoolingRate(double coolRate) {
+ coolingRate = coolRate;
+ }
+
+ public double getCoolingRate() {
+ return coolingRate;
+ }
+
+ /**
* sets the maximum image size
*
* @param imageSize the image size
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2010-06-09 06:11:13 UTC (rev 224)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2010-09-29 04:05:19 UTC (rev 225)
@@ -30,6 +30,7 @@
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
+import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
@@ -52,6 +53,11 @@
private JButton resetButton;
private JButton okButton;
private JButton cancelButton;
+ private JTextField generationSizeField;
+ private JTextField eliteSizeField;
+ private JCheckBox useAnnealingButton;
+ private JTextField startTemperatureField;
+ private JTextField coolingRateField;
private JTextField widthField;
private JTextField heightField;
private JTextField maxPolygonField;
@@ -59,8 +65,10 @@
private JTextField maxPolygonPointsField;
private JTextField maxPtMoveField;
private JTextField maxColorChangeField;
+ private SelectAllFocuser focuser;
private boolean isOK;
+
/**
* constructs the dialog using the passed in settings to set default values
*
@@ -99,7 +107,16 @@
Container cp = getContentPane();
cp.setLayout(new BorderLayout(4, 4));
- cp.add(createOptionsPanel(), BorderLayout.CENTER);
+ focuser = new SelectAllFocuser();
+
+ JPanel centerPanel = new JPanel();
+ centerPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
+ centerPanel.add(createGeneticsPanel());
+ centerPanel.add(Box.createVerticalStrut(10));
+ centerPanel.add(createOptionsPanel());
+
+ cp.add(centerPanel, BorderLayout.CENTER);
cp.add(createControlPanel(), BorderLayout.SOUTH);
pack();
}
@@ -110,10 +127,9 @@
* @return the options panel
*/
private JPanel createOptionsPanel() {
-
- SelectAllFocuser focuser = new SelectAllFocuser();
JPanel optPanel = new JPanel();
- optPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ optPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(PolycassoBundle.getString(PolycassoBundle.Key.ImageOptions)),
+ BorderFactory.createEmptyBorder(10, 10, 10, 10)));
optPanel.setLayout(new FormLayout("pref, 3dlu, 100px, 5dlu, pref, 3dlu, 100px", "pref, 1dlu, pref, 15dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref"));
CellConstraints cc = new CellConstraints();
@@ -181,7 +197,66 @@
return optPanel;
}
+ private JPanel createGeneticsPanel() {
+
+ JPanel geneticsPanel = new JPanel();
+ geneticsPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(PolycassoBundle.getString(PolycassoBundle.Key.GeneticsOptions)),
+ BorderFactory.createEmptyBorder(10, 10, 10, 10)));
+
+ geneticsPanel.setLayout(new FormLayout("6dlu, pref, 3dlu, 100px, 3dlu", "pref, 1dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref"));
+ CellConstraints cc = new CellConstraints();
+
+ JLabel generationSizeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.GenerationSize));
+ geneticsPanel.add(generationSizeLabel, cc.xyw(1, 1, 2));
+
+ generationSizeField = new JTextField(4);
+ generationSizeField.setDocument(new IntegerDocument());
+ generationSizeLabel.setLabelFor(generationSizeField);
+ geneticsPanel.add(generationSizeField, cc.xy(4, 1));
+ generationSizeField.addFocusListener(focuser);
+
+ JLabel eliteSizeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.EliteSize));
+ geneticsPanel.add(eliteSizeLabel, cc.xyw(1, 3, 2));
+
+ eliteSizeField = new JTextField(4);
+ eliteSizeField.setDocument(new IntegerDocument());
+ eliteSizeLabel.setLabelFor(eliteSizeField);
+ geneticsPanel.add(eliteSizeField, cc.xy(4, 3));
+ eliteSizeField.addFocusListener(focuser);
+
+ useAnnealingButton = new JCheckBox(PolycassoBundle.getString(PolycassoBundle.Key.UseAnnealing));
+ geneticsPanel.add(useAnnealingButton, cc.xyw(1, 5, 5));
+
+ JLabel startTemperatureLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.StartTemperature));
+ geneticsPanel.add(startTemperatureLabel, cc.xy(2, 7));
+
+ startTemperatureField = new JTextField(4);
+ startTemperatureField.setDocument(new DoubleDocument());
+ startTemperatureLabel.setLabelFor(startTemperatureField);
+ geneticsPanel.add(startTemperatureField, cc.xy(4, 7));
+ startTemperatureField.addFocusListener(focuser);
+
+ JLabel coolingRateLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.CoolingRate));
+ geneticsPanel.add(coolingRateLabel, cc.xy(2, 9));
+
+ coolingRateField = new JTextField(4);
+ coolingRateField.setDocument(new DoubleDocument());
+ coolingRateLabel.setLabelFor(coolingRateField);
+ geneticsPanel.add(coolingRateField, cc.xy(4, 9));
+ coolingRateField.addFocusListener(focuser);
+
+ return geneticsPanel;
+ }
+
private void populateValues() {
+ generationSizeField.setText(String.valueOf(dlgSettings.getGenerationSize()));
+ eliteSizeField.setText(String.valueOf(dlgSettings.getEliteSize()));
+ boolean enable = dlgSettings.isUseAnnealing();
+ useAnnealingButton.setSelected(enable);
+ startTemperatureField.setEnabled(enable);
+ startTemperatureField.setText(String.valueOf(dlgSettings.getStartTemperature()));
+ coolingRateField.setEnabled(enable);
+ coolingRateField.setText(String.valueOf(dlgSettings.getCoolingRate()));
widthField.setText(String.valueOf(dlgSettings.getMaxImageSize().width));
heightField.setText(String.valueOf(dlgSettings.getMaxImageSize().height));
maxPolygonField.setText(String.valueOf(dlgSettings.getMaxPolygons()));
@@ -189,7 +264,6 @@
maxPolygonPointsField.setText(String.valueOf(dlgSettings.getMaxPoints()));
maxPtMoveField.setText(String.valueOf(dlgSettings.getMaxPtMovement()));
maxColorChangeField.setText(String.valueOf(dlgSettings.getMaxColorChange()));
-
}
/**
@@ -221,6 +295,16 @@
* sets up all the control listeners for the dialog
*/
private void initListeners() {
+
+ useAnnealingButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ boolean enable = useAnnealingButton.isSelected();
+ startTemperatureField.setEnabled(enable);
+ coolingRateField.setEnabled(enable);
+ }
+ });
+
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
@@ -286,7 +370,19 @@
* @return whether the settings are valid
*/
private boolean validateSettings() {
- if (dlgSettings.getMaxImageSize().width < 10) {
+ if (dlgSettings.getGenerationSize() < 10) {
+ generationSizeField.setText("10");
+ generationSizeField.requestFocus();
+ } else if (dlgSettings.getEliteSize() < 2) {
+ eliteSizeField.setText("2");
+ eliteSizeField.requestFocus();
+ } else if (dlgSettings.getStartTemperature() > 255) {
+ startTemperatureField.setText("255.0");
+ startTemperatureField.requestFocus();
+ } else if (dlgSettings.getCoolingRate() > 40) {
+ coolingRateField.setText("40.0");
+ coolingRateField.requestFocus();
+ } else if (dlgSettings.getMaxImageSize().width < 10) {
widthField.setText("10");
widthField.requestFocus();
} else if (dlgSettings.getMaxImageSize().height < 10) {
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2010-06-09 06:11:13 UTC (rev 224)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2010-09-29 04:05:19 UTC (rev 225)
@@ -37,6 +37,13 @@
pc.settings = Settings
pc.about = About
pc.aboutpolycasso = About Polycasso
+pc.geneticsoptions = Genetics Options
+pc.generationsize = Generation Size
+pc.elitesize = Elite Size
+pc.useannealing = Use Annealing
+pc.starttemperature = Annealing Starting Temperature
+pc.coolingrate = Annealing cooling rate
+pc.imageoptions = Image Options
pc.maximagesize = Maximum Image Size
pc.width = Width
pc.height = Height
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2011-07-25 05:45:21
|
Revision: 234
http://polycasso.svn.sourceforge.net/polycasso/?rev=234&view=rev
Author: dbrosius
Date: 2011-07-25 05:45:14 +0000 (Mon, 25 Jul 2011)
Log Message:
-----------
add tooltips
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2011-07-25 05:32:52 UTC (rev 233)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2011-07-25 05:45:14 UTC (rev 234)
@@ -52,10 +52,15 @@
AboutPolycasso("pc.aboutpolycasso"),
GeneticsOptions("pc.geneticsoptions"),
GenerationSize("pc.generationsize"),
+ GenerationSizeToolTip("pc.generationsize.tt"),
EliteSize("pc.elitesize"),
+ EliteSizeToolTip("pc.elitesize.tt"),
UseAnnealing("pc.useannealing"),
+ UseAnnealingToolTip("pc.useannealing.tt"),
StartTemperature("pc.starttemperature"),
+ StartTemperatureToolTip("pc.starttemperature.tt"),
CoolingRate("pc.coolingrate"),
+ CoolingRateToolTip("pc.coolingrate.tt"),
ImageOptions("pc.imageoptions"),
MaxImageSize("pc.maximagesize"),
Width("pc.width"),
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2011-07-25 05:32:52 UTC (rev 233)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2011-07-25 05:45:14 UTC (rev 234)
@@ -201,6 +201,7 @@
geneticsPanel.add(generationSizeLabel, cc.xyw(1, 1, 2));
generationSizeField = new JTextField(4);
+ generationSizeField.setToolTipText(PolycassoBundle.getString(PolycassoBundle.Key.GenerationSizeToolTip));
generationSizeField.setDocument(new IntegerDocument());
generationSizeLabel.setLabelFor(generationSizeField);
geneticsPanel.add(generationSizeField, cc.xy(4, 1));
@@ -210,18 +211,21 @@
geneticsPanel.add(eliteSizeLabel, cc.xyw(1, 3, 2));
eliteSizeField = new JTextField(4);
+ eliteSizeField.setToolTipText(PolycassoBundle.getString(PolycassoBundle.Key.EliteSizeToolTip));
eliteSizeField.setDocument(new IntegerDocument());
eliteSizeLabel.setLabelFor(eliteSizeField);
geneticsPanel.add(eliteSizeField, cc.xy(4, 3));
eliteSizeField.addFocusListener(focuser);
useAnnealingButton = new JCheckBox(PolycassoBundle.getString(PolycassoBundle.Key.UseAnnealing));
+ useAnnealingButton.setToolTipText(PolycassoBundle.getString(PolycassoBundle.Key.UseAnnealingToolTip));
geneticsPanel.add(useAnnealingButton, cc.xyw(1, 5, 5));
JLabel startTemperatureLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.StartTemperature));
geneticsPanel.add(startTemperatureLabel, cc.xy(2, 7));
startTemperatureField = new JTextField(4);
+ startTemperatureField.setToolTipText(PolycassoBundle.getString(PolycassoBundle.Key.StartTemperatureToolTip));
startTemperatureField.setDocument(new DoubleDocument());
startTemperatureLabel.setLabelFor(startTemperatureField);
geneticsPanel.add(startTemperatureField, cc.xy(4, 7));
@@ -231,6 +235,7 @@
geneticsPanel.add(coolingRateLabel, cc.xy(2, 9));
coolingRateField = new JTextField(4);
+ coolingRateField.setToolTipText(PolycassoBundle.getString(PolycassoBundle.Key.CoolingRateToolTip));
coolingRateField.setDocument(new DoubleDocument());
coolingRateLabel.setLabelFor(coolingRateField);
geneticsPanel.add(coolingRateField, cc.xy(4, 9));
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2011-07-25 05:32:52 UTC (rev 233)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2011-07-25 05:45:14 UTC (rev 234)
@@ -39,10 +39,15 @@
pc.aboutpolycasso = About Polycasso
pc.geneticsoptions = Genetics Options
pc.generationsize = Generation Size
+pc.generationsize.tt = The number of images to generate in one generation
pc.elitesize = Elite Size
+pc.elitesize.tt = The number of images that are copied from one generation to another
pc.useannealing = Use Annealing
+pc.useannealing.tt = Accept images that are not as good as the elite images to encourage variations
pc.starttemperature = Annealing Starting Temperature
+pc.starttemperature.tt = The average pixel error (color difference) that an inferior image can have to be accepted
pc.coolingrate = Annealing cooling rate
+pc.coolingrate.tt = How the average error is decreased on each generation
pc.imageoptions = Image Options
pc.maximagesize = Maximum Image Size
pc.width = Width
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2011-07-25 07:08:10
|
Revision: 235
http://polycasso.svn.sourceforge.net/polycasso/?rev=235&view=rev
Author: dbrosius
Date: 2011-07-25 07:08:03 +0000 (Mon, 25 Jul 2011)
Log Message:
-----------
hook up annealing
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/GenerationHandler.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/GenerationHandler.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/GenerationHandler.java 2011-07-25 05:45:14 UTC (rev 234)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/GenerationHandler.java 2011-07-25 07:08:03 UTC (rev 235)
@@ -146,7 +146,7 @@
int r = random.nextInt(size);
- int idx = (r * r) / (size * size);
+ int idx = (int)(r * ((double) r / (double) size));
return generation.get(idx).data;
}
@@ -174,6 +174,25 @@
nextGeneration.add(generation.get(i));
}
+ if (settings.isUseAnnealing() && (annealingValue > 0.01)) {
+ int annealingReplacements = 0;
+ /* always keep the best, so start at 1 */
+ for (int i = 1; i < eliteSize; i++) {
+ int candidateIndex = random.nextInt(sz - eliteSize) + eliteSize;
+ Member candidate = generation.get(candidateIndex);
+ Member elite = generation.get(i);
+ double delta = candidate.score - elite.score;
+ if (delta < annealingValue) {
+ nextGeneration.set(i, candidate);
+ annealingReplacements++;
+ }
+ }
+
+ if (Polycasso.DEBUG) {
+ System.out.println("Generation " + generationNumber + " had " + annealingReplacements + " annealing replacements with annealing value: " + annealingValue);
+ }
+ }
+
generation = nextGeneration;
eliteCutOff = generation.get(eliteSize-1).score;
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java 2011-07-25 05:45:14 UTC (rev 234)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Polycasso.java 2011-07-25 07:08:03 UTC (rev 235)
@@ -28,7 +28,7 @@
/**
* enable some console debugging, and show the target image
*/
- public static final boolean DEBUG = false;
+ public static final boolean DEBUG = true;
/**
* the main entry point to the web start app
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2011-07-25 05:45:14 UTC (rev 234)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2011-07-25 07:08:03 UTC (rev 235)
@@ -47,7 +47,7 @@
generationSize = 40;
eliteSize = 10;
useAnnealing = true;
- startTemperature = 1;
+ startTemperature = 10;
coolingRate = 0.01;
maxImageSize = new Dimension(800, 600);
maxPolygons = 100;
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2011-07-25 05:45:14 UTC (rev 234)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2011-07-25 07:08:03 UTC (rev 235)
@@ -47,7 +47,7 @@
pc.starttemperature = Annealing Starting Temperature
pc.starttemperature.tt = The average pixel error (color difference) that an inferior image can have to be accepted
pc.coolingrate = Annealing cooling rate
-pc.coolingrate.tt = How the average error is decreased on each generation
+pc.coolingrate.tt = How the average pixel error is decreased by multiplication on each generation
pc.imageoptions = Image Options
pc.maximagesize = Maximum Image Size
pc.width = Width
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|