001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance.painter;
031:
032: import java.awt.Shape;
033: import java.awt.image.BufferedImage;
034:
035: import org.jvnet.substance.color.ColorScheme;
036: import org.jvnet.substance.utils.PerlinNoiseGenerator;
037: import org.jvnet.substance.utils.SubstanceCoreUtilities;
038:
039: /**
040: * Gradient painter that uses noise textures. This class is part of officially
041: * supported API.
042: *
043: * @author Kirill Grouchnikov
044: */
045: public class NoiseGradientPainter extends BaseGradientPainter {
046: /**
047: * Noise generator.
048: */
049: protected static PerlinNoiseGenerator noiseGenerator = new PerlinNoiseGenerator();
050:
051: /*
052: * (non-Javadoc)
053: *
054: * @see org.jvnet.substance.painter.SubstanceGradientPainter#getDisplayName()
055: */
056: public String getDisplayName() {
057: return "Noise";
058: }
059:
060: /* (non-Javadoc)
061: * @see org.jvnet.substance.painter.SubstanceGradientPainter#getContourBackground(int, int, java.awt.Shape, boolean, org.jvnet.substance.color.ColorScheme, org.jvnet.substance.color.ColorScheme, float, boolean, boolean)
062: */
063: public BufferedImage getContourBackground(int width, int height,
064: Shape contour, boolean isDark, ColorScheme colorScheme1,
065: ColorScheme colorScheme2, float cyclePos, boolean hasShine,
066: boolean useCyclePosAsInterpolation) {
067:
068: // // System.err.println(System.currentTimeMillis() + ":" + width + "*"
069: // +
070: // // height);
071: //
072: // BufferedImage mixResult = this.getMixContourBackground(width, height,
073: // contour, isDark, colorScheme1, colorScheme2, cyclePos,
074: // hasShine, useCyclePosAsInterpolation);
075: // if (mixResult != null)
076: // return mixResult;
077: //
078: // // long millis = System.nanoTime();
079: //
080: BufferedImage image = SubstanceCoreUtilities.getBlankImage(
081: width, height);
082: // Graphics2D graphics = (Graphics2D) image.getGraphics();
083: // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
084: // RenderingHints.VALUE_ANTIALIAS_ON);
085: //
086: // ColorScheme interpolationScheme1 = colorScheme1;
087: // ColorScheme interpolationScheme2 = useCyclePosAsInterpolation ?
088: // colorScheme2
089: // : colorScheme1;
090: //
091: // double cycleCoef = 1.0 - cyclePos / 10.0;
092: //
093: // Color topBorderColor = SubstanceColorUtilities.getTopBorderColor(
094: // interpolationScheme1, interpolationScheme2, cycleCoef);
095: // Color midBorderColor = SubstanceColorUtilities.getMidBorderColor(
096: // interpolationScheme1, interpolationScheme2, cycleCoef);
097: // Color bottomBorderColor =
098: // SubstanceColorUtilities.getBottomBorderColor(
099: // interpolationScheme1, interpolationScheme2, cycleCoef);
100: //
101: // // FabricFilter.FabricFilterLink fabricLink1 =
102: // FabricFilterLink.getXLink(
103: // // 1.0, 10.0, TrigKind.SINE);
104: // // FabricFilter.FabricFilterLink fabricLink2 =
105: // FabricFilterLink.getYLink(
106: // // 1.0, 10.0, TrigKind.COSINE);
107: // // NoiseFilter fabricFilter = new FabricFilter(fabricLink1,
108: // fabricLink2);
109: // NoiseFilter mazeFilter = new MedianBeakFilter();
110: //
111: // graphics.setClip(contour);
112: // graphics.drawImage(NoiseFactory.getNoiseImage(interpolationScheme1,
113: // interpolationScheme2, cycleCoef, width, height, 0.1, 0.1, true,
114: // mazeFilter, false), 0, 0, null);
115: //
116: // graphics.setStroke(new BasicStroke((float) 1.3,
117: // BasicStroke.CAP_ROUND,
118: // BasicStroke.JOIN_ROUND));
119: //
120: // // long millis001 = System.nanoTime();
121: //
122: // // long millis003 = 0, millis004 = 0, millis005 = 0;
123: //
124: // // Draw border
125: // GradientPaint gradientBorderTop = new GradientPaint(0, 0,
126: // topBorderColor, 0, height / 2, midBorderColor);
127: // graphics.setPaint(gradientBorderTop);
128: // graphics.setClip(0, 0, width, height / 2);
129: // graphics.draw(contour);
130: //
131: // GradientPaint gradientBorderBottom = new GradientPaint(0, height / 2,
132: // midBorderColor, 0, height - 2, bottomBorderColor);
133: // graphics.setPaint(gradientBorderBottom);
134: // graphics.setClip(0, height / 2, width, 1 + height / 2);
135: // graphics.draw(contour);
136: //
137: return image;
138: }
139: }
|