Android Open Source - 4est Ring






From Project

Back to project page 4est.

License

The source code is released under:

MIT License

If you think the Android project 4est listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.wordsaretoys.rise.pattern;
/*from ww  w . j a  va2s .  c  o m*/
import java.util.Random;


/**
 * represent a group of pattern generators
 * that derive from a single linear buffer
 * 
 * provides fast lookups suitable for bitmaps
 */
public class Ring implements Pattern.F2F {

  float[] data;
  int modu;
  
  public Ring(int length) {
    data = new float[length];
    modu = length - 1;
  }
  
  public void generate(Random rng, int minP, int maxP, int minT, int maxT) {
    boolean inPeak = false;
    int count = 0;
    int total = 0;
    float peak0 = 0;
    float peak1 = 0;
    
    for (int i = 0; i < data.length; i++, count++) {
      // if we've reached the end of the current phase
      if (count == total) {
        // flip the phase
        inPeak = !inPeak;
        // derive new period & peak (if necessary)
        if (inPeak) {
          total = minP + rng.nextInt(maxP - minP);
        } else {
          total = minT + rng.nextInt(maxT - minT);
          peak0 = peak1;
          peak1 = rng.nextFloat();
        }
        count = 0;
      }
      // if we're in a peak
      if (inPeak) {
        // give me that peak
        data[i] = peak1;
      } else {
        // otherwise, give me the peak-peak transition
        float mu = (float) count / (float) total;
        float m2 = (float)(1 - Math.cos(mu * Math.PI)) * 0.5f;
        data[i] = (1 - m2) * peak0 + m2 * peak1;
      }
    }
  }

  @Override
  public float get(float x, float y) {
    float fx = data[ (int)(data.length * x) & modu ];
    float fy = data[ (int)(data.length * y) & modu ];
    return data[ (int)(data.length * (fx + fy)) & modu];
  }
}




Java Source Code List

com.wordsaretoys.forest.Audio.java
com.wordsaretoys.forest.Debris.java
com.wordsaretoys.forest.Game.java
com.wordsaretoys.forest.GlView.java
com.wordsaretoys.forest.MainActivity.java
com.wordsaretoys.forest.Map.java
com.wordsaretoys.forest.Player.java
com.wordsaretoys.forest.Render.java
com.wordsaretoys.forest.Rotors.java
com.wordsaretoys.forest.Shared.java
com.wordsaretoys.forest.Skybox.java
com.wordsaretoys.rise.geometry.Camera.java
com.wordsaretoys.rise.geometry.Geom.java
com.wordsaretoys.rise.geometry.Mote.java
com.wordsaretoys.rise.geometry.Ortho.java
com.wordsaretoys.rise.geometry.Quaternion.java
com.wordsaretoys.rise.geometry.Vector.java
com.wordsaretoys.rise.glwrapper.Mesh.java
com.wordsaretoys.rise.glwrapper.Shader.java
com.wordsaretoys.rise.glwrapper.Texture.java
com.wordsaretoys.rise.meshutil.HeightMapper.java
com.wordsaretoys.rise.meshutil.IndexBuffer.java
com.wordsaretoys.rise.meshutil.SurfaceMapper.java
com.wordsaretoys.rise.meshutil.VertexBuffer.java
com.wordsaretoys.rise.meshutil.Vindexer.java
com.wordsaretoys.rise.pattern.Bitmap.java
com.wordsaretoys.rise.pattern.F2FSumMap.java
com.wordsaretoys.rise.pattern.I2FCutMap.java
com.wordsaretoys.rise.pattern.I2FMap.java
com.wordsaretoys.rise.pattern.I2IMap.java
com.wordsaretoys.rise.pattern.Pattern.java
com.wordsaretoys.rise.pattern.Ring.java
com.wordsaretoys.rise.utility.Asset.java
com.wordsaretoys.rise.utility.Board.java
com.wordsaretoys.rise.utility.Dbg.java
com.wordsaretoys.rise.utility.Interval.java
com.wordsaretoys.rise.utility.Misc.java
com.wordsaretoys.rise.utility.Needle.java