<commit_before>/*
 * Copyright (C) 2013 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

package org.dmfs.android.colorpicker.palettes;

import android.graphics.Color;


/**
 * A factory for colors.
 */
public interface ColorFactory
{

	/**
	 * A Factory that returns colors with a specific HUE value.
	 * 
	 * @author <NAME> <<EMAIL>>
	 */
	public class ColorShadeFactory implements ColorFactory
	{
		private final float[] mHSL = new float[] { 0, 0, 0 };


		public ColorShadeFactory(float hue)
		{
			mHSL[0] = hue;
		}


		@Override
		public int getColor(int index, int count)
		{
			index++;
			count++;
			float[] hsl = mHSL;

			if (index <= count / 2)
			{
				mHSL[1] = 1f;
				mHSL[2] = index * 2f / count;
			}
			else
			{
				mHSL[1] = 2f - index * 2f / count;
				mHSL[2] = 1f;
			}
			return Color.HSVToColor(255, hsl);
		}
	}

	/**
	 * A factory that returns the entire palette with a specific saturation and lightness value.
	 * 
	 * @author <NAME> <<EMAIL>>
	 */
	public class RainbowColorFactory implements ColorFactory
	{
		private final float[] mHSL = new float[] { 0, 0, 0 };


		public RainbowColorFactory(float saturation, float lightness)
		{
			mHSL[1] = saturation;
			mHSL[2] = lightness;
		}


		@Override
		public int getColor(int index, int count)
		{
			count += 1;
			float[] hsl = mHSL;

			hsl[0] = index * 360f / count;

			return Color.HSVToColor(255, hsl);
		}
	}

	/**
	 * A Factory that combines multiple factories into one, by concatenation of the palettes.
	 * 
	 * @author <NAME> <<EMAIL>>
	 */
	public class CombinedColorFactory implements ColorFactory
	{

		private final ColorFactory[] mFactories;


		public CombinedColorFactory(ColorFactory... factories)
		{
			mFactories = factories;
		}


		@Override
		public int getColor(int index, int count)
		{
			int factoryCount = mFactories.length;
			return mFactories[(index * factoryCount) / count].getColor(index % (count / factoryCount), count / factoryCount);
		}

	}

	/**<commit_msg>add new color factory to create a grey scale<commit_after>/*
 * Copyright (C) 2013 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

package org.dmfs.android.colorpicker.palettes;

import android.graphics.Color;


/**
 * A factory for colors.
 */
public interface ColorFactory
{

	/**
	 * A Factory that returns colors with a specific hue and saturation. The lightness of all colors is spread evenly across the entire palette.
	 * 
	 * @author <NAME> <<EMAIL>>
	 */
	public class ColorLigthnessFactory implements ColorFactory
	{
		private final float[] mHSL = new float[] { 0, 0, 0 };


		public ColorLigthnessFactory(float hue, float saturation)
		{
			mHSL[0] = hue;
			mHSL[1] = saturation;
		}


		@Override
		public int getColor(int index, int count)
		{
			if (count <= 1)
			{
				return Color.WHITE;
			}

			float[] hsl = mHSL;

			hsl[2] = (float) index / (count - 1);

			return Color.HSVToColor(255, hsl);
		}
	}

	/**
	 * A Factory that returns colors with a specific HUE value. This factory leaves out the edge cases - pure black and pure white.
	 * 
	 * @author <NAME> <<EMAIL>>
	 */
	public class ColorShadeFactory implements ColorFactory
	{
		private final float[] mHSL = new float[] { 0, 0, 0 };


		public ColorShadeFactory(float hue)
		{
			mHSL[0] = hue;
		}


		@Override
		public int getColor(int index, int count)
		{
			index++;
			count++;
			float[] hsl = mHSL;

			if (index <= count / 2)
			{
				hsl[1] = 1f;
				hsl[2] = index * 2f / count;
			}
			else
			{
				hsl[1] = 2f - index * 2f / count;
				hsl[2] = 1f;
			}
			return Color.HSVToColor(255, hsl);
		}
	}

	/**
	 * A factory that returns the entire palette with a specific saturation and lightness value.
	 * 
	 * @author <NAME> <<EMAIL>>
	 */
	public class RainbowColorFactory implements ColorFactory
	{
		private final float[] mHSL = new float[] { 0, 0, 0 };


		public RainbowColorFactory(float saturation, float lightness)
		{
			mHSL[1] = saturation;
			mHSL[2] = lightness;
		}


		@Override
		public int getColor(int index, int count)
		{
			count += 1;
			float[] hsl = mHSL;

			hsl[0] = index * 360f / count;

			return Color.HSVToColor(255, hsl);
		}
	}

	/**
	 * A Factory that combines multiple factories into one, by concatenation of the palettes.
	 * 
	 * @author <NAME> <<EMAIL>>
	 */
	public class CombinedColorFactory implements ColorFactory
	{

		private final ColorFactory[] mFactories;


		public CombinedColorFactory(ColorFactory... factories)
		{
			mFactories = factories;
		}


		@Override
		public int getColor(int index, int count)
		{
			int factoryCount = mFactories.length;
			return mFactories[(index * factoryCount) / count].getColor(index % (count / factoryCount), count / factoryCount);
		}

	}

	/**
	 * Grey scale from black to white
	 */
	public final static ColorFactory GREY = new ColorLigthnessFactory(0, 0);

	/**
{'fraction_non_alphanumeric': 0.10382073190391745, 'fraction_numerical': 0.017894567144929874, 'mean_word_length': 3.1222591362126244, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2558638', 'n_tokens_mistral': 2294, 'n_tokens_neox': 1919, 'n_words': 710}