/// Evolver Copyright 2000, Morgan McGuire
/// matrix@alum.mit.edu   http://graphics3d.com/matrix
import java.awt.*;

public class FrequencyBlocks extends ZeroArgumentOperator implements ELOperator 
{
  public void apply(ELMatrix argument[], ELMatrix out, ELEnvironment environment)
  {
    checkArguments(argument);
    
    // For extra performance, pull the arrays into locals so we avoid
    // excess dereferences.
    float red[] = out.red;
    float grn[] = out.grn;
    float blu[] = out.blu;

    int width = out.getWidth();
    int height = out.getHeight();
    float xspan = width;
    float yspan = height;

    double filteredFrequency[] = environment.filteredFrequency;

    int i = width * height - 1;
    for(int y = height - 1; y >= 0; y--) {

      // Pick out the appropriate filtered frequency
      int fy = (int)((y * 8) / yspan);

      for(int x = width - 1; x >= 0; x--) {
        int fx = (int)((x * 8) / xspan);
        int f = fx + 8 * fy;

        float s = (float)filteredFrequency[f];

        red[i] = s;
        grn[i] = s;
        blu[i] = s;
        i--;
      }      
    }
  }

  public String name()
  {
    return "FrequencyBlocks";
  }

  public String description()
  {
    return "Grid of grayscale blocks with intensity based on input frequencies.";
  }

  protected String iconString()
  {
    return "FBk";
  }

  public boolean hasExternalInfluences() {
    return true;
  }
}
