Search in sources :

Example 1 with PVector

use of processing.core.PVector in project WordCram by danbernier.

the class PlottingWordPlacer method place.

public PVector place(Word word, int wordIndex, int wordsCount, int wordImageWidth, int wordImageHeight, int fieldWidth, int fieldHeight) {
    PVector v = wrappedPlacer.place(word, wordIndex, wordsCount, wordImageWidth, wordImageHeight, fieldWidth, fieldHeight);
    parent.pushStyle();
    parent.noFill();
    parent.stroke(15, 255, 255, 200);
    parent.ellipse(v.x, v.y, 10, 10);
    parent.popStyle();
    return v;
}
Also used : PVector(processing.core.PVector)

Example 2 with PVector

use of processing.core.PVector in project WordCram by danbernier.

the class ShapeBasedPlacer method nudgeFor.

public PVector nudgeFor(Word word, int attempt) {
    PVector target = word.getTargetPlace();
    float wx = target.x;
    float wy = target.y;
    float ww = word.getRenderedWidth();
    float wh = word.getRenderedHeight();
    for (int i = 0; i < 1000; i++) {
        float newX = randomBetween(minX, maxX);
        float newY = randomBetween(minY, maxY);
        if (area.contains(newX, newY, ww, wh)) {
            return new PVector(newX - wx, newY - wy);
        }
    }
    return new PVector(-1, -1);
}
Also used : PVector(processing.core.PVector)

Example 3 with PVector

use of processing.core.PVector in project WordCram by danbernier.

the class PlacerHeatMap method draw.

public void draw(PApplet sketch) {
    RectStack rectStack = new RectStack();
    for (int i = 0; i < words.length; i++) {
        Word word = words[i];
        PFont wordFont = word.getFont(fonter);
        float wordSize = word.getSize(sizer, i, words.length);
        float wordAngle = word.getAngle(angler);
        Shape shape = shaper.getShapeFor(word.word, wordFont, wordSize, wordAngle);
        Rectangle2D rect = shape.getBounds2D();
        //return r.getHeight() < minShapeSize || r.getWidth() < minShapeSize;
        int wordImageWidth = (int) rect.getWidth();
        int wordImageHeight = (int) rect.getHeight();
        PVector desiredLocation = word.getTargetPlace(placer, i, words.length, wordImageWidth, wordImageHeight, sketch.width, sketch.height);
        //sketch.rect(desiredLocation.x, desiredLocation.y, wordImageWidth, wordImageHeight);
        rectStack.add((int) desiredLocation.x, (int) desiredLocation.y, wordImageWidth, wordImageHeight);
    }
    RectGrid grid = new RectGrid(rectStack);
    grid.draw(sketch);
}
Also used : PVector(processing.core.PVector) Shape(java.awt.Shape) PFont(processing.core.PFont) Rectangle2D(java.awt.geom.Rectangle2D)

Example 4 with PVector

use of processing.core.PVector in project WordCram by danbernier.

the class Placers method centerClump.

public static WordPlacer centerClump() {
    final Random r = new Random();
    final float stdev = 0.4f;
    return new WordPlacer() {

        public PVector place(Word word, int wordIndex, int wordsCount, int wordImageWidth, int wordImageHeight, int fieldWidth, int fieldHeight) {
            return new PVector(getOneUnder(fieldWidth - wordImageWidth), getOneUnder(fieldHeight - wordImageHeight));
        }

        private int getOneUnder(float upperLimit) {
            return PApplet.round(PApplet.map((float) r.nextGaussian() * stdev, -2, 2, 0, upperLimit));
        }
    };
}
Also used : PVector(processing.core.PVector) Random(java.util.Random)

Example 5 with PVector

use of processing.core.PVector in project WordCram by danbernier.

the class Placers method horizLine.

public static WordPlacer horizLine() {
    final Random r = new Random();
    return new WordPlacer() {

        public PVector place(Word word, int wordIndex, int wordsCount, int wordImageWidth, int wordImageHeight, int fieldWidth, int fieldHeight) {
            int centerHorizLine = (int) ((fieldHeight - wordImageHeight) * 0.5);
            int centerVertLine = (int) ((fieldWidth - wordImageWidth) * 0.5);
            float xOff = (float) r.nextGaussian() * ((fieldWidth - wordImageWidth) * 0.2f);
            float yOff = (float) r.nextGaussian() * 50;
            return new PVector(centerVertLine + xOff, centerHorizLine + yOff);
        /*
                int adjFieldWidth = fieldWidth - wordImageWidth;
                int adjFieldHeight = fieldHeight - wordImageHeight;

                float xOff = (float) r.nextGaussian();// * 0.2f;
                float yOff = (float) r.nextGaussian();// * 0.5f;
                yOff = (float)Math.pow(yOff, 3) * 1.5f;

                return new PVector(PApplet.map(xOff, -2, 2, 0, adjFieldWidth),
                                    PApplet.map(yOff, -2, 2, 0, adjFieldHeight));
*/
        }
    };
}
Also used : PVector(processing.core.PVector) Random(java.util.Random)

Aggregations

PVector (processing.core.PVector)13 Random (java.util.Random)3 Rectangle2D (java.awt.geom.Rectangle2D)2 Shape (java.awt.Shape)1 PFont (processing.core.PFont)1