package frond.colourschemes;
import frond.frames.CustomColourSchemeEditor;
import java.awt.Color;
/**
* Standard colour scheme
*
* Implements the standard colour scheme for rendering fractals
*/
public class CustomColourScheme implements ColourScheme {
private int[] powers;
private float[] coefficients;
private boolean useRGB;
private String name;
private CustomColourSchemeEditor colourSchemeEditor;
/**
* Constructor
*
* Initialises the value of the colour scheme and
* shows a panel to edit the colour scheme.
*/
public CustomColourScheme(String name) {
this.name = name;
useRGB = false;
powers = new int[3];
coefficients = new float[3];
for (int i = 0; i < 3; i++) {
powers[i] = 1;
coefficients[i] = 1.0f;
}
}
/**
* Shows a JPanle that allows the ColourScheme to be edited and returns a handle
*/
public CustomColourSchemeEditor showEditColourScheme() {
if (colourSchemeEditor == null) {
colourSchemeEditor = new CustomColourSchemeEditor(this);
}
colourSchemeEditor.showEditor();
return colourSchemeEditor;
}
/**
* Calculates the colour value
*
* @param tendency
*/
public Color getColourForTendency(double tendency) {
double[] tendencies = {1, tendency, tendency * tendency, tendency * tendency * tendency };
return new Color((float)(tendencies[powers[0]] * coefficients[0]),
(float)(tendencies[powers[1]] * coefficients[1]),
(float)(tendencies[powers[2]] * coefficients[2]));
}
/**
* Sets the name of the scheme
*
* @param string name
*/
public void setSchemeName(String name) {
this.name = name;
}
/**
* Returns the colour scheme's name
*/
public String getSchemeName() {
return name;
}
/**
* Sets the coefficients
*
* @param int index of colour
* @param value to set coefficient to
*/
public void setCoefficient(int i, float c) {
if (c < 1) coefficients[i] = c;
}
/**
* Sets the Powers
*
* @param int index
* @param int power
*/
public void setPower(int i, int p) {
powers[i] = p;
}
/**
* Gets the powers
*
* @param index of color
*/
public int getPower(int index) {
return powers[index];
}
/**
* Gets the coefficients
*
* @param index of the colour
*/
public float getCoefficient(int index) {
return coefficients[index];
}
}