當前位置: 首頁>>代碼示例>>Java>>正文


Java CubicCurve2D.getPathIterator方法代碼示例

本文整理匯總了Java中java.awt.geom.CubicCurve2D.getPathIterator方法的典型用法代碼示例。如果您正苦於以下問題:Java CubicCurve2D.getPathIterator方法的具體用法?Java CubicCurve2D.getPathIterator怎麽用?Java CubicCurve2D.getPathIterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.geom.CubicCurve2D的用法示例。


在下文中一共展示了CubicCurve2D.getPathIterator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeNoise

import java.awt.geom.CubicCurve2D; //導入方法依賴的package包/類
@Override
public void makeNoise(BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();

    // the curve from where the points are taken
    CubicCurve2D cc = new CubicCurve2D.Float(width * .1f, height * RAND.nextFloat(), width * .1f, height
            * RAND.nextFloat(), width * .25f, height * RAND.nextFloat(), width * .9f, height * RAND.nextFloat());

    // creates an iterator to define the boundary of the flattened curve
    PathIterator pi = cc.getPathIterator(null, 2);
    Point2D tmp[] = new Point2D[200];
    int i = 0;

    // while pi is iterating the curve, adds points to tmp array
    while (!pi.isDone()) {
        float[] coords = new float[6];
        switch (pi.currentSegment(coords)) {
        case PathIterator.SEG_MOVETO:
        case PathIterator.SEG_LINETO:
            tmp[i] = new Point2D.Float(coords[0], coords[1]);
        }
        i++;
        pi.next();
    }

    // the points where the line changes the stroke and direction
    Point2D[] pts = new Point2D[i];
    // copies points from tmp to pts
    System.arraycopy(tmp, 0, pts, 0, i);

    Graphics2D graph = (Graphics2D) image.getGraphics();
    graph.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));

    graph.setColor(_color);

    // for the maximum 3 point change the stroke and direction
    for (i = 0; i < pts.length - 1; i++) {
        if (i < 3) {
            graph.setStroke(new BasicStroke(_width));
        }
        graph.drawLine((int) pts[i].getX(), (int) pts[i].getY(), (int) pts[i + 1].getX(), (int) pts[i + 1].getY());
    }

    graph.dispose();
}
 
開發者ID:akuma,項目名稱:meazza,代碼行數:47,代碼來源:CurvedLineNoiseProducer.java

示例2: makeNoise

import java.awt.geom.CubicCurve2D; //導入方法依賴的package包/類
/**
 * Draws a noise on the image. The noise curve depends on the factor values.
 * Noise won't be visible if all factors have the value > 1.0f
 * 
 * @param image
 *            the image to add the noise to
 * @param factorOne
 * @param factorTwo
 * @param factorThree
 * @param factorFour
 */
public void makeNoise(BufferedImage image, float factorOne,
		float factorTwo, float factorThree, float factorFour)
{
	Color color = getConfig().getNoiseColor();

	// image size
	int width = image.getWidth();
	int height = image.getHeight();

	// the points where the line changes the stroke and direction
	Point2D[] pts = null;
	Random rand = new Random();

	// the curve from where the points are taken
	CubicCurve2D cc = new CubicCurve2D.Float(width * factorOne, height
			* rand.nextFloat(), width * factorTwo, height
			* rand.nextFloat(), width * factorThree, height
			* rand.nextFloat(), width * factorFour, height
			* rand.nextFloat());

	// creates an iterator to define the boundary of the flattened curve
	PathIterator pi = cc.getPathIterator(null, 2);
	Point2D tmp[] = new Point2D[200];
	int i = 0;

	// while pi is iterating the curve, adds points to tmp array
	while (!pi.isDone())
	{
		float[] coords = new float[6];
		switch (pi.currentSegment(coords))
		{
			case PathIterator.SEG_MOVETO:
			case PathIterator.SEG_LINETO:
				tmp[i] = new Point2D.Float(coords[0], coords[1]);
		}
		i++;
		pi.next();
	}

	pts = new Point2D[i];
	System.arraycopy(tmp, 0, pts, 0, i);

	Graphics2D graph = (Graphics2D) image.getGraphics();
	graph.setRenderingHints(new RenderingHints(
			RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON));

	graph.setColor(color);

	// for the maximum 3 point change the stroke and direction
	for (i = 0; i < pts.length - 1; i++)
	{
		if (i < 3)
			graph.setStroke(new BasicStroke(0.9f * (4 - i)));
		graph.drawLine((int) pts[i].getX(), (int) pts[i].getY(),
				(int) pts[i + 1].getX(), (int) pts[i + 1].getY());
	}

	graph.dispose();
}
 
開發者ID:ycaihua,項目名稱:kaptcha,代碼行數:72,代碼來源:DefaultNoise.java

示例3: makeNoise

import java.awt.geom.CubicCurve2D; //導入方法依賴的package包/類
@Override
public void makeNoise(BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();

    // the curve from where the points are taken
    CubicCurve2D cc = new CubicCurve2D.Float(width * .1f, height
            * RAND.nextFloat(), width * .1f, height
            * RAND.nextFloat(), width * .25f, height
            * RAND.nextFloat(), width * .9f, height
            * RAND.nextFloat());

    // creates an iterator to define the boundary of the flattened curve
    PathIterator pi = cc.getPathIterator(null, 2);
    Point2D tmp[] = new Point2D[200];
    int i = 0;

    // while pi is iterating the curve, adds points to tmp array
    while (!pi.isDone()) {
        float[] coords = new float[6];
        switch (pi.currentSegment(coords)) {
        case PathIterator.SEG_MOVETO:
        case PathIterator.SEG_LINETO:
            tmp[i] = new Point2D.Float(coords[0], coords[1]);
        }
        i++;
        pi.next();
    }

    // the points where the line changes the stroke and direction
    Point2D[] pts = new Point2D[i];
    // copies points from tmp to pts
    System.arraycopy(tmp, 0, pts, 0, i);

    Graphics2D graph = (Graphics2D) image.getGraphics();
    graph.setRenderingHints(new RenderingHints(
            RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON));

    graph.setColor(_color);

    // for the maximum 3 point change the stroke and direction
    for (i = 0; i < pts.length - 1; i++) {
        if (i < 3) {
        	graph.setStroke(new BasicStroke(_width));
        }
        graph.drawLine((int) pts[i].getX(), (int) pts[i].getY(),
                (int) pts[i + 1].getX(), (int) pts[i + 1].getY());
    }

    graph.dispose();
}
 
開發者ID:rookiefly,項目名稱:simplecaptcha,代碼行數:53,代碼來源:CurvedLineNoiseProducer.java


注:本文中的java.awt.geom.CubicCurve2D.getPathIterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。