Sha256: c341894e542be1e7f87696394708029df62d5b7c2e775d297be7f57a862fa76b

Contents?: true

Size: 807 Bytes

Versions: 9

Compression:

Stored size: 807 Bytes

Contents

package wordcram;

import processing.core.*;

public class WaveWordPlacer implements WordPlacer {

    @Override
    public PVector place(Word word, int wordIndex, int wordsCount,
            int wordImageWidth, int wordImageHeight, int fieldWidth,
            int fieldHeight) {

        float normalizedIndex = (float) wordIndex / wordsCount;
        float x = normalizedIndex * fieldWidth;
        float y = normalizedIndex * fieldHeight;

        float yOffset = getYOffset(wordIndex, wordsCount, fieldHeight);
        return new PVector(x, y + yOffset);
    }

    private float getYOffset(int wordIndex, int wordsCount, int fieldHeight) {
        float theta = PApplet.map(wordIndex, 0, wordsCount, PConstants.PI, -PConstants.PI);

        return (float) Math.sin(theta) * (fieldHeight / 3f);
    }
}

Version data entries

9 entries across 9 versions & 1 rubygems

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