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;
}
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);
}
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);
}
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));
}
};
}
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));
*/
}
};
}
Aggregations