use of processing.core.PVector in project processing by processing.
the class PShapeOpenGL method getWidth.
/*
static public void copyGroup2D(PGraphicsOpenGL pg, PShape src, PShape dest) {
copyMatrix(src, dest);
copyStyles(src, dest);
copyImage(src, dest);
for (int i = 0; i < src.getChildCount(); i++) {
PShape c = createShape2D(pg, src.getChild(i));
dest.addChild(c);
}
}
*/
///////////////////////////////////////////////////////////
//
// Query methods
@Override
public float getWidth() {
PVector min = new PVector(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
if (shapeCreated) {
getVertexMin(min);
getVertexMax(max);
}
width = max.x - min.x;
return width;
}
use of processing.core.PVector in project processing by processing.
the class PShapeOpenGL method getHeight.
@Override
public float getHeight() {
PVector min = new PVector(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
if (shapeCreated) {
getVertexMin(min);
getVertexMax(max);
}
height = max.y - min.y;
return height;
}
use of processing.core.PVector in project WordCram by danbernier.
the class WordCramEngine method placeWord.
private boolean placeWord(EngineWord eWord) {
Word word = eWord.word;
// TODO can we move these into EngineWord.setDesiredLocation? Does that make sense?
Rectangle2D rect = eWord.getShape().getBounds2D();
int wordImageWidth = (int) rect.getWidth();
int wordImageHeight = (int) rect.getHeight();
eWord.setDesiredLocation(placer, eWords.size(), wordImageWidth, wordImageHeight, renderer.getWidth(), renderer.getHeight());
// Set maximum number of placement trials
int maxAttemptsToPlace = renderOptions.maxAttemptsToPlaceWord > 0 ? renderOptions.maxAttemptsToPlaceWord : calculateMaxAttemptsFromWordWeight(word);
EngineWord lastCollidedWith = null;
for (int attempt = 0; attempt < maxAttemptsToPlace; attempt++) {
eWord.nudge(nudger.nudgeFor(word, attempt));
PVector loc = eWord.getCurrentLocation();
if (loc.x < 0 || loc.y < 0 || loc.x + wordImageWidth >= renderer.getWidth() || loc.y + wordImageHeight >= renderer.getHeight()) {
continue;
}
if (lastCollidedWith != null && eWord.overlaps(lastCollidedWith)) {
continue;
}
boolean foundOverlap = false;
for (EngineWord otherWord : drawnWords) {
if (eWord.overlaps(otherWord)) {
foundOverlap = true;
lastCollidedWith = otherWord;
break;
}
}
if (!foundOverlap) {
eWord.finalizeLocation();
return true;
}
}
skipWord(eWord.word, WordSkipReason.NO_SPACE);
return false;
}
use of processing.core.PVector in project WordCram by danbernier.
the class Placers method horizBandAnchoredLeft.
public static WordPlacer horizBandAnchoredLeft() {
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) {
// big=left, small=right
float x = (1 - word.weight) * fieldWidth * r.nextFloat();
float y = ((float) fieldHeight) * 0.5f;
return new PVector(x, y);
}
};
}
use of processing.core.PVector in project WordCram by danbernier.
the class PlottingWordNudger method nudgeFor.
public PVector nudgeFor(Word word, int attempt) {
PVector v = wrappedNudger.nudgeFor(word, attempt);
parent.pushStyle();
parent.noStroke();
float alpha = attempt / 700f;
//alpha = (float) Math.pow(alpha, 3);
//, alpha * 255);
parent.fill(40, 255, 255);
PVector wordLoc = PVector.add(v, word.getTargetPlace());
parent.ellipse(wordLoc.x, wordLoc.y, 3, 3);
parent.popStyle();
return v;
}
Aggregations