001: package test;
002:
003: import java.awt.Graphics;
004: import java.awt.image.BufferedImage;
005:
006: import javax.swing.JFrame;
007:
008: import org.jvnet.lafwidget.LafWidgetUtilities;
009: import org.jvnet.substance.SubstanceImageCreator;
010: import org.jvnet.substance.painter.noise.*;
011: import org.jvnet.substance.painter.noise.FabricFilter.FabricFilterLink;
012: import org.jvnet.substance.painter.noise.NoiseFilter.TrigKind;
013: import org.jvnet.substance.theme.*;
014: import org.jvnet.substance.utils.SubstanceCoreUtilities;
015:
016: public class NoiseFrame extends JFrame {
017:
018: public NoiseFrame() {
019: }
020:
021: @Override
022: public void paint(Graphics g) {
023: int width = this .getWidth();
024: int height = this .getHeight();
025:
026: // // double[][] noise = new
027: // // PerlinNoiseGenerator().getSparseNormalizedNoise(
028: // // width, height, 0);
029: // ColorScheme cs = new BrownColorScheme();
030: // Color c1 = SubstanceCoreUtilities.getInterpolatedColor(
031: // cs.getMidColor(), cs.getLightColor(), 0.9);
032: // Color c2 = cs.getLightColor();
033: // Color c3 = cs.getUltraLightColor();
034: //
035: // BufferedImage bi = new BufferedImage(width, height,
036: // BufferedImage.TYPE_INT_ARGB);
037: // Graphics2D g2d = (Graphics2D) bi.getGraphics();
038: //
039: // for (int i = 0; i < width; i++) {
040: // double ii = (double) (i - width / 2) / 10.0;
041: // for (int j = 0; j < height; j++) {
042: // double jj = (double) (j - height / 2) / 10.0;
043: // double zz2 = 1.0;// 100 - ii * ii - 4 * jj * jj;
044: // if (zz2 > 0.0) {
045: // double noise = 0.5 + 0.5 * PerlinNoiseGenerator.noise(ii,
046: // jj, Math.sqrt(zz2));
047: // // noise = 0.5 + 0.5 * Math.cos(i + 20*noise);
048: // // noise = 0.5 + 0.5*Math.sin(i + j + 20*noise);
049: // // noise = (0.5 + 0.5 * Math.sin(i + 20 * noise)
050: // // * Math.cos(-i + j + 20 * noise)); // fabric
051: // // noise = 0.5 + 0.5 * Math.cos(i / 10. + noise); // marble
052: // // noise = Math.sqrt(Math.abs(2*noise-1)); // maze
053: //
054: // double noise2 = 0.5 + 0.5 * PerlinNoiseGenerator.noise(
055: // i / 100.0, j / 100.0, zz2);
056: // // noise = 20 * noise - (int) (20 * noise); // wood
057: //
058: // // double bumps = PerlinNoiseGenerator.PerlinNoise_2D(ii,
059: // // jj / 10.0);
060: // // if (bumps < .5)
061: // // bumps = 0;
062: // // else
063: // // bumps = 1;
064: // // noise += (1-noise)*bumps*0.5;
065: //
066: // FabricFilter.FabricFilterLink fabricLink1 = FabricFilterLink
067: // .getXLink(1.0, 20.0, TrigKind.SINE);
068: // FabricFilter.FabricFilterLink fabricLink2 = FabricFilterLink
069: // .getYLink(1.0, 20.0, TrigKind.COSINE);
070: // NoiseFilter fabricFilter = new FabricFilter(fabricLink1,
071: // fabricLink2);
072: // NoiseFilter marbleFilter = MarbleFilter.getXFilter(0.1,
073: // TrigKind.COSINE);
074: // NoiseFilter mazeFilter = new MazeFilter();
075: // NoiseFilter woodFilter = new WoodFilter(30.0);
076: //
077: // CompoundNoiseFilter compoundFilter = new CompoundNoiseFilter(
078: // woodFilter);
079: // noise = compoundFilter.apply(i, j, zz2, noise2);
080: //
081: // if (noise < 0.5)
082: // g2d.setColor(SubstanceCoreUtilities
083: // .getInterpolatedColor(c2, c1, 2.0 * noise));
084: // else
085: // g2d.setColor(SubstanceCoreUtilities
086: // .getInterpolatedColor(c3, c2,
087: // 2.0 * (noise - .5)));
088: // g2d.fillRect(i, j, 1, 1);
089: // } else {
090: // g2d.setColor(Color.black);
091: // g2d.fillRect(i, j, 1, 1);
092: // }
093: // }
094: // }
095: // ConvolveOp convolve = new ConvolveOp(new Kernel(3, 3, new float[] {
096: // .08f, .08f, .08f, .08f, .38f, .08f, .08f, .08f, .08f }),
097: // ConvolveOp.EDGE_NO_OP, null);
098: // bi = convolve.filter(bi, null);
099:
100: FabricFilter.FabricFilterLink fabricLink1 = FabricFilterLink
101: .getXLink(1.0, 10.0, TrigKind.SINE);
102: FabricFilter.FabricFilterLink fabricLink2 = FabricFilterLink
103: .getYLink(1.0, 10.0, TrigKind.COSINE);
104: NoiseFilter fabricFilter = new FabricFilter(fabricLink1,
105: fabricLink2);
106: NoiseFilter marbleFilter = MarbleFilter.getXFilter(0.1,
107: TrigKind.COSINE);
108: NoiseFilter mazeFilter = new MedianBeakFilter();
109: NoiseFilter woodFilter = new WoodFilter(30.0);
110:
111: // CompoundNoiseFilter compoundFilter = new CompoundNoiseFilter(
112: // fabricFilter);
113: // long start = System.currentTimeMillis();
114: // BufferedImage bi = NoiseFactory.getNoiseImage(
115: // new SubstanceCharcoalTheme(), new SubstanceCharcoalTheme(),
116: // width, height, 0.01, 0.01, true, compoundFilter, true, false);
117: // long end = System.currentTimeMillis();
118: // System.out.println("Time0 " + (end - start));
119: //
120: // CompoundNoiseFilter compoundFilter2 = new CompoundNoiseFilter(
121: // fabricFilter);
122: long start = System.currentTimeMillis();
123: SubstanceTheme theme = new SubstanceAquaTheme();
124: BufferedImage bi2 = NoiseFactory.getNoiseImage(theme, theme,
125: 400, 400, 0.8, 0.8, false, null, true, true);
126: //bi2 = LafWidgetUtilities.createThumbnail(bi2, 200);
127: long end = System.currentTimeMillis();
128: System.out.println("Time1 " + (end - start));
129:
130: // g.setColor(new SubstanceCharcoalTheme().getDefaultTheme()
131: // .getColorScheme().getDarkColor().brighter());
132: // g.fillRect(0, 0, 1000, 1000);
133: g.drawImage(bi2, 0, 0, null);
134: }
135:
136: public static void main(String[] args) {
137: NoiseFrame nf = new NoiseFrame();
138: nf.setSize(400, 400);
139: nf.setLocationRelativeTo(null);
140: nf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
141: nf.setVisible(true);
142: }
143:
144: }
|