Sha256: b72f219f2b7361ec705064562f0810e99619bd84296d1d712a80cf427b857674

Contents?: true

Size: 1.71 KB

Versions: 9

Compression:

Stored size: 1.71 KB

Contents

package wordcram;

import processing.core.PApplet;

/**
 * Sizers contains pre-made {@link WordSizer} implementations that you might
 * find useful. Right now, it's only {@link Sizers#byWeight(int, int)} and
 * {@link Sizers#byRank(int, int)}.
 * @see WordSizer
 */
public class Sizers {

    /**
     * Returns a WordSizer that sizes words by their weight, where the
     * "heaviest" word will be sized at <code>maxSize</code>.
     * <p>
     * To be specific, the font size for each word will be calculated with:
     *
     * <pre>
     * PApplet.lerp(minSize, maxSize, (float) word.weight)
     * </pre>
     *
     * @param minSize
     *            the size to draw a Word with weight = 0
     * @param maxSize
     *            the size to draw a Word with weight = 1
     * @return the WordSizer
     */
    public static WordSizer byWeight(final int minSize, final int maxSize) {
        return (Word word, int wordRank, int wordCount) -> PApplet.lerp(minSize, maxSize, word.weight);
    }

    /**
     * Returns a WordSizer that sizes words by their rank. The first word will
     * be sized at <code>maxSize</code>.
     * <p>
     * To be specific, the font size for each word will be calculated with:
     *
     * <pre>
     * PApplet.map(wordRank, 0, wordCount, maxSize, minSize)
     * </pre>
     *
     * @param minSize
     *            the size to draw the last Word
     * @param maxSize
     *            the size to draw the first Word
     * @return the WordSizer
     */
    public static WordSizer byRank(final int minSize, final int maxSize) {
        return (Word word, int wordRank, int wordCount) -> PApplet.map(wordRank, 0, wordCount, maxSize, minSize);
    }

    // TODO try exponent scales, rather than linear.
}

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby_wordcram-2.1.1 src/wordcram/Sizers.java
ruby_wordcram-2.1.0 src/wordcram/Sizers.java
ruby_wordcram-2.0.6 src/wordcram/Sizers.java
ruby_wordcram-2.0.5 src/wordcram/Sizers.java
ruby_wordcram-2.0.4 src/wordcram/Sizers.java
ruby_wordcram-2.0.3 src/wordcram/Sizers.java
ruby_wordcram-2.0.2 src/wordcram/Sizers.java
ruby_wordcram-2.0.1 src/wordcram/Sizers.java
ruby_wordcram-2.0.0 src/wordcram/Sizers.java